Skip to content

Commit 5c7dc96

Browse files
committed
Automated conversion of % format specifiers
Using ruff. Does not change any translatable strings. There are still several thousand usages of % left that ruff wont auto-convert. Get to them someday.
1 parent 39f7f61 commit 5c7dc96

522 files changed

Lines changed: 2908 additions & 3179 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

icons/icns/make_iconsets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
try:
2828
for sz in (16, 32, 128, 256, 512, 1024):
2929
iname = f'icon_{sz}x{sz}.png'
30-
iname2x = 'icon_{0}x{0}@2x.png'.format(sz // 2)
30+
iname2x = f'icon_{sz // 2}x{sz // 2}@2x.png'
3131
if src.endswith('.svg'):
3232
subprocess.check_call(['rsvg-convert', src, '-w', str(sz), '-h', str(sz), '-o', iname])
3333
else:

setup/build.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ def build_headless(self):
656656
os.chdir(bdir)
657657
try:
658658
self.check_call(cmd + ['-S', os.path.dirname(sources[0])])
659-
self.check_call([self.env.make] + ['-j{}'.format(cpu_count or 1)])
659+
self.check_call([self.env.make] + [f'-j{cpu_count or 1}'])
660660
finally:
661661
os.chdir(cwd)
662662
os.rename(self.j(bdir, 'libheadless.so'), target)
@@ -733,7 +733,7 @@ def build_pyqt_extension(self, ext, sbf):
733733
env = os.environ.copy()
734734
if is_macos_universal_build:
735735
env['ARCHS'] = 'x86_64 arm64'
736-
self.check_call([self.env.make] + ([] if iswindows else ['-j{}'.format(os.cpu_count() or 1)]), env=env)
736+
self.check_call([self.env.make] + ([] if iswindows else [f'-j{os.cpu_count() or 1}']), env=env)
737737
e = 'pyd' if iswindows else 'so'
738738
m = glob.glob(f'{ext.name}/{ext.name}.*{e}')
739739
if not m:

setup/check.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def run_check_files(self):
114114
for i, f in enumerate(dirty_files):
115115
self.info('\tChecking', f)
116116
if self.file_has_errors(f):
117-
self.info('{} files left to check'.format(len(dirty_files) - i - 1))
117+
self.info(f'{len(dirty_files) - i - 1} files left to check')
118118
try:
119119
edit_file(f)
120120
except FileNotFoundError:

setup/hosting.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,16 @@ def report_progress(self, size):
5656
eta = int((self._total - self.tell()) / bit_rate) + 1
5757
eta_m, eta_s = eta / 60, eta % 60
5858
sys.stdout.write(
59-
' {:.1f}% {:.1f}/{:.1f}MB {:.1f} KB/sec {} minutes, {} seconds left'
60-
.format(frac * 100, mb_pos, mb_tot, kb_rate, eta_m, eta_s)
59+
f' {frac * 100:.1f}% {mb_pos:.1f}/{mb_tot:.1f}MB {kb_rate:.1f} KB/sec {eta_m} minutes, {eta_s} seconds left'
60+
6161
)
6262
sys.stdout.write('\x1b[u')
6363
if self.tell() >= self._total:
6464
sys.stdout.write('\n')
6565
t = int(time.time() - self.start_time) + 1
6666
print(
67-
'Upload took {} minutes and {} seconds at {:.1f} KB/sec'
68-
.format(t/60, t % 60, kb_rate)
67+
f'Upload took {t/60} minutes and {t % 60} seconds at {kb_rate:.1f} KB/sec'
68+
6969
)
7070
sys.stdout.flush()
7171

setup/install.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ def pre_sub_commands(self, opts):
388388
st = time.time()
389389
clone_cmd.insert(2, '--depth=1')
390390
subprocess.check_call(clone_cmd, cwd=self.d(self.SRC))
391-
print('Downloaded translations in {} seconds'.format(int(time.time() - st)))
391+
print(f'Downloaded translations in {int(time.time() - st)} seconds')
392392
else:
393393
if os.path.exists(tdir):
394394
subprocess.check_call(['git', 'pull'], cwd=tdir)

setup/plugins_mirror.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ def plugin_to_index(plugin, count):
460460
released = datetime(*tuple(map(int, re.split(r'\D', plugin['last_modified'])))[:6]).strftime('%e %b, %Y').lstrip()
461461
details = [
462462
'Version: <b>{}</b>'.format(escape('.'.join(map(str, plugin['version'])))),
463-
'Released: <b>{}</b>'.format(escape(released)),
463+
f'Released: <b>{escape(released)}</b>',
464464
'Author: {}'.format(escape(plugin['author'])),
465465
'calibre: {}'.format(escape('.'.join(map(str, plugin['minimum_calibre_version'])))),
466466
'Platforms: {}'.format(escape(', '.join(sorted(plugin['supported_platforms']) or ['all']))),

setup/publish.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ def run(self, opts):
5050
platforms = 'linux64', 'linuxarm64', 'osx', 'win'
5151
for x in platforms:
5252
cmd = (
53-
'''{exe} -c "import subprocess; subprocess.Popen(['{exe}', './setup.py', '{x}']).wait() != 0 and'''
54-
''' input('Build of {x} failed, press Enter to exit');"'''
55-
).format(exe=sys.executable, x=x)
53+
f'''{sys.executable} -c "import subprocess; subprocess.Popen(['{sys.executable}', './setup.py', '{x}']).wait() != 0 and'''
54+
f''' input('Build of {x} failed, press Enter to exit');"'''
55+
)
5656
session.append('title ' + x)
5757
session.append('launch ' + cmd)
5858

@@ -220,8 +220,8 @@ def run(self, opts):
220220
if x and not os.path.exists(x):
221221
os.symlink('.', x)
222222
self.info(
223-
'Built manual for {} languages in {} minutes'
224-
.format(len(jobs), int((time.time() - st) / 60.))
223+
f'Built manual for {len(jobs)} languages in {int((time.time() - st) / 60.)} minutes'
224+
225225
)
226226
finally:
227227
os.chdir(cwd)
@@ -335,6 +335,6 @@ class TagRelease(Command):
335335
def run(self, opts):
336336
self.info('Tagging release')
337337
subprocess.check_call(
338-
'git tag -s v{0} -m "version-{0}"'.format(__version__).split()
338+
f'git tag -s v{__version__} -m "version-{__version__}"'.split()
339339
)
340340
subprocess.check_call(f'git push origin v{__version__}'.split())

setup/upload.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,12 +361,11 @@ class UploadDemo(Command): # {{{
361361

362362
def run(self, opts):
363363
check_call(
364-
'''ebook-convert {}/demo.html /tmp/html2lrf.lrf '''
364+
f'''ebook-convert {self.j(self.SRC, HTML2LRF)}/demo.html /tmp/html2lrf.lrf '''
365365
'''--title='Demonstration of html2lrf' --authors='Kovid Goyal' '''
366366
'''--header '''
367367
'''--serif-family "/usr/share/fonts/corefonts, Times New Roman" '''
368-
'''--mono-family "/usr/share/fonts/corefonts, Andale Mono" '''
369-
''''''.format(self.j(self.SRC, HTML2LRF)),
368+
'''--mono-family "/usr/share/fonts/corefonts, Andale Mono" ''',
370369
shell=True
371370
)
372371

setup/win-ci.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def main():
9898
else:
9999
if len(sys.argv) == 1:
100100
raise SystemExit('Usage: win-ci.py sw|build|test')
101-
raise SystemExit('{!r} is not a valid action'.format(sys.argv[-1]))
101+
raise SystemExit(f'{sys.argv[-1]!r} is not a valid action')
102102

103103

104104
if __name__ == '__main__':

src/calibre/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ def get_proxy_info(proxy_scheme, proxy_string):
292292
'''
293293
from polyglot.urllib import urlparse
294294
try:
295-
proxy_url = '%s://%s'%(proxy_scheme, proxy_string)
295+
proxy_url = f'{proxy_scheme}://{proxy_string}'
296296
urlinfo = urlparse(proxy_url)
297297
ans = {
298298
'scheme': urlinfo.scheme,

0 commit comments

Comments
 (0)