Reformat Python code with ruff

This commit is contained in:
Jakub Beránek
2024-12-04 23:02:25 +01:00
parent 0b737a163e
commit 536516f949
25 changed files with 1540 additions and 943 deletions

View File

@@ -19,6 +19,7 @@ $ python3 upload-build-metrics.py <path-to-CPU-usage-CSV>
`path-to-CPU-usage-CSV` is a path to a CSV generated by the `src/ci/cpu-usage-over-time.py` script.
"""
import argparse
import csv
import os
@@ -31,7 +32,7 @@ from typing import List
def load_cpu_usage(path: Path) -> List[float]:
usage = []
with open(path) as f:
reader = csv.reader(f, delimiter=',')
reader = csv.reader(f, delimiter=",")
for row in reader:
# The log might contain incomplete rows or some Python exception
if len(row) == 2:
@@ -50,25 +51,21 @@ def upload_datadog_measure(name: str, value: float):
print(f"Metric {name}: {value:.4f}")
datadog_cmd = "datadog-ci"
if os.getenv("GITHUB_ACTIONS") is not None and sys.platform.lower().startswith("win"):
if os.getenv("GITHUB_ACTIONS") is not None and sys.platform.lower().startswith(
"win"
):
# Due to weird interaction of MSYS2 and Python, we need to use an absolute path,
# and also specify the ".cmd" at the end. See https://github.com/rust-lang/rust/pull/125771.
datadog_cmd = "C:\\npm\\prefix\\datadog-ci.cmd"
subprocess.run([
datadog_cmd,
"measure",
"--level", "job",
"--measures", f"{name}:{value}"
],
check=False
subprocess.run(
[datadog_cmd, "measure", "--level", "job", "--measures", f"{name}:{value}"],
check=False,
)
if __name__ == "__main__":
parser = argparse.ArgumentParser(
prog="DataDog metric uploader"
)
parser = argparse.ArgumentParser(prog="DataDog metric uploader")
parser.add_argument("cpu-usage-history-csv")
args = parser.parse_args()