Skip to content

Commit 144fb64

Browse files
style: pre-commit.ci auto fixes [...]
1 parent 51c3a7a commit 144fb64

10 files changed

Lines changed: 34 additions & 110 deletions

File tree

builddecisionscript/src/builddecisionscript/cron/__init__.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,7 @@ def run(*, repository, branch, force_run, cron_input=None, dry_run):
110110
except Exception as exc:
111111
failed_jobs.append((job_name, exc))
112112
traceback.print_exc()
113-
logger.error(
114-
f'cron job "{job_name}" run failed; continuing to next job'
115-
)
113+
logger.error(f'cron job "{job_name}" run failed; continuing to next job')
116114

117115
else:
118116
logger.info(f'not running cron job "{job_name}"')
@@ -123,12 +121,9 @@ def run(*, repository, branch, force_run, cron_input=None, dry_run):
123121
def _format_and_raise_error_if_any(failed_jobs):
124122
if failed_jobs:
125123
failed_job_names = [job_name for job_name, _ in failed_jobs]
126-
failed_job_names_with_exceptions = (
127-
f'"{job_name}": "{exc}"' for job_name, exc in failed_jobs
128-
)
124+
failed_job_names_with_exceptions = (f'"{job_name}": "{exc}"' for job_name, exc in failed_jobs)
129125
raise RuntimeError(
130-
"Cron jobs {} couldn't be triggered properly. "
131-
"Reason(s):\n * {}\nSee logs above for details.".format(
126+
"Cron jobs {} couldn't be triggered properly. Reason(s):\n * {}\nSee logs above for details.".format(
132127
failed_job_names, "\n * ".join(failed_job_names_with_exceptions)
133128
)
134129
)

builddecisionscript/src/builddecisionscript/cron/decision.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ def run_decision_task(job_name, job, *, repository, push_info, cron_input=None,
3535
push_info = copy.deepcopy(push_info)
3636
push_info["owner"] = "cron"
3737

38-
taskcluster_yml = repository.get_file(
39-
".taskcluster.yml", revision=push_info["revision"]
40-
)
38+
taskcluster_yml = repository.get_file(".taskcluster.yml", revision=push_info["revision"])
4139

4240
arguments = make_arguments(job)
4341

builddecisionscript/src/builddecisionscript/cron/util.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,10 @@ def calculate_time():
5151
time = datetime.datetime.utcfromtimestamp(int(os.environ["CRON_TIME"]))
5252
logger.info("cron time: %s", time)
5353
else:
54-
logger.warning(
55-
"using current time for time; try setting $CRON_TIME to a timestamp"
56-
)
54+
logger.warning("using current time for time; try setting $CRON_TIME to a timestamp")
5755
time = datetime.datetime.utcnow()
5856
else:
59-
queue = taskcluster.Queue(
60-
{"rootUrl": os.environ["TASKCLUSTER_PROXY_URL"]}, session=SESSION
61-
)
57+
queue = taskcluster.Queue({"rootUrl": os.environ["TASKCLUSTER_PROXY_URL"]}, session=SESSION)
6258
task = queue.task(os.environ["TASK_ID"])
6359
created = task["created"]
6460
time = datetime.datetime.strptime(created, "%Y-%m-%dT%H:%M:%S.%fZ")

builddecisionscript/src/builddecisionscript/decision.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import attr
1010
import jsone
1111
import slugid
12+
1213
import taskcluster
1314

1415
from .util.http import SESSION
@@ -56,7 +57,5 @@ def submit(self):
5657
session=SESSION,
5758
)
5859
else:
59-
queue = taskcluster.Queue(
60-
taskcluster.optionsFromEnvironment(), session=SESSION
61-
)
60+
queue = taskcluster.Queue(taskcluster.optionsFromEnvironment(), session=SESSION)
6261
queue.createTask(self.task_id, self.task_payload)

builddecisionscript/src/builddecisionscript/repository.py

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,9 @@ def get_file(self, path, *, revision=None):
5252
headers["Authorization"] = f"token {self.github_token}"
5353
headers["Accept"] = "application/vnd.github.raw+json"
5454
elif repo_url.startswith("git@github.com:"):
55-
raise Exception(
56-
f"Don't know how to get file from private github repo: {repo_url}"
57-
)
55+
raise Exception(f"Don't know how to get file from private github repo: {repo_url}")
5856
else:
59-
raise Exception(
60-
"Don't know how to determine get file for non-github "
61-
f"repo: {repo_url}"
62-
)
57+
raise Exception(f"Don't know how to determine get file for non-github repo: {repo_url}")
6358
else:
6459
raise Exception(f"Unknown repository_type {self.repository_type}!")
6560

@@ -94,24 +89,16 @@ def get_push_info(self, *, revision=None, branch=None):
9489
res.raise_for_status()
9590
pushes = res.json()["pushes"]
9691
if len(pushes) == 0:
97-
raise NoPushesError(
98-
f"Changeset {revset} has no associated pushes. "
99-
"Maybe the push log has not been updated?"
100-
)
92+
raise NoPushesError(f"Changeset {revset} has no associated pushes. Maybe the push log has not been updated?")
10193
elif len(pushes) != 1:
102-
raise ValueError(
103-
f"Changeset {revset} has {len(pushes)} associated pushes; "
104-
"only one supported."
105-
)
94+
raise ValueError(f"Changeset {revset} has {len(pushes)} associated pushes; only one supported.")
10695
[(push_id, push_info)] = pushes.items()
10796
changesets = push_info["changesets"]
10897
first_pushed_revision = changesets[0]
10998
base_revision = first_pushed_revision["parents"][0]
11099
tip_revision = changesets[-1]["node"]
111100
if revision and revision != tip_revision:
112-
raise ValueError(
113-
f"Changeset {revision} is not the tip {tip_revision} of the associated push."
114-
)
101+
raise ValueError(f"Changeset {revision} is not the tip {tip_revision} of the associated push.")
115102

116103
return {
117104
"owner": push_info["user"],
@@ -130,38 +117,25 @@ def get_push_info(self, *, revision=None, branch=None):
130117
if self.github_token:
131118
headers["Authorization"] = f"token {self.github_token}"
132119
if repo_url.startswith("https://github.com/"):
133-
url = (
134-
f"https://api.github.com"
135-
f"/repos/{self.repo_path}/git/ref/heads/{branch}"
136-
)
120+
url = f"https://api.github.com/repos/{self.repo_path}/git/ref/heads/{branch}"
137121
res = SESSION.get(url, headers=headers, timeout=60)
138122
res.raise_for_status()
139123
return {
140124
"branch": branch,
141125
"revision": res.json()["object"]["sha"],
142126
}
143127
elif repo_url.startswith("git@github.com:"):
144-
raise Exception(
145-
"Don't know how to determine revision for private github "
146-
f"repo: {repo_url}"
147-
)
128+
raise Exception(f"Don't know how to determine revision for private github repo: {repo_url}")
148129
else:
149-
raise Exception(
150-
"Don't know how to determine revision for non-github "
151-
f"repo: {repo_url}"
152-
)
130+
raise Exception(f"Don't know how to determine revision for non-github repo: {repo_url}")
153131
else:
154132
raise Exception(f"Unknown repository_type {self.repository_type}!")
155133

156134
@property
157135
def repo_path(self):
158-
if self.repository_type == "hg" and self.repo_url.startswith(
159-
"https://hg.mozilla.org/"
160-
):
136+
if self.repository_type == "hg" and self.repo_url.startswith("https://hg.mozilla.org/"):
161137
return self.repo_url.replace("https://hg.mozilla.org/", "", 1).rstrip("/")
162-
elif self.repository_type == "git" and self.repo_url.startswith(
163-
"https://github.com/"
164-
):
138+
elif self.repository_type == "git" and self.repo_url.startswith("https://github.com/"):
165139
return self.repo_url.replace("https://github.com/", "", 1).rstrip("/")
166140
else:
167141
raise AttributeError(f"no repo_path available for {self.repo_url}")

builddecisionscript/src/builddecisionscript/script.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,7 @@ def get_default_config(base_dir=None):
7575
return {
7676
"work_dir": os.path.join(base_dir, "work_dir"),
7777
"artifact_dir": os.path.join(base_dir, "artifact_dir"),
78-
"schema_file": os.path.join(
79-
os.path.dirname(__file__), "data", "builddecisionscript_task_schema.json"
80-
),
78+
"schema_file": os.path.join(os.path.dirname(__file__), "data", "builddecisionscript_task_schema.json"),
8179
}
8280

8381

builddecisionscript/src/builddecisionscript/util/keyed_by.py

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -54,43 +54,28 @@ def evaluate_keyed_by(value, item_name, attributes):
5454
default: 12
5555
"""
5656
while True:
57-
if (
58-
not isinstance(value, dict)
59-
or len(value) != 1
60-
or not list(value.keys())[0].startswith("by-")
61-
):
57+
if not isinstance(value, dict) or len(value) != 1 or not list(value.keys())[0].startswith("by-"):
6258
return value
6359

6460
keyed_by = list(value.keys())[0][3:] # strip off 'by-' prefix
6561
key = attributes.get(keyed_by)
6662
alternatives = list(value.values())[0]
6763

6864
if len(alternatives) == 1 and "default" in alternatives:
69-
raise Exception(
70-
f"Keyed-by '{keyed_by}' unnecessary with only value 'default' "
71-
f"found, when determining item {item_name}"
72-
)
65+
raise Exception(f"Keyed-by '{keyed_by}' unnecessary with only value 'default' found, when determining item {item_name}")
7366

7467
if key is None:
7568
if "default" in alternatives:
7669
value = alternatives["default"]
7770
continue
7871
else:
79-
raise Exception(
80-
f"No attribute {keyed_by} and no value for 'default' found "
81-
f"while determining item {item_name}"
82-
)
72+
raise Exception(f"No attribute {keyed_by} and no value for 'default' found while determining item {item_name}")
8373

8474
matches = keymatch(alternatives, key)
8575
if len(matches) > 1:
86-
raise Exception(
87-
f"Multiple matching values for {keyed_by} {key!r} found while "
88-
f"determining item {item_name}"
89-
)
76+
raise Exception(f"Multiple matching values for {keyed_by} {key!r} found while determining item {item_name}")
9077
elif matches:
9178
value = matches[0]
9279
continue
9380

94-
raise Exception(
95-
f"No {keyed_by} matching {key!r} nor 'default' found while determining item {item_name}"
96-
)
81+
raise Exception(f"No {keyed_by} matching {key!r} nor 'default' found while determining item {item_name}")

builddecisionscript/src/builddecisionscript/util/schema.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ class Schema:
2222
_schema = attr.ib()
2323
_validator = attr.ib(
2424
init=False,
25-
default=attr.Factory(
26-
lambda self: _get_validator(self._schema), takes_self=True
27-
),
25+
default=attr.Factory(lambda self: _get_validator(self._schema), takes_self=True),
2826
)
2927

3028
@classmethod

builddecisionscript/src/builddecisionscript/util/scopes.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ def satisfies(*, have, require):
1111
assert isinstance(require, list)
1212
for req_scope in require:
1313
for have_scope in have:
14-
if have_scope == req_scope or (
15-
have_scope.endswith("*") and req_scope.startswith(have_scope[:-1])
16-
):
14+
if have_scope == req_scope or (have_scope.endswith("*") and req_scope.startswith(have_scope[:-1])):
1715
break
1816
else:
1917
return False

builddecisionscript/src/builddecisionscript/util/trigger_action.py

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import attr
1919
import jsone
2020
import jsonschema
21+
2122
import taskcluster
2223

2324
from . import scopes
@@ -35,13 +36,7 @@ def _is_task_in_context(context, task_tags):
3536
a given task, if that task's tags match one of the tag-sets given
3637
in the context property for the action.
3738
"""
38-
return any(
39-
all(
40-
tag in task_tags and task_tags[tag] == tag_set[tag]
41-
for tag in tag_set.keys()
42-
)
43-
for tag_set in context
44-
)
39+
return any(all(tag in task_tags and task_tags[tag] == tag_set[tag] for tag in tag_set.keys()) for tag_set in context)
4540

4641

4742
def _filter_relevant_actions(actions_json, original_task):
@@ -71,27 +66,22 @@ def _check_decision_task_scopes(decision_task_id, hook_group_id, hook_id):
7166
queue = taskcluster.Queue(taskcluster.optionsFromEnvironment(), session=SESSION)
7267
auth = taskcluster.Auth(taskcluster.optionsFromEnvironment(), session=SESSION)
7368
decision_task = queue.task(decision_task_id)
74-
decision_task_scopes = auth.expandScopes({"scopes": decision_task["scopes"]})[
75-
"scopes"
76-
]
69+
decision_task_scopes = auth.expandScopes({"scopes": decision_task["scopes"]})["scopes"]
7770
in_tree_scope = f"in-tree:hook-action:{hook_group_id}/{hook_id}"
7871

7972
if not scopes.satisfies(have=decision_task_scopes, require=[in_tree_scope]):
8073
raise RuntimeError(
8174
"Action is misconfigured: "
8275
f"decision task's scopes do not include {in_tree_scope}\n"
83-
"Decision Task {decision_task_id} has scopes:\n"
84-
+ "\n".join(f" - {scope}" for scope in decision_task_scopes)
76+
"Decision Task {decision_task_id} has scopes:\n" + "\n".join(f" - {scope}" for scope in decision_task_scopes)
8577
)
8678

8779

8880
def render_action(*, action_name, task_id, decision_task_id, action_input):
8981
queue = taskcluster.Queue(taskcluster.optionsFromEnvironment(), session=SESSION)
9082

9183
logger.debug("Fetching actions.json...")
92-
actions_url = queue.buildUrl(
93-
"getLatestArtifact", decision_task_id, "public/actions.json"
94-
)
84+
actions_url = queue.buildUrl("getLatestArtifact", decision_task_id, "public/actions.json")
9585
actions_response = SESSION.get(actions_url)
9686
actions_response.raise_for_status()
9787
actions_json = actions_response.json()
@@ -106,17 +96,12 @@ def render_action(*, action_name, task_id, decision_task_id, action_input):
10696
relevant_actions = _filter_relevant_actions(actions_json, task_definition)
10797

10898
if action_name not in relevant_actions:
109-
raise LookupError(
110-
f"{action_name} action is not available for this task. "
111-
f"Available: {sorted(relevant_actions.keys())}"
112-
)
99+
raise LookupError(f"{action_name} action is not available for this task. Available: {sorted(relevant_actions.keys())}")
113100

114101
action = relevant_actions[action_name]
115102

116103
if action["kind"] != "hook":
117-
raise NotImplementedError(
118-
f"Unable to submit actions with '{action['kind']}' kind."
119-
)
104+
raise NotImplementedError(f"Unable to submit actions with '{action['kind']}' kind.")
120105

121106
_check_decision_task_scopes(
122107
decision_task_id,
@@ -163,9 +148,7 @@ def submit(self):
163148
session=SESSION,
164149
)
165150
else:
166-
hooks = taskcluster.Hooks(
167-
taskcluster.optionsFromEnvironment(), session=SESSION
168-
)
151+
hooks = taskcluster.Hooks(taskcluster.optionsFromEnvironment(), session=SESSION)
169152

170153
logger.info("Triggering hook %s/%s", self.hook_group_id, self.hook_id)
171154
result = hooks.triggerHook(self.hook_group_id, self.hook_id, self.hook_payload)

0 commit comments

Comments
 (0)