Skip to content

Commit 6ede6f7

Browse files
committed
chore(lint): run formatter on python files
1 parent f13a494 commit 6ede6f7

25 files changed

Lines changed: 422 additions & 503 deletions

.github/workflows/scripts/components/compute_render_set.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,12 @@ def main() -> None:
7474
# changed list AND with hand-edited specs would otherwise print twice,
7575
# and a component with N modified spec files would print N times.
7676
# dict.fromkeys preserves first-seen order.
77-
names = dict.fromkeys([
78-
*from_changed(entries),
79-
*from_specs_diff(args.specs_diff_file, args.specs_dir, renderable),
80-
])
77+
names = dict.fromkeys(
78+
[
79+
*from_changed(entries),
80+
*from_specs_diff(args.specs_diff_file, args.specs_dir, renderable),
81+
]
82+
)
8183
for name in names:
8284
print(name)
8385

.github/workflows/scripts/control-tower/client.py

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@
2828
# (azl-ControlTower/ControlTower/Shared/Models/Jobs/JobStatus.cs).
2929
NON_TERMINAL_STATUSES = frozenset({"Queued", "Pending", "Running"})
3030
SUCCESS_STATUS = "Completed"
31-
TERMINAL_FAILURE_STATUSES = frozenset(
32-
{"Failed", "Cancelled", "CancelledByAdmin", "Unknown", "TimedOut"}
33-
)
31+
TERMINAL_FAILURE_STATUSES = frozenset({"Failed", "Cancelled", "CancelledByAdmin", "Unknown", "TimedOut"})
3432

3533

