Skip to content

Commit 9c4a1a8

Browse files
committed
assume f-strings are available (python3.6+) for all scripts we are the only ones to run
1 parent 174cea7 commit 9c4a1a8

File tree

3 files changed

+42
-37
lines changed

3 files changed

+42
-37
lines changed

doc/source/check_api_doc.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ def only_deprecated(self):
113113

114114
def diff(self, other):
115115
if not isinstance(other, ClassItem):
116-
raise TypeError("Expect a {} instance as argument. "
117-
"Got a {} instance instead".format(ClassItem.__name__, type(other).__name__))
116+
raise TypeError(f"Expect a {ClassItem.__name__} instance as argument. "
117+
f"Got a {type(other).__name__} instance instead")
118118
diff_item = ClassItem(self.class_)
119119
diff_item.attrs = {k: v for k, v in self.attrs.items() if k not in other.attrs}
120120
diff_item.methods = {k: v for k, v in self.methods.items() if k not in other.methods}
@@ -128,15 +128,15 @@ def write(self, ofile):
128128
_write_header(ofile, self.name, '=', indent=indent)
129129
if self.attrs:
130130
_write_header(ofile, 'Attributes', indent=indent)
131-
ofile.writelines(indent + ' * {}\n'.format(attr) for attr in self.attrs.keys())
131+
ofile.writelines(f'{indent} * {attr}\n' for attr in self.attrs.keys())
132132
ofile.write('\n')
133133
if self.methods:
134134
_write_header(ofile, 'Methods', indent=indent)
135-
ofile.writelines(indent + ' * {}\n'.format(method) for method in self.methods.keys())
135+
ofile.writelines(f'{indent} * {method}\n' for method in self.methods.keys())
136136
ofile.write('\n')
137137
if self.deprecated_methods:
138138
_write_header(ofile, 'Deprecated Methods', indent=indent)
139-
ofile.writelines(indent + ' * {}\n'.format(method) for method in self.deprecated_methods.keys())
139+
ofile.writelines(f'{indent} * {method}\n' for method in self.deprecated_methods.keys())
140140
ofile.write('\n')
141141
ofile.write('\n')
142142

@@ -182,6 +182,7 @@ def insert_element(self, name, obj):
182182
self.funcs[name] = obj
183183
elif inspect.isclass(obj):
184184
if name in self.classes:
185+
# FIXME: missing format or fstring
185186
warnings.warn("Class '{}' was already present in '{}' module item and will be replaced")
186187
class_ = getattr(self.module, name)
187188
class_item = ClassItem(class_)
@@ -210,8 +211,8 @@ def only_deprecated(self):
210211

211212
def diff(self, other):
212213
if not isinstance(other, ModuleItem):
213-
raise TypeError("Expect a {} instance as argument. "
214-
"Got a {} instance instead".format(ModuleItem.__name__, type(other).__name__))
214+
raise TypeError(f"Expect a {ModuleItem.__name__} instance as argument. "
215+
f"Got a {type(other).__name__} instance instead")
215216
diff_item = ModuleItem(self.module)
216217
diff_item.others = {k: v for k, v in self.others.items() if k not in other.others}
217218
diff_item.funcs = {k: v for k, v in self.funcs.items() if k not in other.funcs}
@@ -227,15 +228,15 @@ def write(self, ofile):
227228
ofile.write('\n')
228229
if self.others:
229230
_write_header(ofile, 'Miscellaneous', '=')
230-
ofile.writelines(' * {}\n'.format(other) for other in self.others.keys())
231+
ofile.writelines(f' * {other}\n' for other in self.others.keys())
231232
ofile.write('\n')
232233
if self.funcs:
233234
_write_header(ofile, 'Functions', '=')
234-
ofile.writelines(' * {}\n'.format(func) for func in self.funcs.keys())
235+
ofile.writelines(f' * {func}\n' for func in self.funcs.keys())
235236
ofile.write('\n')
236237
if self.deprecated_items:
237238
_write_header(ofile, 'Deprecated Functions or Classes', '=')
238-
ofile.writelines(' * {}\n'.format(func) for func in self.deprecated_items.keys())
239+
ofile.writelines(f' * {func}\n' for func in self.deprecated_items.keys())
239240
ofile.write('\n')
240241
if self.classes:
241242
_write_header(ofile, 'Classes', '=')
@@ -270,7 +271,7 @@ def get_public_api():
270271
module_item.auto_discovery()
271272
public_api[module_name] = module_item
272273
except ImportError as err:
273-
print('module {} could not be imported: {}'.format(module_name, err))
274+
print(f'module {module_name} could not be imported: {err}')
274275
public_api[module_name] = err
275276
return public_api
276277

@@ -294,7 +295,7 @@ def get_autosummary_api():
294295
module_item = ModuleItem(module)
295296
autosummary_api[module_name] = module_item
296297
except ImportError as err:
297-
print('module {} could not be imported: {}'.format(module_name, err))
298+
print(f'module {module_name} could not be imported: {err}')
298299
autosummary_api[module_name] = err
299300

