From 047ebcffe427e57db9b7fa06adf63ec8b4d95cb4 Mon Sep 17 00:00:00 2001 From: un-pogaz <46523284+un-pogaz@users.noreply.github.com> Date: Fri, 24 Jan 2025 11:14:16 +0100 Subject: [PATCH] convert some legacy percent format (manual) ruff 'UP031' --- manual/epub.py | 2 +- setup/build.py | 6 +++--- setup/check.py | 2 +- setup/hosting.py | 8 ++++---- setup/install.py | 2 +- setup/lc_data.py | 2 +- setup/plugins_mirror.py | 2 +- setup/publish.py | 6 +++--- setup/test.py | 2 +- setup/translations.py | 2 +- src/odf/attrconverters.py | 2 +- src/odf/odf2moinmoin.py | 2 +- src/odf/odf2xhtml.py | 12 ++++++------ src/odf/odfmanifest.py | 2 +- src/odf/opendocument.py | 6 +++--- 15 files changed, 29 insertions(+), 29 deletions(-) diff --git a/manual/epub.py b/manual/epub.py index 6b2224a888..195a3a420a 100644 --- a/manual/epub.py +++ b/manual/epub.py @@ -50,7 +50,7 @@ class EPUBHelpBuilder(EpubBuilder): fmt, width, height = identify(container.raw_data(imgname)) if width == -1: raise ValueError('Failed to read size of: {}'.format(imgname)) - img.set('style', 'width: %dpx; height: %dpx' % (width, height)) + img.set('style', 'width: {}px; height: {}px'.format(width, height)) def fix_opf(self, container): spine_names = {n for n, l in container.spine_names} diff --git a/setup/build.py b/setup/build.py index 8835a7d7d8..0108af65e2 100644 --- a/setup/build.py +++ b/setup/build.py @@ -21,7 +21,7 @@ from setup import SRC, Command, isbsd, isfreebsd, ishaiku, islinux, ismacos, isw isunix = islinux or ismacos or isbsd or ishaiku -py_lib = os.path.join(sys.prefix, 'libs', 'python%d%d.lib' % sys.version_info[:2]) +py_lib = os.path.join(sys.prefix, 'libs', 'python{}{}.lib'.format(*sys.version_info[:2])) class CompileCommand(NamedTuple): cmd: list[str] @@ -657,7 +657,7 @@ class Build(Command): os.chdir(bdir) try: self.check_call(cmd + ['-S', os.path.dirname(sources[0])]) - self.check_call([self.env.make] + ['-j%d'%(cpu_count or 1)]) + self.check_call([self.env.make] + ['-j{}'.format(cpu_count or 1)]) finally: os.chdir(cwd) os.rename(self.j(bdir, 'libheadless.so'), target) @@ -734,7 +734,7 @@ sip-file = {os.path.basename(sipf)!r} env = os.environ.copy() if is_macos_universal_build: env['ARCHS'] = 'x86_64 arm64' - self.check_call([self.env.make] + ([] if iswindows else ['-j%d'%(os.cpu_count() or 1)]), env=env) + self.check_call([self.env.make] + ([] if iswindows else ['-j{}'.format(os.cpu_count() or 1)]), env=env) e = 'pyd' if iswindows else 'so' m = glob.glob(f'{ext.name}/{ext.name}.*{e}') if not m: diff --git a/setup/check.py b/setup/check.py index aa73a07059..ea069b8582 100644 --- a/setup/check.py +++ b/setup/check.py @@ -150,7 +150,7 @@ class Check(Command): for i, f in enumerate(dirty_files): self.info('\tChecking', f) if self.file_has_errors(f): - self.info('%d files left to check' % (len(dirty_files) - i - 1)) + self.info('{} files left to check'.format(len(dirty_files) - i - 1)) try: edit_file(f) except FileNotFoundError: diff --git a/setup/hosting.py b/setup/hosting.py index 4ca36854f0..5415fe11ba 100644 --- a/setup/hosting.py +++ b/setup/hosting.py @@ -56,16 +56,16 @@ class ReadFileWithProgressReporting: # {{{ eta = int((self._total - self.tell()) / bit_rate) + 1 eta_m, eta_s = eta / 60, eta % 60 sys.stdout.write( - ' %.1f%% %.1f/%.1fMB %.1f KB/sec %d minutes, %d seconds left' % - (frac * 100, mb_pos, mb_tot, kb_rate, eta_m, eta_s) + ' {:.1f}% {:.1f}/{:.1f}MB {:.1f} KB/sec {} minutes, {} seconds left' + .format(frac * 100, mb_pos, mb_tot, kb_rate, eta_m, eta_s) ) sys.stdout.write('\x1b[u') if self.tell() >= self._total: sys.stdout.write('\n') t = int(time.time() - self.start_time) + 1 print( - 'Upload took %d minutes and %d seconds at %.1f KB/sec' % - (t / 60, t % 60, kb_rate) + 'Upload took {} minutes and {} seconds at {:.1f} KB/sec' + .format(t/60, t % 60, kb_rate) ) sys.stdout.flush() diff --git a/setup/install.py b/setup/install.py index eb7d622775..53df06d7a6 100644 --- a/setup/install.py +++ b/setup/install.py @@ -388,7 +388,7 @@ class Bootstrap(Command): st = time.time() clone_cmd.insert(2, '--depth=1') subprocess.check_call(clone_cmd, cwd=self.d(self.SRC)) - print('Downloaded translations in %d seconds' % int(time.time() - st)) + print('Downloaded translations in {} seconds'.format(int(time.time() - st))) else: if os.path.exists(tdir): subprocess.check_call(['git', 'pull'], cwd=tdir) diff --git a/setup/lc_data.py b/setup/lc_data.py index a386e71228..94a1db2f4d 100644 --- a/setup/lc_data.py +++ b/setup/lc_data.py @@ -20,7 +20,7 @@ def generate_data(): ans = [] for x, limit in (('day', 8), ('mon', 13)): for attr in ('ab' + x, x): - ans.append((attr, tuple(map(nl, (getattr(locale, '%s_%d' % (attr.upper(), i)) for i in range(1, limit)))))), + ans.append((attr, tuple(map(nl, (getattr(locale, '{}_{}'.format(attr.upper(), i)) for i in range(1, limit)))))), for x in ('d_t_fmt', 'd_fmt', 't_fmt', 't_fmt_ampm', 'radixchar', 'thousep', 'yesexpr', 'noexpr'): ans.append((x, nl(getattr(locale, x.upper())))) return ans diff --git a/setup/plugins_mirror.py b/setup/plugins_mirror.py index a240945b22..fe381f9dee 100644 --- a/setup/plugins_mirror.py +++ b/setup/plugins_mirror.py @@ -476,7 +476,7 @@ def plugin_to_index(plugin, count): block.append('
') block.append('
  • {}
  • '.format(li)) block = ''.format('\n'.join(block)) - downloads = ('\xa0[%d total downloads]' % count) if count else '' + downloads = ('\xa0[{} total downloads]'.format(count)) if count else '' zipfile = '
    Download plugin \u2193{}
    '.format( quoteattr(plugin['file']), quoteattr(plugin['name'] + '.zip'), downloads) desc = plugin['description'] or '' diff --git a/setup/publish.py b/setup/publish.py index ee1065d94d..42623055f6 100644 --- a/setup/publish.py +++ b/setup/publish.py @@ -203,7 +203,7 @@ class Manual(Command): sys.executable, self.j(self.d(self.SRC), 'manual', 'build.py'), language, self.j(tdir, language) ], '\n\n**************** Building translations for: {}'.format(language))) - self.info('Building manual for %d languages' % len(jobs)) + self.info('Building manual for {} languages'.format(len(jobs))) subprocess.check_call(jobs[0].cmd) if not parallel_build(jobs[1:], self.info): raise SystemExit(1) @@ -222,8 +222,8 @@ class Manual(Command): if x and not os.path.exists(x): os.symlink('.', x) self.info( - 'Built manual for %d languages in %s minutes' % - (len(jobs), int((time.time() - st) / 60.)) + 'Built manual for {} languages in {} minutes' + .format(len(jobs), int((time.time() - st) / 60.)) ) finally: os.chdir(cwd) diff --git a/setup/test.py b/setup/test.py index 8a077845e6..8be2acac81 100644 --- a/setup/test.py +++ b/setup/test.py @@ -37,7 +37,7 @@ class Test(BaseTest): super().add_options(parser) parser.add_option('--test-verbosity', type=int, default=4, help='Test verbosity (0-4)') parser.add_option('--test-module', '--test-group', default=[], action='append', type='choice', choices=sorted(map(str, TEST_MODULES)), - help='The test module to run (can be specified more than once for multiple modules). Choices: {}'.format(', '.join(sorted(TEST_MODULES)))) + help='The test module to run (can be specified more than once for multiple modules). Choices: {}'.format(', '.join(sorted(TEST_MODULES)))) parser.add_option('--test-name', '-n', default=[], action='append', help='The name of an individual test to run. Can be specified more than once for multiple tests. The name of the' ' test is the name of the test function without the leading test_. For example, the function test_something()' diff --git a/setup/translations.py b/setup/translations.py index 42122797a8..7c0640513e 100644 --- a/setup/translations.py +++ b/setup/translations.py @@ -93,7 +93,7 @@ class POT(Command): # {{{ ans = [] for lineno, msg in msgs: - ans.append('#: %s:%d'%(path, lineno)) + ans.append('#: {}:{}'.format(path, lineno)) slash = codepoint_to_chr(92) msg = msg.replace(slash, slash*2).replace('"', r'\"').replace('\n', r'\n').replace('\r', r'\r').replace('\t', r'\t') diff --git a/src/odf/attrconverters.py b/src/odf/attrconverters.py index 46a948f2dd..a17117369f 100644 --- a/src/odf/attrconverters.py +++ b/src/odf/attrconverters.py @@ -275,7 +275,7 @@ def cnv_points(attribute, arg, element): return arg else: try: - strarg = ' '.join(['%d,%d' % p for p in arg]) + strarg = ' '.join(['{},{}'.format(*p) for p in arg]) except: raise ValueError('Points must be string or [(0,0),(1,1)] - not {}'.format(arg)) return strarg diff --git a/src/odf/odf2moinmoin.py b/src/odf/odf2moinmoin.py index 2e6e0d5c73..609ba34f8b 100644 --- a/src/odf/odf2moinmoin.py +++ b/src/odf/odf2moinmoin.py @@ -131,7 +131,7 @@ class ParagraphProps: def __unicode__(self): - return '[bq=%s, h=%d, code=%s]' % (unicode_type(self.blockquote), + return '[bq={}, h={}, code={}]'.format(unicode_type(self.blockquote), self.headingLevel, unicode_type(self.code)) __str__ = __unicode__ diff --git a/src/odf/odf2xhtml.py b/src/odf/odf2xhtml.py index 920907e93f..60f80d2b5e 100644 --- a/src/odf/odf2xhtml.py +++ b/src/odf/odf2xhtml.py @@ -647,7 +647,7 @@ class ODF2XHTML(handler.ContentHandler): ''' Create a unique anchor id for a href name ''' if name not in self.anchors: # Changed by Kovid - self.anchors[name] = 'anchor%d' % (len(self.anchors) + 1) + self.anchors[name] = 'anchor{}'.format(len(self.anchors) + 1) return self.anchors.get(name) def purgedata(self): @@ -940,13 +940,13 @@ dl.notes dd:last-of-type { page-break-after: avoid } for key in range(1,self.currentnote+1): note = self.notedict[key] # for key,note in self.notedict.items(): - self.opentag('dt', {'id':'footnote-%d' % key}) + self.opentag('dt', {'id':'footnote-{}'.format(key)}) # self.opentag('sup') # self.writeout(escape(note['citation'])) # self.closetag('sup', False) self.writeout('[') - self.opentag('a', {'href': '#citation-%d' % key}) - self.writeout('←%d' % key) + self.opentag('a', {'href': '#citation-{}'.format(key)}) + self.writeout('←{}'.format(key)) self.closetag('a') self.writeout(']\xa0') self.closetag('dt') @@ -1335,7 +1335,7 @@ dl.notes dd:last-of-type { page-break-after: avoid } # the list level must return to 1, even though the table or # textbox itself may be nested within another list. name = self.tagstack.rfindattr((TEXTNS,'style-name')) - list_class = '%s_%d' % (name, level) + list_class = '{}_{}'.format(name, level) tag_name = self.listtypes.get(list_class,'ul') number_class = tag_name + list_class if list_id: @@ -1372,7 +1372,7 @@ dl.notes dd:last-of-type { page-break-after: avoid } # the list level must return to 1, even though the table or # textbox itself may be nested within another list. name = self.tagstack.rfindattr((TEXTNS,'style-name')) - list_class = '%s_%d' % (name, level) + list_class = '{}_{}'.format(name, level) self.closetag(self.listtypes.get(list_class,'ul')) self.purgedata() diff --git a/src/odf/odfmanifest.py b/src/odf/odfmanifest.py index feeabd9ab5..560b0d9cb2 100644 --- a/src/odf/odfmanifest.py +++ b/src/odf/odfmanifest.py @@ -114,4 +114,4 @@ if __name__ == '__main__': import sys result = odfmanifest(sys.argv[1]) for file in result.values(): - print('%-40s %-40s' % (file['media-type'], file['full-path'])) + print('{:<40} {:<40}'.format(file['media-type'], file['full-path'])) diff --git a/src/odf/opendocument.py b/src/odf/opendocument.py index 1c25eb2b97..7689960f6b 100644 --- a/src/odf/opendocument.py +++ b/src/odf/opendocument.py @@ -385,7 +385,7 @@ class OpenDocument: ''' self.childobjects.append(document) if objectname is None: - document.folder = '%s/Object %d' % (self.folder, len(self.childobjects)) + document.folder = '{}/Object {}'.format(self.folder, len(self.childobjects)) else: document.folder = objectname return '.{}'.format(document.folder) @@ -407,7 +407,7 @@ class OpenDocument: # Look in subobjects subobjectnum = 1 for subobject in object.childobjects: - self._savePictures(subobject,'%sObject %d/' % (folder, subobjectnum)) + self._savePictures(subobject,'{}Object {}/'.format(folder, subobjectnum)) subobjectnum += 1 def __replaceGenerator(self): @@ -524,7 +524,7 @@ class OpenDocument: # Write subobjects subobjectnum = 1 for subobject in object.childobjects: - self._saveXmlObjects(subobject, '%sObject %d/' % (folder, subobjectnum)) + self._saveXmlObjects(subobject, '{}Object {}/'.format(folder, subobjectnum)) subobjectnum += 1 # Document's DOM methods