3634
@dataclass
@@ -86,9 +84,7 @@ def format_error(response: requests.Response) -> str:
8684
* ASP.NET validation: ``{"title", "errors": {field: [msg, ...]}}``
8785
"""
8886
method = response.request.method if response.request is not None else "?"
89-
lines: list[str] = [
90-
f"HTTP {response.status_code} {response.reason} from {method} {response.url}"
91-
]
87+
lines: list[str] = [f"HTTP {response.status_code} {response.reason} from {method} {response.url}"]
9288

9389
body: Any
9490
try:
@@ -178,8 +174,7 @@ def _parse_json_object(response: requests.Response, context: str) -> dict:
178174
body = response.json()
179175
except ValueError as exc:
180176
raise RuntimeError(
181-
f"{context} returned HTTP {response.status_code} "
182-
f"but the body was not valid JSON:\n{response.text}"
177+
f"{context} returned HTTP {response.status_code} but the body was not valid JSON:\n{response.text}"
183178
) from exc
184179
if not isinstance(body, dict):
185180
raise RuntimeError(
@@ -219,9 +214,7 @@ def post_scenario(
219214
json_payload=payload,
220215
)
221216
if not response.ok:
222-
raise RuntimeError(
223-
f"Control Tower '{context}' request failed.\n" + format_error(response)
224-
)
217+
raise RuntimeError(f"Control Tower '{context}' request failed.\n" + format_error(response))
225218
return _parse_json_object(response, f"Control Tower '{context}'")
226219

227220

@@ -235,13 +228,9 @@ def get_job_status(
235228
) -> dict:
236229
"""GET the job status. Refreshes the bearer token on 401 and retries once."""
237230
url = f"{base_url}/api/Workflow/jobs/status/{job_id}"
238-
response = _request_with_refresh(
239-
session, "GET", url, credential, audience, token_holder
240-
)
231+
response = _request_with_refresh(session, "GET", url, credential, audience, token_holder)
241232
if not response.ok:
242-
raise RuntimeError(
243-
"Control Tower job status request failed.\n" + format_error(response)
244-
)
233+
raise RuntimeError("Control Tower job status request failed.\n" + format_error(response))
245234
return _parse_json_object(response, "Control Tower job status")
246235

247236

@@ -284,19 +273,13 @@ def poll_until_terminal(
284273
job_status_object: dict = {}
285274

286275
while True:
287-
job_status_object = get_job_status(
288-
session, base_url, credential, audience, token_holder, job_id
289-
)
276+
job_status_object = get_job_status(session, base_url, credential, audience, token_holder, job_id)
290277
current_status = job_status_object.get("status", "Unknown")
291278
elapsed = int(time.monotonic() - start)
292279

293280
if current_status != previous_status:
294281
task_summary = _summarize_tasks(job_status_object.get("tasks"))
295-
transition = (
296-
f"{previous_status} -> {current_status}"
297-
if previous_status is not None
298-
else current_status
299-
)
282+
transition = f"{previous_status} -> {current_status}" if previous_status is not None else current_status
300283
suffix = f" | {task_summary}" if task_summary else ""
301284
print(
302285
f"Job {job_id} status: {transition} (elapsed {elapsed}s){suffix}",
@@ -342,14 +325,7 @@ def report_failure(final: dict) -> None:
342325

343326
tasks = final.get("tasks")
344327
if isinstance(tasks, list):
345-
failed = [
346-
t
347-
for t in tasks
348-
if isinstance(t, dict) and t.get("status") in TERMINAL_FAILURE_STATUSES
349-
]
328+
failed = [t for t in tasks if isinstance(t, dict) and t.get("status") in TERMINAL_FAILURE_STATUSES]
350329
for task in failed:
351330
name = task.get("taskName") or task.get("taskId")
352-
print(
353-
f"##[error]task '{name}' status={task.get('status')} "
354-
f"attempt={task.get('attemptNumber')}"
355-
)
331+
print(f"##[error]task '{name}' status={task.get('status')} attempt={task.get('attemptNumber')}")

.github/workflows/scripts/control-tower/run_package_build.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,12 @@ def _load_build_components(path: Path) -> list[str]:
3939
try:
4040
raw = path.read_text(encoding="utf-8")
4141
except OSError as exc:
42-
raise SystemExit(
43-
f"##[error]Failed to read --changed-components-file {path!s}: {exc}"
44-
) from exc
42+
raise SystemExit(f"##[error]Failed to read --changed-components-file {path!s}: {exc}") from exc
4543

4644
try:
4745
entries = json.loads(raw)
4846
except json.JSONDecodeError as exc:
49-
raise SystemExit(
50-
f"##[error]--changed-components-file {path!s} is not valid JSON: {exc}"
51-
) from exc
47+
raise SystemExit(f"##[error]--changed-components-file {path!s} is not valid JSON: {exc}") from exc
5248

5349
if not isinstance(entries, list):
5450
raise SystemExit(
@@ -212,10 +208,7 @@ def main() -> None:
212208

213209
job_id = build_response.get("jobId")
214210
if not job_id:
215-
print(
216-
"##[error]Control Tower 'package' response did not include a 'jobId'. "
217-
"Cannot confirm job acceptance."
218-
)
211+
print("##[error]Control Tower 'package' response did not include a 'jobId'. Cannot confirm job acceptance.")
219212
sys.exit(1)
220213

221214
# ── Brief poll — just confirm the job was accepted ───────────────

.github/workflows/scripts/control-tower/run_prcheck.py

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,12 @@ def _load_components_from_file(path: Path) -> list[str]:
4949
try:
5050
raw = path.read_text(encoding="utf-8")
5151
except OSError as exc:
52-
raise SystemExit(
53-
f"##[error]Failed to read --changed-components-file {path!s}: {exc}"
54-
) from exc
52+
raise SystemExit(f"##[error]Failed to read --changed-components-file {path!s}: {exc}") from exc
5553

5654
try:
5755
entries = json.loads(raw)
5856
except json.JSONDecodeError as exc:
59-
raise SystemExit(
60-
f"##[error]--changed-components-file {path!s} is not valid JSON: {exc}"
61-
) from exc
57+
raise SystemExit(f"##[error]--changed-components-file {path!s} is not valid JSON: {exc}") from exc
6258

6359
if not isinstance(entries, list):
6460
raise SystemExit(
@@ -89,9 +85,7 @@ def _parse_args() -> argparse.Namespace:
8985
required=True,
9086
help="Entra ID audience URI (e.g. api://<client-id>)",
9187
)
92-
parser.add_argument(
93-
"--api-base-url", required=True, help="Base URL of the Control Tower service"
94-
)
88+
parser.add_argument("--api-base-url", required=True, help="Base URL of the Control Tower service")
9589
parser.add_argument(
9690
"--build-reason",
9791
required=True,
@@ -182,16 +176,11 @@ def main() -> None:
182176
print(json.dumps(payload, indent=2))
183177

184178
if args.build_reason == "PullRequest":
185-
print(
186-
"Skipping Control Tower call - pull request triggers are not supported, yet."
187-
)
179+
print("Skipping Control Tower call - pull request triggers are not supported, yet.")
188180
return
189181

190182
if not components:
191-
print(
192-
"No affected components detected between source and target commits; "
193-
"skipping Control Tower call."
194-
)
183+
print("No affected components detected between source and target commits; skipping Control Tower call.")
195184
return
196185

197186
# ── Acquire bearer token ─────────────────────────────────────────
@@ -221,17 +210,11 @@ def main() -> None:
221210

222211
job_id = prcheck_response.get("jobId")
223212
if not job_id:
224-
print(
225-
"##[error]Control Tower 'prcheck' response did not include a 'jobId'. "
226-
"Cannot poll for job status."
227-
)
213+
print("##[error]Control Tower 'prcheck' response did not include a 'jobId'. Cannot poll for job status.")
228214
sys.exit(1)
229215

230216
# ── Poll for job completion ──────────────────────────────────────
231-
print(
232-
f"Polling job {job_id} every {args.poll_interval_seconds}s "
233-
f"(timeout {args.poll_timeout_seconds}s)..."
234-
)
217+
print(f"Polling job {job_id} every {args.poll_interval_seconds}s (timeout {args.poll_timeout_seconds}s)...")
235218
try:
236219
final, timed_out = ct.poll_until_terminal(
237220
session,

.github/workflows/scripts/locks-check/post_locks_comment.py

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -117,19 +117,12 @@ def parse_update_output(path: Path) -> list[dict]:
117117

118118
if not isinstance(data, list):
119119
raise SystemExit(
120-
f"Error: update output has unexpected shape (expected null or list, "
121-
f"got {type(data).__name__})"
120+
f"Error: update output has unexpected shape (expected null or list, got {type(data).__name__})"
122121
)
123122

124123
for entry in data:
125-
if (
126-
not isinstance(entry, dict)
127-
or "component" not in entry
128-
or "changed" not in entry
129-
):
130-
raise SystemExit(
131-
f"Error: update output entry has unexpected shape: {entry!r}"
132-
)
124+
if not isinstance(entry, dict) or "component" not in entry or "changed" not in entry:
125+
raise SystemExit(f"Error: update output entry has unexpected shape: {entry!r}")
133126

134127
return [entry for entry in data if entry["changed"] is True]
135128

@@ -160,9 +153,7 @@ def format_comment(
160153
# inject arbitrary commands into a maintainer's terminal. Fall back to
161154
# `-a` if any name fails the same regex used for display so the
162155
# printed command is always safe to run as-is.
163-
use_all = n_changed > 30 or any(
164-
not _SAFE_NAME_RE.match(name) for name in comp_names
165-
)
156+
use_all = n_changed > 30 or any(not _SAFE_NAME_RE.match(name) for name in comp_names)
166157
remediation_cmd = _update_command([] if use_all else comp_names, use_all=use_all)
167158

168159
lines: list[str] = [
@@ -248,9 +239,7 @@ def format_comment(
248239

249240

250241
def _gh(*args: str) -> str:
251-
return subprocess.run(
252-
["gh", *args], capture_output=True, text=True, check=True
253-
).stdout.strip()
242+
return subprocess.run(["gh", *args], capture_output=True, text=True, check=True).stdout.strip()
254243

255244

256245
def find_existing_comments(repo: str, pr: str) -> list[str]:
@@ -267,11 +256,7 @@ def find_existing_comments(repo: str, pr: str) -> list[str]:
267256
"--paginate",
268257
f"/repos/{repo}/issues/{pr}/comments",
269258
"--jq",
270-
(
271-
f'.[] | select(.user.login == "{BOT_AUTHOR}") '
272-
f'| select(.body | contains("{COMMENT_MARKER}")) '
273-
"| .id"
274-
),
259+
(f'.[] | select(.user.login == "{BOT_AUTHOR}") | select(.body | contains("{COMMENT_MARKER}")) | .id'),
275260
)
276261
except subprocess.CalledProcessError:
277262
return []
@@ -342,9 +327,7 @@ def delete_comment_if_exists(repo: str, pr: str) -> None:
342327

343328

344329
def main() -> int:
345-
parser = argparse.ArgumentParser(
346-
description="Post `azldev component update` drift as a PR comment."
347-
)
330+
parser = argparse.ArgumentParser(description="Post `azldev component update` drift as a PR comment.")
348331
parser.add_argument(
349332
"--update-output",
350333
type=Path,
@@ -353,9 +336,7 @@ def main() -> int:
353336
)
354337
parser.add_argument("--repo", required=True, help="GitHub repo (owner/repo)")
355338
parser.add_argument("--pr", required=True, help="PR number")
356-
parser.add_argument(
357-
"--artifacts-url", default=None, help="Direct URL to patch artifact"
358-
)
339+
parser.add_argument("--artifacts-url", default=None, help="Direct URL to patch artifact")
359340
parser.add_argument("--run-id", default=None, help="GitHub Actions run ID")
360341
args = parser.parse_args()
361342

0 commit comments

Comments
 (0)