300301
for generated_rst_file in os.listdir(output_dir):
@@ -327,7 +328,7 @@ def write_api(filepath, api, header='API', version=True):
327328
failed = []
328329
with open(output_file, 'w') as ofile:
329330
if version:
330-
header = '{} [{}]'.format(header, __version__)
331+
header = f'{header} [{__version__}]'
331332
_write_header(ofile, header, '~')
332333
ofile.write('\n')
333334
keys = sorted(api.keys())
@@ -341,7 +342,7 @@ def write_api(filepath, api, header='API', version=True):
341342

342343
if failed:
343344
_write_header(ofile, 'Modules that failed to import')
344-
ofile.writelines(' * {} -- {}\n'.format(module_name, error) for module_name, error in failed)
345+
ofile.writelines(f' * {module_name} -- {error}\n' for module_name, error in failed)
345346

346347

347348
def get_items_from_api_doc():

make_release.py

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
#!/usr/bin/python
2-
# coding=utf-8
32
# Release script for LArray
43
# Licence: GPLv3
54
# Requires:
65
# * git
7-
from __future__ import print_function, unicode_literals
8-
96
import sys
107
from os.path import abspath, dirname, join
118
from subprocess import check_call
@@ -35,15 +32,12 @@ def update_metapackage(context):
3532
chdir(context['repository'])
3633
version = short(context['release_name'])
3734

38-
def fill(s):
39-
return s.format(version=version)
40-
4135
# TODO: this should be echocall(redirect_stdout=False)
42-
print(fill('Updating larrayenv metapackage to version {version}'))
36+
print(f'Updating larrayenv metapackage to version {version}')
4337
# - excluded versions 5.0 and 5.1 of ipykernel because these versions make the console useless after any exception
4438
# https://github.com/larray-project/larray-editor/issues/166
45-
check_call(['conda', 'metapackage', 'larrayenv', version, '--dependencies', fill('larray =={version}'),
46-
fill('larray-editor =={version}'), fill('larray_eurostat =={version}'),
39+
check_call(['conda', 'metapackage', 'larrayenv', version, '--dependencies', f'larray =={version}',
40+
f'larray-editor =={version}', f'larray_eurostat =={version}',
4741
"qtconsole", "matplotlib", "pyqt", "qtpy", "pytables",
4842
"xlsxwriter", "xlrd", "openpyxl", "xlwings", "ipykernel !=5.0,!=5.1.0",
4943
'--user', 'larray-project',
@@ -72,33 +66,44 @@ def announce_new_release(release_name):
7266
outlook = win32.Dispatch('outlook.application')
7367
mail = outlook.CreateItem(0)
7468
mail.To = LARRAY_ANNOUNCE_MAILING_LIST
75-
mail.Subject = "LArray {} released".format(version)
76-
mail.Body = """\
69+
mail.Subject = f"LArray {version} released"
70+
mail.Body = f"""\
7771
Hello all,
7872
7973
We are pleased to announce that version {version} of LArray is now available.
8074
The complete description of changes including examples can be found at:
8175
82-
{readthedocs}changes.html#version-{version_doc}
76+
{LARRAY_READTHEDOCS}changes.html#version-{version.replace('.', '-')}
8377
8478
8579
8680
As always, *any* feedback is very welcome, preferably on the larray-users
87-
mailing list: {larray_users_group} (you need to register to be able to post).
88-
""".format(version=version, readthedocs=LARRAY_READTHEDOCS, version_doc=version.replace('.', '-'),
89-
larray_users_group=LARRAY_USERS_GROUP)
81+
mailing list: {LARRAY_USERS_GROUP} (you need to register to be able to post).
82+
"""
9083
mail.Display(True)
9184

9285

9386
if __name__ == '__main__':
9487
argv = sys.argv
9588
if len(argv) < 2:
96-
print("Usage: {} [-c|--conda] release_name|dev [step|startstep:stopstep] [branch]".format(argv[0]))
97-
print("make release steps:", ', '.join(f.__name__ for f, _ in make_release_steps))
98-
print("update conda-forge feedstock steps:", ', '.join(f.__name__ for f, _ in update_feedstock_steps))
99-
print("or")
100-
print("Usage: {} -a|--announce release_name".format(argv[0]))
101-
print("Usage: {} -m|--meta release_name".format(argv[0]))
89+
print(f"""
90+
Usage:
91+
* {argv[0]} release_name|dev [step|startstep:stopstep] [branch]
92+
main release script
93+
94+
steps: {', '.join(f.__name__ for f, _ in make_release_steps)}
95+
96+
* {argv[0]} -c|--conda release_name
97+
update conda-forge feedstock
98+
99+
steps: {', '.join(f.__name__ for f, _ in update_feedstock_steps)}
100+
101+
* {argv[0]} -a|--announce release_name
102+
announce release
103+
104+
* {argv[0]} -m|--meta release_name
105+
update metapackage
106+
""")
102107
sys.exit()
103108

104109
local_repository = abspath(dirname(__file__))

next_release.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/python
2-
# encoding: utf-8
32
# script to start a new release cycle
43
# Licence: GPLv3
54
from os.path import abspath, dirname
@@ -12,7 +11,7 @@
1211

1312
argv = sys.argv
1413
if len(argv) < 2:
15-
print("Usage: {} release_name [branch]".format(argv[0]))
14+
print(f"Usage: {argv[0]} release_name [branch]")
1615
sys.exit()
1716

1817
local_repository = abspath(dirname(__file__))

0 commit comments

Comments
 (0)