Skip to content

Commit 5521b7b

Browse files
committed
Fixup Python formatting and ruff lints
1 parent 7df5609 commit 5521b7b

15 files changed

+44
-59
lines changed

automation/prepare-release.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
moz_remote = get_moz_remote()
3030

3131
# 2. Figure out the current version
32-
with open(VERSION_FILE, "r") as stream:
32+
with open(VERSION_FILE) as stream:
3333
cur_version = stream.read().strip()
3434

3535
major_version_number = int(cur_version.split(".")[0])
@@ -59,7 +59,7 @@
5959
stream.write(new_version)
6060

6161
step_msg(f"updating {CHANGELOG_FILE}")
62-
with open(CHANGELOG_FILE, "r") as stream:
62+
with open(CHANGELOG_FILE) as stream:
6363
changelog = stream.read().splitlines()
6464

6565
if changelog[0] != f"# v{major_version_number}.0 (In progress)":

automation/publish_to_maven_local_if_modified.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
import argparse
1111
import hashlib
1212
import os
13+
import shutil
1314
import sys
1415
import time
15-
import shutil
1616

1717
from shared import fatal_err, find_app_services_root, run_cmd_checked
1818

automation/symbols-generation/symbolstore.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
# -s <srcdir> : Use <srcdir> as the top source directory to
2222
# generate relative filenames.
2323

24-
from __future__ import print_function
2524

2625
import ctypes
2726
import errno
@@ -441,7 +440,7 @@ def dump_syms_cmdline(self, file, arch, dsymbundle=None):
441440
def dump_syms_extra_info(self):
442441
return [
443442
"--extra-info",
444-
"VERSION {}".format(get_version(self.srcdirs)),
443+
f"VERSION {get_version(self.srcdirs)}",
445444
"--extra-info",
446445
"PRODUCTNAME ApplicationServices",
447446
]

automation/symbols-generation/upload_symbols.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# License, v. 2.0. If a copy of the MPL was not distributed with this
44
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
55

6-
from __future__ import print_function
76

87
import os
98
import shutil
@@ -19,7 +18,7 @@
1918

2019
def upload_symbols(zip_file, token_file):
2120
print(
22-
"Uploading symbols file '{0}' to '{1}'".format(zip_file, DEFAULT_SYMBOL_URL),
21+
f"Uploading symbols file '{zip_file}' to '{DEFAULT_SYMBOL_URL}'",
2322
file=sys.stdout,
2423
)
2524
zip_name = os.path.basename(zip_file)
@@ -28,7 +27,7 @@ def upload_symbols(zip_file, token_file):
2827
# already that communication with Taskcluster to get the credentials for
2928
# communicating with the server
3029
auth_token = ""
31-
with open(token_file, "r") as f:
30+
with open(token_file) as f:
3231
auth_token = f.read().strip()
3332
if len(auth_token) == 0:
3433
print("Failed to get the symbol token.", file=sys.stderr)
@@ -51,15 +50,15 @@ def upload_symbols(zip_file, token_file):
5150
# has to fetch the entire zip file, which can take a while. The load balancer
5251
# in front of symbols.mozilla.org has a 300 second timeout, so we'll use that.
5352
timeout=(10, 300),
54-
**zip_arg
53+
**zip_arg,
5554
)
5655
# 500 is likely to be a transient failure.
5756
# Break out for success or other error codes.
5857
if r.status_code < 500:
5958
break
60-
print("Error: {0}".format(r), file=sys.stderr)
59+
print(f"Error: {r}", file=sys.stderr)
6160
except requests.exceptions.RequestException as e:
62-
print("Error: {0}".format(e), file=sys.stderr)
61+
print(f"Error: {e}", file=sys.stderr)
6362
print("Retrying...", file=sys.stdout)
6463
else:
6564
print("Maximum retries hit, giving up!", file=sys.stderr)
@@ -69,7 +68,7 @@ def upload_symbols(zip_file, token_file):
6968
print("Uploaded successfully", file=sys.stdout)
7069
return True
7170

72-
print("Upload symbols failed: {0}".format(r), file=sys.stderr)
71+
print(f"Upload symbols failed: {r}", file=sys.stderr)
7372
print(r.text, file=sys.stderr)
7473
return False
7574

