Skip to content

Commit

Permalink
chore: replace %-formatting of strings with f-strings or format method
Browse files Browse the repository at this point in the history
Fixes ruff UP301 errors.
  • Loading branch information
jcristau committed Dec 3, 2024
1 parent f89760f commit e8d111e
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 18 deletions.
15 changes: 9 additions & 6 deletions src/taskgraph/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,9 @@ def _run(self):
all_tasks, Graph(frozenset(full_task_set.graph.nodes), frozenset(edges))
)
logger.info(
"Full task graph contains %d tasks and %d dependencies"
% (len(full_task_set.graph.nodes), len(edges))
"Full task graph contains {} tasks and {} dependencies".format(
len(full_task_set.graph.nodes), len(edges)
)
)
yield self.verify("full_task_graph", full_task_graph, graph_config, parameters)

Expand All @@ -356,8 +357,9 @@ def _run(self):
Graph(frozenset(target_tasks), frozenset()),
)
logger.info(
"Filter %s pruned %d tasks (%d remain)"
% (fltr.__name__, old_len - len(target_tasks), len(target_tasks))
"Filter {} pruned {} tasks ({} remain)".format(
fltr.__name__, old_len - len(target_tasks), len(target_tasks)
)
)

yield self.verify("target_task_set", target_task_set, graph_config, parameters)
Expand All @@ -375,8 +377,9 @@ def _run(self):
else:
always_target_tasks = set()
logger.info(
"Adding %d tasks with `always_target` attribute"
% (len(always_target_tasks) - len(always_target_tasks & target_tasks)) # type: ignore
"Adding {} tasks with `always_target` attribute".format(
(len(always_target_tasks) - len(always_target_tasks & target_tasks))
)
)
requested_tasks = target_tasks | always_target_tasks # type: ignore
target_graph = full_task_graph.graph.transitive_closure(requested_tasks)
Expand Down
4 changes: 2 additions & 2 deletions src/taskgraph/transforms/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,11 @@ def create_fetch_url_task(config, name, fetch):
"--sha256",
fetch["sha256"],
"--size",
"%d" % fetch["size"],
f"{fetch['size']}",
]

if fetch.get("strip-components"):
args.extend(["--strip-components", "%d" % fetch["strip-components"]])
args.extend(["--strip-components", f'{fetch["strip-components"]}'])

if fetch.get("add-prefix"):
args.extend(["--add-prefix", fetch["add-prefix"]])
Expand Down
2 changes: 1 addition & 1 deletion src/taskgraph/util/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def _quote(s):
not enclosed in quotes.
"""
if isinstance(s, int):
return "%d" % s
return f"{s}"

# Empty strings need to be quoted to have any significance
if s and not SHELL_QUOTE_RE.search(s) and not s.startswith("~"):
Expand Down
2 changes: 1 addition & 1 deletion test/test_optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ def test_get_subgraph(monkeypatch, graph, kwargs, exp_subgraph, exp_label_to_tas
4. The expected label_to_taskid.
"""
monkeypatch.setattr(
optimize_mod, "slugid", partial(next, ("tid%d" % i for i in range(1, 10)))
optimize_mod, "slugid", partial(next, (f"tid{i}" for i in range(1, 10)))
)

kwargs.setdefault("removed_tasks", set())
Expand Down
8 changes: 4 additions & 4 deletions test/test_util_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,22 @@ class TestArchive(unittest.TestCase):
def _create_files(self, root):
files = {}
for i in range(10):
p = os.path.join(root, "file%02d" % i)
p = os.path.join(root, f"file{i:02d}")
with open(p, "wb") as fh:
fh.write(b"file%02d" % i)
# Need to set permissions or umask may influence testing.
os.chmod(p, MODE_STANDARD)
files["file%02d" % i] = p
files[f"file{i:02d}"] = p

for i in range(10):
files["file%02d" % (i + 10)] = io.BytesIO(b"file%02d" % (i + 10))
files[f"file{i + 10:02d}"] = io.BytesIO(b"file%02d" % (i + 10))

return files

def _verify_basic_tarfile(self, tf):
self.assertEqual(len(tf.getmembers()), 20)

names = ["file%02d" % i for i in range(20)]
names = [f"file{i:02d}" for i in range(20)]
self.assertEqual(tf.getnames(), names)

for ti in tf.getmembers():
Expand Down
4 changes: 2 additions & 2 deletions test/test_util_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def test_create_context_extra_directory(self):
extra = os.path.join(tmp, "extra")
os.mkdir(extra)
for i in range(3):
p = os.path.join(extra, "file%d" % i)
p = os.path.join(extra, f"file{i}")
with open(p, "wb") as fh:
fh.write(b"file%d" % i)
os.chmod(p, MODE_STANDARD)
Expand Down Expand Up @@ -249,7 +249,7 @@ def test_stream_context_tar(self):
extra = os.path.join(tmp, "extra")
os.mkdir(extra)
for i in range(3):
p = os.path.join(extra, "file%d" % i)
p = os.path.join(extra, f"file{i}")
with open(p, "wb") as fh:
fh.write(b"file%d" % i)
os.chmod(p, MODE_STANDARD)
Expand Down
4 changes: 2 additions & 2 deletions test/test_util_parameterization.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_timestamps_appears_with_other_keys():
@pytest.fixture
def assert_task_refs():
def inner(input, output):
taskid_for_edge_name = {"edge%d" % n: "tid%d" % n for n in range(1, 4)}
taskid_for_edge_name = {f"edge{n}": f"tid{n}" for n in range(1, 4)}
assert (
resolve_task_references(
"subject",
Expand Down Expand Up @@ -151,7 +151,7 @@ def assert_artifact_refs(monkeypatch):
def inner(input, output):
# Clear memoized function
get_root_url.cache_clear()
taskid_for_edge_name = {"edge%d" % n: "tid%d" % n for n in range(1, 4)}
taskid_for_edge_name = {f"edge{n}": f"tid{n}" for n in range(1, 4)}
assert (
resolve_task_references(
"subject", input, "tid-self", "tid-decision", taskid_for_edge_name
Expand Down

0 comments on commit e8d111e

Please sign in to comment.