Skip to content

Commit

Permalink
Further f-strings
Browse files Browse the repository at this point in the history
  • Loading branch information
mara004 committed Feb 24, 2023
1 parent ddcc5f2 commit a98cb78
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 28 deletions.
9 changes: 4 additions & 5 deletions setupsrc/pypdfium2_setup/autorelease.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,15 @@ def register_changes(curr_ns):
def _get_log(name, url, cwd, ver_a, ver_b, prefix_ver, prefix_commit, prefix_tag):
log = ""
log += "\n<details>\n"
log += " <summary>%s commit log</summary>\n\n" % name
log += " <summary>%s commit log</summary>\n\n" % (name, )
# TODO turn 'between' into a GH compare link
log += "Commits between [`%s`](%s) and [`%s`](%s) " % (
ver_a, url+prefix_ver+ver_a,
ver_b, url+prefix_ver+ver_b,
)
log += "(latest commit first):\n\n"
log += run_cmd(["git", "log",
"%s..%s" % (prefix_tag+ver_a, prefix_tag+ver_b),
"--pretty=format:* [`%h`]({}%H) %s".format(url+prefix_commit)],
log += run_cmd(
["git", "log", "%s..%s" % (prefix_tag+ver_a, prefix_tag+ver_b), "--pretty", f"format:* [`%h`]({url+prefix_commit}%H) %s"],
capture=True, check=True, cwd=cwd,
)
log += "\n\n</details>\n"
Expand All @@ -166,7 +165,7 @@ def _get_log(name, url, cwd, ver_a, ver_b, prefix_ver, prefix_commit, prefix_tag
def make_releasenotes(summary, prev_ns, curr_ns, c_updates):

relnotes = ""
relnotes += "## Changes (Release %s)\n\n" % curr_ns["V_PYPDFIUM2"]
relnotes += "## Changes (Release %s)\n\n" % (curr_ns["V_PYPDFIUM2"], )
relnotes += "### Summary (pypdfium2)\n\n"
if summary:
relnotes += summary + "\n"
Expand Down
14 changes: 7 additions & 7 deletions setupsrc/pypdfium2_setup/build_pdfium.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def dl_pdfium(GClient, do_update, revision):
run_cmd([GClient, "config", "--custom-var", "checkout_configuration=minimal", "--unmanaged", PDFium_URL], cwd=SB_Dir)

if is_sync:
run_cmd([GClient, "sync", "--revision", "origin/%s" % revision, "--no-history", "--with_branch_heads"], cwd=SB_Dir)
run_cmd([GClient, "sync", "--revision", f"origin/{revision}", "--no-history", "--with_branch_heads"], cwd=SB_Dir)

return is_sync

Expand Down Expand Up @@ -143,7 +143,7 @@ def get_pdfium_version():
tag_commit = tag_commit[:7]
tag = ref.split("/")[-1]

print("Current head %s, latest tagged commit %s (%s)" % (head_commit, tag_commit, tag), file=sys.stderr)
print(f"Current head {head_commit}, latest tagged commit {tag_commit} ({tag})", file=sys.stderr)

if head_commit == tag_commit:
v_libpdfium = tag
Expand Down Expand Up @@ -219,7 +219,7 @@ def find_lib(src_libname=None, directory=PDFiumBuildDir):
libname = "pdfium.dll"
else:
# TODO implement fallback artifact detection
raise RuntimeError("Not sure how pdfium artifact is called on platform '%s'" % (sys.platform, ))
raise RuntimeError(f"Not sure how pdfium artifact is called on platform '{sys.platform}'")

libpath = join(directory, libname)
assert os.path.exists(libpath)
Expand Down Expand Up @@ -256,13 +256,13 @@ def serialise_config(config_dict):
sep = ""

for key, value in config_dict.items():
config_str += sep + "%s = " % key
config_str += sep + f"{key} = "
if isinstance(value, bool):
config_str += str(value).lower()
elif isinstance(value, str):
config_str += '"%s"' % value
config_str += f'"{value}"'
else:
raise TypeError("Not sure how to serialise type %s" % type(value))
raise TypeError(f"Not sure how to serialise type {type(value).__name__}")
sep = "\n"

return config_str
Expand Down Expand Up @@ -316,7 +316,7 @@ def main(
if b_use_syslibs:
config_dict.update(SyslibsConfig)
config_str = serialise_config(config_dict)
print("\nBuild configuration:\n%s\n" % config_str)
print(f"\nBuild configuration:\n{config_str}\n")

configure(GN, config_str)
build(Ninja, b_target)
Expand Down
2 changes: 1 addition & 1 deletion setupsrc/pypdfium2_setup/check_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
def main():
missing = {cmd for cmd in Commands if not shutil.which(cmd)}
if len(missing) > 0:
raise RuntimeError("The following packages or commands are missing: %s" % missing)
raise RuntimeError(f"The following packages or commands are missing: {missing}")


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion setupsrc/pypdfium2_setup/craft_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __init__(self):
if len(self.plfile_paths) == 0:
return
elif len(self.plfile_paths) != 2:
print("Warning: Expected exactly 2 platform files, but found %s." % len(self.plfile_paths), file=sys.stderr)
print(f"Warning: Expected exactly 2 platform files, but found {len(self.plfile_paths)}.", file=sys.stderr)

self.tmp_dir = tempfile.TemporaryDirectory(prefix="pypdfium2_artefact_stash_")
for fp in self.plfile_paths:
Expand Down
14 changes: 7 additions & 7 deletions setupsrc/pypdfium2_setup/packaging_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,12 @@ def get_wheel_tag(pl_name):
tag = tag.replace(char, "_")
return tag
else:
raise ValueError("Unknown platform name %s" % pl_name)
raise ValueError(f"Unknown platform name {pl_name}")


def run_cmd(command, cwd, capture=False, check=True, **kwargs):

print('%s ("%s")' % (command, cwd), file=sys.stderr)
print(f"{command} (cwd='{cwd}')", file=sys.stderr)
if capture:
kwargs.update( dict(stdout=subprocess.PIPE, stderr=subprocess.STDOUT) )

Expand All @@ -203,7 +203,7 @@ def run_cmd(command, cwd, capture=False, check=True, **kwargs):


def get_latest_version():
git_ls = run_cmd(["git", "ls-remote", "%s.git" % ReleaseRepo], cwd=None, capture=True)
git_ls = run_cmd(["git", "ls-remote", f"{ReleaseRepo}.git"], cwd=None, capture=True)
tag = git_ls.split("\t")[-1]
return int( tag.split("/")[-1] )

Expand All @@ -213,9 +213,9 @@ def call_ctypesgen(target_dir, include_dir):
bindings = join(target_dir, BindingsFileName)
headers = sorted(glob( join(include_dir, "*.h") ))

run_cmd(["ctypesgen", "--library", "pdfium", "--runtime-libdir", ".", "--strip-build-path=%s" % include_dir, *headers, "-o", bindings], cwd=target_dir)
# https://github.com/ctypesgen/ctypesgen/issues/160
run_cmd(["ctypesgen", "--library", "pdfium", "--runtime-libdir", ".", f"--strip-build-path={include_dir}", *headers, "-o", bindings], cwd=target_dir)

# --strip-build-path fails for the header: https://github.com/ctypesgen/ctypesgen/issues/160
with open(bindings, "r") as file_reader:
text = file_reader.read()
text = text.replace(include_dir, ".")
Expand Down Expand Up @@ -255,7 +255,7 @@ def copy_platfiles(pl_name):
platfiles = get_platfiles(pl_name)
for fp in platfiles:
if not os.path.exists(fp):
raise RuntimeError("Platform file missing: %s" % fp)
raise RuntimeError(f"Platform file missing: {fp}")
shutil.copy(fp, ModuleDir)


Expand Down Expand Up @@ -311,7 +311,7 @@ def set_versions(ver_changes):
previous = template % (var, VerNamespace[var])
updated = template % (var, new_val)

print("'%s' -> '%s'" % (previous, updated))
print(f"'{previous}' -> '{updated}'")
assert content.count(previous) == 1
content = content.replace(previous, updated)

Expand Down
4 changes: 2 additions & 2 deletions setupsrc/pypdfium2_setup/setup_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ def mkwheel(pl_name):

pl_dir = join(DataTree, pl_name)
if not exists(pl_dir):
raise RuntimeError("Missing platform directory %s - you might have forgotten to run update_pdfium.py" % pl_name)
raise RuntimeError(f"Missing platform directory {pl_name} - you might have forgotten to run update_pdfium.py")

ver_file = join(pl_dir, VerStatusFileName)
if not exists(ver_file):
raise RuntimeError("Missing PDFium version file for %s" % pl_name)
raise RuntimeError(f"Missing PDFium version file for {pl_name}")

with open(ver_file, "r") as fh:
v_libpdfium = fh.read().strip()
Expand Down
10 changes: 5 additions & 5 deletions setupsrc/pypdfium2_setup/update_pdfium.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ def _get_package(latest_ver, robust, pl_name):
if not os.path.exists(pl_dir):
os.makedirs(pl_dir)

file_name = "%s.%s" % (ReleaseNames[pl_name], "tgz")
file_url = "%s%s/%s" % (ReleaseURL, latest_ver, file_name)
file_name = f"{ReleaseNames[pl_name]}.tgz"
file_url = f"{ReleaseURL}{latest_ver}/{file_name}"
file_path = join(pl_dir, file_name)
print("'%s' -> '%s'" % (file_url, file_path))
print(f"'{file_url}' -> '{file_path}'")

try:
request.urlretrieve(file_url, file_path)
Expand Down Expand Up @@ -114,7 +114,7 @@ def generate_bindings(archives, latest_ver):
elif "linux" in dirname:
target_name = "pdfium"
else:
raise ValueError("Unknown platform directory name '%s'" % dirname)
raise ValueError(f"Unknown platform directory name '{dirname}'")

items = os.listdir(bin_dir)
assert len(items) == 1
Expand Down Expand Up @@ -155,7 +155,7 @@ def parse_args(argv):
metavar = "identifier",
choices = platform_choices,
default = BinaryPlatforms,
help = "The platform(s) to include. Available platform identifiers are %s. `auto` represents the current host platform." % (platform_choices, ),
help = f"The platform(s) to include. `auto` represents the current host platform. Choices: {platform_choices}.",
)
parser.add_argument(
"--robust",
Expand Down

0 comments on commit a98cb78

Please sign in to comment.