automation/tests.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@
6565
def blue_text(text):
6666
if not sys.stdout.isatty():
6767
return text
68-
return "\033[96m{}\033[0m".format(text)
68+
return f"\033[96m{text}\033[0m"
6969

7070

7171
def yellow_text(text):
7272
if not sys.stdout.isatty():
7373
return text
74-
return "\033[93m{}\033[0m".format(text)
74+
return f"\033[93m{text}\033[0m"
7575

7676

7777
def get_output(cmdline, **kwargs):
@@ -316,7 +316,7 @@ def touch_changed_paths(branch_changes):
316316

317317

318318
def print_rust_environment():
319-
print("platform: {}".format(platform.uname()))
319+
print(f"platform: {platform.uname()}")
320320
print("rustc version: {}".format(get_output(["rustc", "--version"]).strip()))
321321
print("cargo version: {}".format(get_output(["cargo", "--version"]).strip()))
322322
print("rustfmt version: {}".format(get_output(["rustfmt", "--version"]).strip()))
@@ -498,15 +498,15 @@ def __init__(self, name, func, *args, **kwargs):
498498

499499
def run(self):
500500
print()
501-
print(blue_text("Running {}".format(self.name)))
501+
print(blue_text(f"Running {self.name}"))
502502
try:
503503
self.func(*self.args, **self.kwargs)
504504
except subprocess.CalledProcessError:
505-
exit_with_error(1, "Error while running {}".format(self.name))
505+
exit_with_error(1, f"Error while running {self.name}")
506506
except Exception:
507507
exit_with_error(
508508
2,
509-
"Unexpected exception while running {}".format(self.name),
509+
f"Unexpected exception while running {self.name}",
510510
print_exception=True,
511511
)
512512

