From 1bb7a160f8622b3bd34dcf17075aa077b6208f5c Mon Sep 17 00:00:00 2001 From: un-pogaz <46523284+un-pogaz@users.noreply.github.com> Date: Sun, 2 Feb 2025 10:18:08 +0100 Subject: [PATCH] add-noqa for unconvertible % format --- src/calibre/db/cli/cmd_list.py | 2 +- src/calibre/db/cli/cmd_list_categories.py | 2 +- src/calibre/ebooks/conversion/preprocess.py | 10 +++++----- src/calibre/ebooks/metadata/mobi.py | 2 +- src/calibre/ebooks/metadata/topaz.py | 2 +- src/calibre/ebooks/pdf/html_writer.py | 2 +- src/calibre/ebooks/rtf/rtfml.py | 2 +- src/calibre/gui2/viewer/search.py | 2 +- src/calibre/library/catalogs/bibtex.py | 2 +- src/calibre/library/catalogs/epub_mobi_builder.py | 6 +++--- src/calibre/srv/auth.py | 2 +- src/calibre/utils/config.py | 2 +- 12 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/calibre/db/cli/cmd_list.py b/src/calibre/db/cli/cmd_list.py index 1b6fdf2adf..ebe16113fc 100644 --- a/src/calibre/db/cli/cmd_list.py +++ b/src/calibre/db/cli/cmd_list.py @@ -231,7 +231,7 @@ def do_list( widths = list(base_widths) titles = map( - lambda x, y: '%-*s%s' % (x - len(separator), y, separator), widths, + lambda x, y: '%-*s%s' % (x - len(separator), y, separator), widths, # noqa: UP031 [template_title if v == 'template' else v for v in fields] ) with ColoredStream(sys.stdout, fg='green'): diff --git a/src/calibre/db/cli/cmd_list_categories.py b/src/calibre/db/cli/cmd_list_categories.py index 58225f30ac..f096b922ab 100644 --- a/src/calibre/db/cli/cmd_list_categories.py +++ b/src/calibre/db/cli/cmd_list_categories.py @@ -99,7 +99,7 @@ def do_list(fields, data, opts): widths = list(base_widths) titles = map( - lambda x, y: '%-*s%s' % (x - len(separator), y, separator), widths, fields + lambda x, y: '%-*s%s' % (x - len(separator), y, separator), widths, fields # noqa: UP031 ) with ColoredStream(sys.stdout, fg='green'): prints(''.join(titles)) diff --git a/src/calibre/ebooks/conversion/preprocess.py b/src/calibre/ebooks/conversion/preprocess.py index 453462b179..37e29203d9 100644 --- a/src/calibre/ebooks/conversion/preprocess.py +++ b/src/calibre/ebooks/conversion/preprocess.py @@ -265,16 +265,16 @@ class Dehyphenator: self.format = format if format == 'html': intextmatch = re.compile(( - r'(?<=.{%i})(?P[^\W\-]+)(-|‐)\s*(?=<)(?P()?' + r'(?<=.{%i})(?P[^\W\-]+)(-|‐)\s*(?=<)(?P()?' # noqa: UP031 r'\s*(\s*){1,2}(?P<(p|div)[^>]*>\s*(]*>\s*

\s*)' r'?\s+){0,3}\s*(<[iubp][^>]*>\s*){1,2}(]*>)?)\s*(?P[\w\d]+)') % length) elif format == 'pdf': intextmatch = re.compile(( - r'(?<=.{%i})(?P[^\W\-]+)(-|‐)\s*(?P

|' + r'(?<=.{%i})(?P[^\W\-]+)(-|‐)\s*(?P

|' # noqa: UP031 r'\s*

\s*<[iub]>)\s*(?P[\w\d]+)')% length) elif format == 'txt': intextmatch = re.compile( - r'(?<=.{%i})(?P[^\W\-]+)(-|‐)( |\t)*(?P(\n( |\t)*)+)(?P[\w\d]+)'% length) + r'(?<=.{%i})(?P[^\W\-]+)(-|‐)( |\t)*(?P(\n( |\t)*)+)(?P[\w\d]+)'% length) # noqa: UP031 elif format == 'individual_words': intextmatch = re.compile( r'(?!<)(?P[^\W\-]+)(-|‐)\s*(?P\w+)(?![^<]*?>)', re.UNICODE) @@ -529,11 +529,11 @@ class HTMLPreProcessor: # print('The pdf line length returned is ' + str(length)) # unwrap em/en dashes end_rules.append((re.compile( - r'(?<=.{%i}[–—])\s*

\s*(?=[\[a-z\d])' % length), lambda match: '')) + r'(?<=.{%i}[–—])\s*

\s*(?=[\[a-z\d])' % length), lambda match: '')) # noqa: UP031 end_rules.append( # Un wrap using punctuation (re.compile(( - r'(?<=.{%i}([a-zäëïöüàèìòùáćéíĺóŕńśúýâêîôûçąężıãõñæøþðßěľščťžňďřů,:)\\IAß]' + r'(?<=.{%i}([a-zäëïöüàèìòùáćéíĺóŕńśúýâêîôûçąężıãõñæøþðßěľščťžňďřů,:)\\IAß]' # noqa: UP031 r'|(?)?\s*(

\s*

\s*)+\s*(?=(<(i|b|u)>)?' r'\s*[\w\d$(])') % length, re.UNICODE), wrap_lines), ) diff --git a/src/calibre/ebooks/metadata/mobi.py b/src/calibre/ebooks/metadata/mobi.py index 0f9f5447e3..427096bfe5 100644 --- a/src/calibre/ebooks/metadata/mobi.py +++ b/src/calibre/ebooks/metadata/mobi.py @@ -286,7 +286,7 @@ class MetadataUpdater: s, src = src[:length],src[length:] hexa = ' '.join([f'{ord(x):02X}' for x in s]) s = s.translate(FILTER) - result += '%04X %-*s %s\n' % (N, length*3, hexa, s) + result += '%04X %-*s %s\n' % (N, length*3, hexa, s) # noqa: UP031 N+=length print(result) diff --git a/src/calibre/ebooks/metadata/topaz.py b/src/calibre/ebooks/metadata/topaz.py index 9a1383cae6..374da028e0 100644 --- a/src/calibre/ebooks/metadata/topaz.py +++ b/src/calibre/ebooks/metadata/topaz.py @@ -161,7 +161,7 @@ class MetadataUpdater: s, src = src[:length],src[length:] hexa = ' '.join([f'{ord(x):02X}' for x in s]) s = s.translate(FILTER) - result += '%04X %-*s %s\n' % (N, length*3, hexa, s) + result += '%04X %-*s %s\n' % (N, length*3, hexa, s) # noqa: UP031 N+=length print(result) diff --git a/src/calibre/ebooks/pdf/html_writer.py b/src/calibre/ebooks/pdf/html_writer.py index 48abf79d19..ef4cba7de4 100644 --- a/src/calibre/ebooks/pdf/html_writer.py +++ b/src/calibre/ebooks/pdf/html_writer.py @@ -777,7 +777,7 @@ def add_pagenum_toc(root, toc, opts, page_number_display_map): .calibre-pdf-toc .level-%d td:first-of-type { padding-left: %.1gem } .calibre-pdf-toc .level-%d td:first-of-type { padding-left: %.1gem } .calibre-pdf-toc .level-%d td:first-of-type { padding-left: %.1gem } - ''' % tuple(indents) + (opts.extra_css or '') + ''' % tuple(indents) + (opts.extra_css or '') # noqa: UP031 style = body.makeelement(XHTML('style'), type='text/css') style.text = css body.append(style) diff --git a/src/calibre/ebooks/rtf/rtfml.py b/src/calibre/ebooks/rtf/rtfml.py index 0aed5b31bc..6e28b2bfdc 100644 --- a/src/calibre/ebooks/rtf/rtfml.py +++ b/src/calibre/ebooks/rtf/rtfml.py @@ -177,7 +177,7 @@ class RTFMLizer: self.log.exception(f'Image {item.href} is corrupted, ignoring') repl = '\n\n' else: - repl = '\n\n{\\*\\shppict{\\pict\\jpegblip\\picw%i\\pich%i \n%s\n}}\n\n' % (width, height, data) + repl = '\n\n{\\*\\shppict{\\pict\\jpegblip\\picw%i\\pich%i \n%s\n}}\n\n' % (width, height, data) # noqa: UP031 text = text.replace(f'SPECIAL_IMAGE-{src}-REPLACE_ME', repl) return text diff --git a/src/calibre/gui2/viewer/search.py b/src/calibre/gui2/viewer/search.py index 355e240f04..ef6384d1ed 100644 --- a/src/calibre/gui2/viewer/search.py +++ b/src/calibre/gui2/viewer/search.py @@ -154,7 +154,7 @@ class Search: flags = self.regex_flags flags |= regex.DOTALL match_any_word = r'(?:\b(?:' + '|'.join(words) + r')\b)' - joiner = '.{1,%d}' % interval + joiner = '.{1,%d}' % interval # noqa: UP031 full_pat = regex.compile(joiner.join(match_any_word for x in words), flags=flags) word_pats = tuple(regex.compile(rf'\b{x}\b', flags) for x in words) self._nsd = word_pats, full_pat diff --git a/src/calibre/library/catalogs/bibtex.py b/src/calibre/library/catalogs/bibtex.py index 0406a6c760..49edd025e7 100644 --- a/src/calibre/library/catalogs/bibtex.py +++ b/src/calibre/library/catalogs/bibtex.py @@ -399,7 +399,7 @@ class BIBTEX(CatalogPlugin): entry['ondevice'] = db.catalog_plugin_on_device_temp_mapping[entry['id']]['ondevice'] # outfile.write('%%%Calibre catalog\n%%%{0} entries in catalog\n\n'.format(nb_entries)) - outfile.write('@preamble{"This catalog of %d entries was generated by calibre on %s"}\n\n' + outfile.write('@preamble{"This catalog of %d entries was generated by calibre on %s"}\n\n' # noqa: UP031 % (nb_entries, strftime('%A, %d. %B %Y %H:%M'))) for entry in data: diff --git a/src/calibre/library/catalogs/epub_mobi_builder.py b/src/calibre/library/catalogs/epub_mobi_builder.py index 8907f1a843..f72f716d02 100644 --- a/src/calibre/library/catalogs/epub_mobi_builder.py +++ b/src/calibre/library/catalogs/epub_mobi_builder.py @@ -264,7 +264,7 @@ class CatalogBuilder: (str): sort key ''' if not book['series']: - fs = '{:<%d}!{!s}' % longest_author_sort + fs = '{:<%d}!{!s}' % longest_author_sort # noqa: UP031 key = fs.format(capitalize(book['author_sort']), capitalize(book['title_sort'])) else: @@ -272,7 +272,7 @@ class CatalogBuilder: integer = int(index) fraction = index - integer series_index = f"{integer:04}{str(f'{fraction:0.4f}').lstrip('0')}" - fs = '{:<%d}~{!s}{!s}' % longest_author_sort + fs = '{:<%d}~{!s}{!s}' % longest_author_sort # noqa: UP031 key = fs.format(capitalize(book['author_sort']), self.generate_sort_title(book['series']), series_index) @@ -785,7 +785,7 @@ class CatalogBuilder: if self.DEBUG and self.opts.verbose: tl = [i['title'] for i in books_by_author] lt = max(tl, key=len) - fs = '{:<6}{:<%d} {:<%d} {}' % (len(lt), len(las)) + fs = '{:<6}{:<%d} {:<%d} {}' % (len(lt), len(las)) # noqa: UP031 print(fs.format('', 'Title', 'Author', 'Series')) for i in books_by_author: print(fs.format('', i['title'], i['author_sort'], i['series'])) diff --git a/src/calibre/srv/auth.py b/src/calibre/srv/auth.py index 4bf13a0cf6..86d3cc4883 100644 --- a/src/calibre/srv/auth.py +++ b/src/calibre/srv/auth.py @@ -248,7 +248,7 @@ class AuthController: self.log = log self.secret = as_hex_unicode(os.urandom(random.randint(20, 30))) self.max_age_seconds = max_age_seconds - self.key_order = '{%d}:{%d}:{%d}' % random.choice(tuple(permutations((0,1,2)))) + self.key_order = '{%d}:{%d}:{%d}' % random.choice(tuple(permutations((0,1,2)))) # noqa: UP031 self.realm = realm if '"' in realm: raise ValueError('Double-quotes are not allowed in the authentication realm') diff --git a/src/calibre/utils/config.py b/src/calibre/utils/config.py index 2f5ed06e70..2cd67e7549 100644 --- a/src/calibre/utils/config.py +++ b/src/calibre/utils/config.py @@ -73,7 +73,7 @@ class CustomHelpFormatter(optparse.IndentedHelpFormatter): opts = ' '*self.current_indent + '{}\n'.format(colored(opts, fg='green')) indent_first = self.help_position else: # start help on same line as opts - opts = ' '*self.current_indent + '%-*s ' % (opt_width+len(colored('', fg='green')), colored(opts, fg='green')) + opts = ' '*self.current_indent + '%-*s ' % (opt_width+len(colored('', fg='green')), colored(opts, fg='green')) # noqa: UP031 indent_first = 0 result.append(opts) if option.help: