Skip to content
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

chore(python): migrate to f-string #5066

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions scripts/git-archive-all.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def __init__(self, prefix='', verbose=False, exclude=True, force_sub=False, extr
try:
self.run_shell("[ -d .git ] || git rev-parse --git-dir > /dev/null 2>&1", main_repo_abspath)
except Exception as e:
raise ValueError("Not a git repository (or any of the parent directories).".format(path=main_repo_abspath))
raise ValueError(f"Not a git repository (or any of the parent directories).")

# Detect toplevel directory of the repo.
main_repo_abspath = path.abspath(self.read_git_shell('git rev-parse --show-toplevel', main_repo_abspath).rstrip())
Expand Down Expand Up @@ -102,13 +102,13 @@ def create(self, output_path, dry_run=False, output_format=None):
elif output_format == 'tgz':
t_mode = 'w:gz'
else:
t_mode = 'w:{f}'.format(f=output_format)
t_mode = f'w:{output_format}'

if not dry_run:
archive = tarfile.open(path.abspath(output_path), t_mode)
add = lambda file_path, file_name: archive.add(file_path, path.join(self.prefix, file_name))
else:
raise RuntimeError("Unknown format: {f}".format(f=output_format))
raise RuntimeError(f"Unknown format: {output_format}")

for file_path in self.extra:
if not dry_run:
Expand Down Expand Up @@ -254,7 +254,7 @@ def is_file_excluded(self, repo_abspath, repo_file_path, exclude_patterns):
for p in patterns:
if fnmatch(file_name, p) or fnmatch(repo_file_path, p):
if self.verbose:
print("Exclude pattern matched {pattern}: {path}".format(pattern=p, path=repo_file_path))
print(f"Exclude pattern matched {p}: {repo_file_path}")
is_excluded = True

if not len(components):
Expand Down Expand Up @@ -392,7 +392,7 @@ def read_git_shell(cmd, cwd=None):
from optparse import OptionParser

parser = OptionParser(usage="usage: %prog [-v] [--prefix PREFIX] [--no-exclude] [--force-submodules] [--dry-run] OUTPUT_FILE",
version="%prog {version}".format(version=__version__))
version=f"%prog {__version__}")

parser.add_option('--prefix',
type='string',
Expand Down Expand Up @@ -454,6 +454,6 @@ def read_git_shell(cmd, cwd=None):
options.extra)
archiver.create(output_file_path, options.dry_run)
except Exception as e:
parser.exit(2, "{exception}\n".format(exception=e))
parser.exit(2, f"{e}\n")

sys.exit(0)
4 changes: 2 additions & 2 deletions tests/data/python/gen_issue2342-template.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
for x in range(1, xcount):
for y in range(1, ycount):
for z in range(1, zcount):
print("translate([{}, {}, {}])".format(x,y,z))
print(f"translate([{x}, {y}, {z}])")
print(" cube(0.5);")

print("echo(\"{} elements processed\");".format(totalcount))
print(f'echo("{totalcount} elements processed");')
6 changes: 3 additions & 3 deletions tests/data/python/gen_svg_viewbox_tests-template.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
width, height = p[0:2]
aspectParam = ' '.join(str(x) for x in p[2:])
aspectFile = '_'.join(str(x) for x in p[2:][::-1])
svg_viewBox = "viewBox=\"0 0 {} {}\"".format(width, height)
svg_preserveAspectRatio = "preserveAspectRatio=\"{}\"".format(aspectParam)
svg_viewBox = f'viewBox="0 0 {width} {height}"'
svg_preserveAspectRatio = f'preserveAspectRatio="{aspectParam}"'
out = svg.replace('__VIEWBOX__', svg_viewBox).replace('__PRESERVE_ASPECT_RATIO__', svg_preserveAspectRatio)
outfile = sys.argv[1] + "/viewbox_{}x{}_{}.svg".format(width, height, aspectFile)
outfile = sys.argv[1] + f"/viewbox_{width}x{height}_{aspectFile}.svg"
with open(outfile, "w") as f:
f.write(out)