Skip to content

modernize to f-string #1171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 13 additions & 24 deletions winpython/disthelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def prepend_module_to_path(module_path):
name = Path(module_path).name
prefix = "Prepending module to sys.path"
message = prefix + (
"%s [revision %s]" % (name, changeset)
f"{name} [revision {changeset}]"
).rjust(80 - len(prefix), ".")
print(message, file=sys.stderr)
if name in sys.modules:
Expand All @@ -84,9 +84,9 @@ def prepend_module_to_path(module_path):
if modname.startswith(name + '.'):
sys.modules.pop(modname)
nbsp += 1
warning = '(removed %s from sys.modules' % name
warning = f'(removed {name} from sys.modules'
if nbsp:
warning += ' and %d subpackages' % nbsp
warning += f' and {nbsp} subpackages'
warning += ')'
print(warning.rjust(80), file=sys.stderr)
return message
Expand Down Expand Up @@ -157,7 +157,7 @@ def strip_version(version):
def remove_dir(dirname):
"""Remove directory *dirname* and all its contents
Print details about the operation (progress, success/failure)"""
print("Removing directory '%s'..." % dirname, end=' ')
print(f"Removing directory '{dirname}'...", end=' ')
try:
shutil.rmtree(dirname, ignore_errors=True)
print("OK")
Expand Down Expand Up @@ -530,7 +530,7 @@ def add_matplotlib(self):
def add_modules(self, *module_names):
"""Include module *module_name*"""
for module_name in module_names:
print("Configuring module '%s'" % module_name)
print(f"Configuring module '{module_name}'")
if module_name == 'PyQt4':
self.add_pyqt4()
elif module_name == 'PySide':
Expand All @@ -552,7 +552,7 @@ def add_modules(self, *module_names):
]:
if hasattr(h5py, attr):
self.includes.append(
'h5py.%s' % attr
f'h5py.{attr}'
)
if (
self.bin_path_excludes is not None
Expand Down Expand Up @@ -598,8 +598,7 @@ def add_modules(self, *module_names):
):
if Path(fname).suffix == '.py':
modname = (
'sphinx.ext.%s'
% Path(fname).stem
f'sphinx.ext.{Path(fname).stem}'
)
self.includes.append(modname)
elif module_name == 'pygments':
Expand Down Expand Up @@ -661,8 +660,7 @@ def add_modules(self, *module_names):
)
except IOError:
raise RuntimeError(
"Module not supported: %s"
% module_name
f"Module not supported: {module_name}"
)

def add_module_data_dir(
Expand All @@ -684,7 +682,7 @@ def add_module_data_dir(
data_dir = str(Path(module_dir) / data_dir_name)
if not Path(data_dir).is_dir():
raise IOError(
"Directory not found: %s" % data_dir
f"Directory not found: {data_dir}"
)
for dirpath, _dirnames, filenames in os.walk(
data_dir
Expand Down Expand Up @@ -719,12 +717,7 @@ def add_module_data_files(
*extensions*: list of file extensions, e.g. ('.png', '.svg')
"""
print(
"Adding module '%s' data files in %s (%s)"
% (
module_name,
", ".join(data_dir_names),
", ".join(extensions),
)
f"Adding module '{module_name}' data files in {', '.join(data_dir_names)} ({', '.join(extensions)})"
)
module_dir = get_module_path(module_name)
for data_dir_name in data_dir_names:
Expand All @@ -750,11 +743,7 @@ def add_module_data_files(
)
)
print(
"Adding module '%s' translation file: %s"
% (
module_name,
Path(translation_file).name,
)
f"Adding module '{module_name}' translation file: {Path(translation_file).name}"
)

def build(
Expand Down Expand Up @@ -785,7 +774,7 @@ def build(
)
else:
raise RuntimeError(
"Unsupported library %s" % library
f"Unsupported library {library}"
)

def __cleanup(self):
Expand All @@ -803,7 +792,7 @@ def __create_archive(self, option):
* 'move': move target directory to a ZIP archive
"""
name = self.target_dir
os.system('zip "%s.zip" -r "%s"' % (name, name))
os.system(f'zip "{name}.zip" -r "{name}"')
if option == 'move':
shutil.rmtree(name)

Expand Down