@@ -528,7 +528,7 @@ def calc_steps(args):
528528
for package, features in calc_rust_items():
529529
if should_run_rust_tests(package, False):
530530
yield Step(
531-
"tests for {} ({})".format(package.name, features.label()),
531+
f"tests for {package.name} ({features.label()})",
532532
run_rust_test,
533533
package,
534534
features,
@@ -539,7 +539,7 @@ def calc_steps(args):
539539
for package, features in calc_rust_items():
540540
if should_run_rust_tests(package, True):
541541
yield Step(
542-
"tests for {} ({})".format(package.name, features.label()),
542+
f"tests for {package.name} ({features.label()})",
543543
run_rust_test,
544544
package,
545545
features,
@@ -549,7 +549,7 @@ def calc_steps(args):
549549
yield Step("cargo clean", cargo_clean)
550550
for package, features in calc_rust_items():
551551
yield Step(
552-
"clippy for {} ({})".format(package.name, features.label()),
552+
f"clippy for {package.name} ({features.label()})",
553553
run_clippy,
554554
package,
555555
features,
@@ -558,7 +558,7 @@ def calc_steps(args):
558558
# make sure they don't go stale.
559559
for package, features in calc_non_workspace_rust_items():
560560
yield Step(
561-
"clippy for {} ({})".format(package.name, features.label()),
561+
f"clippy for {package.name} ({features.label()})",
562562
run_clippy,
563563
package,
564564
features,
@@ -582,7 +582,7 @@ def calc_steps(args):
582582
elif args.mode == "python-tests":
583583
yield Step("python tests", run_python_tests)
584584
else:
585-
print("Invalid mode: {}".format(args.mode))
585+
print(f"Invalid mode: {args.mode}")
586586
sys.exit(1)
587587

588588

@@ -614,22 +614,20 @@ def calc_steps_change_mode(args):
614614
yield Step("touch changed paths", touch_changed_paths, branch_changes)
615615
for package, features in rust_items:
616616
yield Step(
617-
"tests for {} ({})".format(package.name, features.label()),
617+
f"tests for {package.name} ({features.label()})",
618618
run_rust_test,
619619
package,
620620
features,
621621
)
622622
for package, features in rust_items:
623623
yield Step(
624-
"clippy for {} ({})".format(package.name, features.label()),
624+
f"clippy for {package.name} ({features.label()})",
625625
run_clippy,
626626
package,
627627
features,
628628
)
629629
for package in rust_packages:
630-
yield Step(
631-
"rustfmt for {}".format(package.name), cargo_fmt, package, fix_issues=True
632-
)
630+
yield Step(f"rustfmt for {package.name}", cargo_fmt, package, fix_issues=True)
633631
yield Step("Check for changes", check_for_fmt_changes, branch_changes)
634632

635633

taskcluster/app_services_taskgraph/build_config.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def get_version_from_version_txt():
5151
current_dir = os.path.dirname(os.path.realpath(__file__))
5252
project_dir = os.path.realpath(os.path.join(current_dir, "..", ".."))
5353

54-
with open(os.path.join(project_dir, "version.txt"), "r") as f:
54+
with open(os.path.join(project_dir, "version.txt")) as f:
5555
return f.read().strip()
5656

5757

@@ -62,9 +62,7 @@ def get_extensions(module_name):
6262
artifact_type = publication["type"]
6363
if artifact_type not in EXTENSIONS:
6464
raise ValueError(
65-
"For '{}', 'publication->type' must be one of {}".format(
66-
module_name, repr(EXTENSIONS.keys())
67-
)
65+
f"For '{module_name}', 'publication->type' must be one of {repr(EXTENSIONS.keys())}"
6866
)
6967
extensions[publication["name"]] = [
7068
extension + checksum_extension

taskcluster/app_services_taskgraph/job.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
44

55

6-
from pipes import quote as shell_quote
6+
from shlex import quote as shell_quote
77

88
from taskgraph.transforms.run import configure_taskdesc_for_run, run_task_using
99
from taskgraph.util.schema import Schema, taskref_or_string

taskcluster/app_services_taskgraph/transforms/__init__.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,9 @@ def publications_to_artifact_map_paths(
4444
artifact_filename = _artifact_filename(publication_name, version, extension)
4545
if preview_build is not None:
4646
# Both nightly and other preview builds are places in separate directory
47-
destination = "maven2/org/mozilla/appservices/nightly/{}/{}/{}".format(
48-
publication_name, version, artifact_filename
49-
)
47+
destination = f"maven2/org/mozilla/appservices/nightly/{publication_name}/{version}/{artifact_filename}"
5048
else:
51-
destination = "maven2/org/mozilla/appservices/{}/{}/{}".format(
52-
publication_name, version, artifact_filename
53-
)
49+
destination = f"maven2/org/mozilla/appservices/{publication_name}/{version}/{artifact_filename}"
5450
build_map_paths[f"public/build/{artifact_filename}"] = {
5551
"checksums_path": "", # XXX beetmover marks this as required, but it's not needed
5652
"destinations": [destination],

taskcluster/app_services_taskgraph/transforms/deps_complete.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ def add_alert_routes(config, tasks):
7171
task.setdefault("routes", [])
7272
for name, value in alerts.items():
7373
if name not in ("slack-channel", "email", "pulse", "matrix-room"):
74-
raise KeyError("Unknown alert type: {}".format(name))
75-
task["routes"].append("notify.{}.{}.on-failed".format(name, value))
74+
raise KeyError(f"Unknown alert type: {name}")
75+
task["routes"].append(f"notify.{name}.{value}.on-failed")
7676
yield task
7777

7878

taskcluster/scripts/generate-nimbus-cli-json.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def dump_json(args):
2929
dir = os.path.dirname(args.path)
3030
if not os.path.exists(dir):
3131
os.makedirs(dir)
32-
with open(args.path, "wt") as f:
32+
with open(args.path, "w") as f:
3333
json.dump(data, f)
3434

3535

taskcluster/scripts/generate-release-json.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def dump_json(args):
5252
dir = os.path.dirname(args.path)
5353
if not os.path.exists(dir):
5454
os.makedirs(dir)
55-
with open(args.path, "wt") as f:
55+
with open(args.path, "w") as f:
5656
json.dump(data, f)
5757

5858

taskcluster/scripts/server-megazord-build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def _patch_uniffi_tomls():
145145

146146

147147
def _replace_text(filename, search, replace):
148-
with open(filename, "r") as file:
148+
with open(filename) as file:
149149
data = file.read()
150150
data = data.replace(search, replace)
151151
with open(filename, "w") as file:

tools/dependency_summary.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,6 @@
904904
"fixup": "https://raw.githubusercontent.com/dtolnay/unicode-ident/master/LICENSE-APACHE",
905905
},
906906
},
907-
908907
"xshell-macros": {
909908
"license": {
910909
"check": "MIT OR Apache-2.0",
@@ -959,7 +958,7 @@ def subprocess_run_cargo(args):
959958
("cargo",) + args,
960959
env=env,
961960
stdout=subprocess.PIPE,
962-
universal_newlines=True,
961+
text=True,
963962
check=False,
964963
)
965964
p.check_returncode()
@@ -975,7 +974,7 @@ def get_workspace_metadata():
975974
)
976975

977976

978-
class WorkspaceMetadata(object):
977+
class WorkspaceMetadata:
979978
"""Package metadata for all dependencies in the workspace.
980979
981980
This uses `cargo metadata` to load the complete set of package metadata for the dependency tree
@@ -1192,9 +1191,7 @@ def pick_most_acceptable_license(self, id, licenseId):
11921191
if license in licenses:
11931192
return license
11941193
raise RuntimeError(
1195-
"Could not determine acceptable license for {}; license is '{}'".format(
1196-
id, licenseId
1197-
)
1194+
f"Could not determine acceptable license for {id}; license is '{licenseId}'"
11981195
)
11991196

12001197
def _find_license_file(self, id, license, pkgInfo):
@@ -1222,7 +1219,7 @@ def _find_license_file(self, id, license, pkgInfo):
12221219
pkgInfo["name"]
12231220
)
12241221
err += "Please select the correct license file and add it to `PACKAGE_METADATA_FIXUPS`.\n"
1225-
err += "Potential license files: {}".format(foundLicenseFiles)
1222+
err += f"Potential license files: {foundLicenseFiles}"
12261223
else:
12271224
err = "Could not find license file for '{}'.\n".format(pkgInfo["name"])
12281225
err += "Please locate the correct license file and add it to `PACKAGE_METADATA_FIXUPS`.\n"
@@ -1288,10 +1285,8 @@ def _find_license_url(self, id, chosenLicense, licenseFile, pkgInfo):
12881285
if licenseUrl is None:
12891286
err = "Could not infer license URL for '{}'.\n".format(pkgInfo["name"])
12901287
err += "Please locate the correct license URL and add it to `PACKAGE_METADATA_FIXUPS`.\n"
1291-
err += "You may need to poke around in the source repository at {}".format(
1292-
repo
1293-
)
1294-
err += " for a {} license file named {}.".format(chosenLicense, licenseFile)
1288+
err += f"You may need to poke around in the source repository at {repo}"
1289+
err += f" for a {chosenLicense} license file named {licenseFile}."
12951290
raise RuntimeError(err)
12961291
# As a special case, convert raw github URLs back into human-friendly page URLs.
12971292
if licenseUrl.startswith("https://raw.githubusercontent.com/"):
@@ -1314,7 +1309,7 @@ def make_license_title(license, deps=None):
13141309
elif license == "Apache-2.0":
13151310
title = "Apache License 2.0"
13161311
else:
1317-
title = "{} License".format(license)
1312+
title = f"{license} License"
13181313
if deps:
13191314
# Dedupe in case of multiple versions of dependencies
13201315
names = sorted(set(d["name"] for d in deps))
@@ -1560,7 +1555,7 @@ def pf(string, *args):
15601555
if args.check:
15611556
output.seek(0)
15621557
outlines = output.readlines()
1563-
with open(args.check, "r") as f:
1558+
with open(args.check) as f:
15641559
checklines = f.readlines()
15651560
if outlines != checklines:
15661561
raise RuntimeError(

tools/loc_summary.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def get_loc_summary(path):
6868
path,
6969
],
7070
stdout=subprocess.PIPE,
71-
universal_newlines=True,
71+
text=True,
7272
check=False,
7373
)
7474
p.check_returncode()

tools/update-moz-central-vendoring.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def get_app_services_rev():
5959

6060
def update_cargo_toml(cargo_toml_path, app_services_rev):
6161
print(f"Updating application-services revision to {app_services_rev}")
62-
with open(cargo_toml_path, "r") as f:
62+
with open(cargo_toml_path) as f:
6363
lines = f.readlines()
6464
for i in range(len(lines)):
6565
line = lines[i]

0 commit comments

Comments
 (0)