From f89760f035bd56382dee71a8b23eef42e81281ab Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 2 Dec 2024 18:15:19 +0000 Subject: [PATCH 1/3] chore: pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.6.9 → v0.8.1](https://github.com/astral-sh/ruff-pre-commit/compare/v0.6.9...v0.8.1) - [github.com/compilerla/conventional-pre-commit: v3.4.0 → v3.6.0](https://github.com/compilerla/conventional-pre-commit/compare/v3.4.0...v3.6.0) --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f699ee441..60dbfc01b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -15,7 +15,7 @@ repos: exclude: template - id: check-added-large-files - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.6.9 + rev: v0.8.1 hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] @@ -35,7 +35,7 @@ repos: test/test_util_path.py )$ - repo: https://github.com/compilerla/conventional-pre-commit - rev: v3.4.0 + rev: v3.6.0 hooks: - id: conventional-pre-commit stages: [commit-msg] From 0e4f80ee3e76c6066f7e08cdcb0c914990b36085 Mon Sep 17 00:00:00 2001 From: Julien Cristau Date: Tue, 3 Dec 2024 11:11:30 +0100 Subject: [PATCH 2/3] chore: replace %-formatting of strings with f-strings or `format` method Fixes ruff UP301 errors. --- src/taskgraph/generator.py | 15 +++++++++------ src/taskgraph/transforms/fetch.py | 4 ++-- src/taskgraph/util/shell.py | 2 +- test/test_optimize.py | 2 +- test/test_util_archive.py | 8 ++++---- test/test_util_docker.py | 4 ++-- test/test_util_parameterization.py | 4 ++-- 7 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/taskgraph/generator.py b/src/taskgraph/generator.py index 3fea99f0b..6d7ce7c29 100644 --- a/src/taskgraph/generator.py +++ b/src/taskgraph/generator.py @@ -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) @@ -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) @@ -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)) # type: ignore + ) ) requested_tasks = target_tasks | always_target_tasks # type: ignore target_graph = full_task_graph.graph.transitive_closure(requested_tasks) diff --git a/src/taskgraph/transforms/fetch.py b/src/taskgraph/transforms/fetch.py index 895167a6a..a38f0a9b7 100644 --- a/src/taskgraph/transforms/fetch.py +++ b/src/taskgraph/transforms/fetch.py @@ -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"]]) diff --git a/src/taskgraph/util/shell.py b/src/taskgraph/util/shell.py index 16b71b7d6..a6f3e0d52 100644 --- a/src/taskgraph/util/shell.py +++ b/src/taskgraph/util/shell.py @@ -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("~"): diff --git a/test/test_optimize.py b/test/test_optimize.py index 0769c5448..cf2560d5e 100644 --- a/test/test_optimize.py +++ b/test/test_optimize.py @@ -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()) diff --git a/test/test_util_archive.py b/test/test_util_archive.py index 6def31157..69c9c58c3 100644 --- a/test/test_util_archive.py +++ b/test/test_util_archive.py @@ -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(): diff --git a/test/test_util_docker.py b/test/test_util_docker.py index b7c038410..18034bbec 100644 --- a/test/test_util_docker.py +++ b/test/test_util_docker.py @@ -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) @@ -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) diff --git a/test/test_util_parameterization.py b/test/test_util_parameterization.py index 15f1dbf0a..5894b55a3 100644 --- a/test/test_util_parameterization.py +++ b/test/test_util_parameterization.py @@ -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", @@ -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 From 7e208bf6e09b393a30992aaa1f3f31aeea5fd2ce Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 3 Dec 2024 10:16:04 +0000 Subject: [PATCH 3/3] style: pre-commit.ci auto fixes [...] --- src/taskgraph/generator.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/taskgraph/generator.py b/src/taskgraph/generator.py index 6d7ce7c29..e8626ba8c 100644 --- a/src/taskgraph/generator.py +++ b/src/taskgraph/generator.py @@ -338,9 +338,7 @@ def _run(self): all_tasks, Graph(frozenset(full_task_set.graph.nodes), frozenset(edges)) ) logger.info( - "Full task graph contains {} tasks and {} dependencies".format( - len(full_task_set.graph.nodes), len(edges) - ) + f"Full task graph contains {len(full_task_set.graph.nodes)} tasks and {len(edges)} dependencies" ) yield self.verify("full_task_graph", full_task_graph, graph_config, parameters) @@ -357,9 +355,7 @@ def _run(self): Graph(frozenset(target_tasks), frozenset()), ) logger.info( - "Filter {} pruned {} tasks ({} remain)".format( - fltr.__name__, old_len - len(target_tasks), len(target_tasks) - ) + f"Filter {fltr.__name__} pruned {old_len - len(target_tasks)} tasks ({len(target_tasks)} remain)" ) yield self.verify("target_task_set", target_task_set, graph_config, parameters) @@ -377,9 +373,7 @@ def _run(self): else: always_target_tasks = set() logger.info( - "Adding {} tasks with `always_target` attribute".format( - (len(always_target_tasks) - len(always_target_tasks & target_tasks)) # type: ignore - ) + f"Adding {len(always_target_tasks) - len(always_target_tasks & target_tasks)} tasks with `always_target` attribute" # type: ignore ) requested_tasks = target_tasks | always_target_tasks # type: ignore target_graph = full_task_graph.graph.transitive_closure(requested_tasks)