From 091750ae5253b62f89b0f7761191e62c9b31a8dd Mon Sep 17 00:00:00 2001 From: Andrew Halberstadt Date: Thu, 3 Mar 2022 16:51:18 +0000 Subject: [PATCH] Bug 1748926 - [taskgraph] Move Task.name to a utility file, r=taskgraph-reviewers,aki The standalone taskgraph does not have this property. Rather than upstream it, I prefer to move it to a utility file. This is because it's not clear what "name" means, or why the label minus the kind equals a "name", or why if a task doesn't have the kind in its label it raises an Exception. Plus this property was only used in two places, and both were Gecko specific. Differential Revision: https://phabricator.services.mozilla.com/D140081 --- taskcluster/gecko_taskgraph/task.py | 7 ------- taskcluster/gecko_taskgraph/transforms/l10n.py | 7 +++++-- taskcluster/gecko_taskgraph/transforms/update_verify.py | 3 ++- taskcluster/gecko_taskgraph/util/attributes.py | 7 +++++++ 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/taskcluster/gecko_taskgraph/task.py b/taskcluster/gecko_taskgraph/task.py index 7fd9a646b0de..35c7ee3ac693 100644 --- a/taskcluster/gecko_taskgraph/task.py +++ b/taskcluster/gecko_taskgraph/task.py @@ -49,13 +49,6 @@ class Task: def __attrs_post_init__(self): self.attributes["kind"] = self.kind - @property - def name(self): - if self.label.startswith(self.kind + "-"): - return self.label[len(self.kind) + 1 :] - else: - raise AttributeError(f"Task {self.label} does not have a name.") - def to_json(self): rv = { "kind": self.kind, diff --git a/taskcluster/gecko_taskgraph/transforms/l10n.py b/taskcluster/gecko_taskgraph/transforms/l10n.py index ec4bf19b7955..056ae4441ee9 100644 --- a/taskcluster/gecko_taskgraph/transforms/l10n.py +++ b/taskcluster/gecko_taskgraph/transforms/l10n.py @@ -17,7 +17,10 @@ from gecko_taskgraph.util.schema import ( resolve_keyed_by, taskref_or_string, ) -from gecko_taskgraph.util.attributes import copy_attributes_from_dependent_job +from gecko_taskgraph.util.attributes import ( + copy_attributes_from_dependent_job, + task_name, +) from gecko_taskgraph.util.taskcluster import get_artifact_prefix from gecko_taskgraph.util.treeherder import add_suffix from gecko_taskgraph.transforms.job import job_description_schema @@ -159,7 +162,7 @@ def setup_name(config, jobs): dep = job["primary-dependency"] # Set the name to the same as the dep task, without kind name. # Label will get set automatically with this kinds name. - job["name"] = job.get("name", dep.name) + job["name"] = job.get("name", task_name(dep)) yield job diff --git a/taskcluster/gecko_taskgraph/transforms/update_verify.py b/taskcluster/gecko_taskgraph/transforms/update_verify.py index 5dd0ea095302..7f47013d6e65 100644 --- a/taskcluster/gecko_taskgraph/transforms/update_verify.py +++ b/taskcluster/gecko_taskgraph/transforms/update_verify.py @@ -9,6 +9,7 @@ Transform the beetmover task into an actual task description. from copy import deepcopy from gecko_taskgraph.transforms.base import TransformSequence +from gecko_taskgraph.util.attributes import task_name from gecko_taskgraph.util.treeherder import add_suffix, inherit_treeherder_from_dep transforms = TransformSequence() @@ -22,7 +23,7 @@ def add_command(config, tasks): "update-verify-config" in dep.kind or "update-verify-next-config" in dep.kind ): - config_tasks[dep.name] = dep + config_tasks[task_name(dep)] = dep for task in tasks: config_task = config_tasks[task["name"]] diff --git a/taskcluster/gecko_taskgraph/util/attributes.py b/taskcluster/gecko_taskgraph/util/attributes.py index 4f8febb7d961..d08328b111ae 100644 --- a/taskcluster/gecko_taskgraph/util/attributes.py +++ b/taskcluster/gecko_taskgraph/util/attributes.py @@ -172,3 +172,10 @@ def is_try(params): `mach try fuzzy`. """ return "try" in params["project"] or params["try_mode"] == "try_select" + + +def task_name(task): + if task.label.startswith(task.kind + "-"): + return task.label[len(task.kind) + 1 :] + else: + raise AttributeError(f"Task {task.label} does not have a name.")