llvmbot monitor: Reformat code with black
make_table.py was already formatted correctly.
Change-Id: I1917983f9763394d5b370c9c76246572a24bcd3c
diff --git a/monitor/buildkite_status.py b/monitor/buildkite_status.py
index 0dbaa10..3f9924b 100755
--- a/monitor/buildkite_status.py
+++ b/monitor/buildkite_status.py
@@ -4,9 +4,11 @@
import logging
from datetime import timedelta
from functools import lru_cache
+
# Base dict order not guaranteed until 3.7+
from collections import OrderedDict
from datetime import datetime
+
# To convert time stamps
# (use datetime.datetime.fromisoformat in Python3.7+)
import dateutil.parser
@@ -37,12 +39,10 @@
# strip to remove ending newline
token = f.readline().strip()
if not token:
- logging.debug(err_msg.format(
- "Buildkite API token file was empty"))
+ logging.debug(err_msg.format("Buildkite API token file was empty"))
token = None
except FileNotFoundError:
- logging.debug(err_msg.format(
- "Couldn't read Buildkite API token file"))
+ logging.debug(err_msg.format("Couldn't read Buildkite API token file"))
return token
@@ -50,13 +50,14 @@
@lru_cache(maxsize=None)
def get_pipeline_builds(organisation, pipeline):
return buildkite.builds().list_all_for_pipeline(
- organisation, pipeline,
+ organisation,
+ pipeline,
# Finished means passed, failed, blocked or cancelled
- states=[BuildState.FINISHED])
+ states=[BuildState.FINISHED],
+ )
-def get_last_finished_build_status(organisation, job_name,
- pipeline):
+def get_last_finished_build_status(organisation, job_name, pipeline):
"""
Get information about the last finished build of a particular
job. (where a job is one of the pipeline steps)
@@ -69,55 +70,53 @@
# branches.
# For the status page we ignore pre-commit and release builds.
# ph_buildable_revision is set if Phabricator triggered this build.
- if 'ph_buildable_revision' in build['env'] or \
- build['branch'] != 'main':
+ if "ph_buildable_revision" in build["env"] or build["branch"] != "main":
continue
# Where each "job" is a config e.g. AArch64, MacOS, C++20 etc.
- for job in build['jobs']:
+ for job in build["jobs"]:
# Some jobs won't have a name. I think these are the wait steps
# between jobs or groups of jobs.
- if job.get('name') != job_name:
+ if job.get("name") != job_name:
continue
# Some jobs were never started due to failures earlier in the pipeline.
# This isn't our fault so ignore these.
- started_time = job.get('started_at')
+ started_time = job.get("started_at")
if started_time is None:
continue
# We use started because that's when it starts to
# run on the agent (don't want to include waiting time)
started = dateutil.parser.isoparse(started_time)
- finished = dateutil.parser.isoparse(job['finished_at'])
+ finished = dateutil.parser.isoparse(job["finished_at"])
# Buildkite gives us mS resoloution but we don't need that
- duration = timedelta(seconds=int(
- (finished - started).total_seconds()))
+ duration = timedelta(seconds=int((finished - started).total_seconds()))
# Time from buildkite ends up as UTC but now has no
# timezone info by default
now = datetime.now(finished.tzinfo)
- time_since = timedelta(
- seconds=int((now - finished).total_seconds()))
+ time_since = timedelta(seconds=int((now - finished).total_seconds()))
- state = job['state']
- failed = state != 'passed'
+ state = job["state"]
+ failed = state != "passed"
status = {
# 'url' is the API url, we want a clickable link
- 'builder_url': job['agent']['web_url'],
+ "builder_url": job["agent"]["web_url"],
# We use the job's url because it takes you to the
# specific agent, instead of the build's url
- 'build_url': job['web_url'],
- 'number': build['number'],
- 'state': state,
- 'duration': duration,
- 'time_since': time_since,
- 'fail': failed,
+ "build_url": job["web_url"],
+ "number": build["number"],
+ "state": state,
+ "duration": duration,
+ "time_since": time_since,
+ "fail": failed,
}
return status
logging.debug(
- "Found no finished builds for job \"{}\" "
- "on pipeline \"{}\"".format(job_name, pipeline))
+ 'Found no finished builds for job "{}" '
+ 'on pipeline "{}"'.format(job_name, pipeline)
+ )
return dict(valid=False)
@@ -134,31 +133,29 @@
buildkite.set_access_token(token)
for server in config:
- if server['name'] != "Buildkite":
+ if server["name"] != "Buildkite":
continue
if token is None:
# We cannot query buildkite but we don't want to mark these
# bots as offline because we don't know that.
- for builder in server['builders']:
- for job in builder['bots']:
- status[bot_key(job['name'])] = {'valid': False}
+ for builder in server["builders"]:
+ for job in builder["bots"]:
+ status[bot_key(job["name"])] = {"valid": False}
continue
# If we have a valid token then we can get the real status
- organisation = server.get('buildkite_org')
+ organisation = server.get("buildkite_org")
if organisation is None:
- raise RuntimeError(
- "Buildkite servers must also have a 'buildkite_org'")
+ raise RuntimeError("Buildkite servers must also have a 'buildkite_org'")
- for builder in server['builders']:
- for job in builder['bots']:
- job_name = job['name']
- logging.debug("Getting status for buildkite job \"{}\"".format(
- job_name))
+ for builder in server["builders"]:
+ for job in builder["bots"]:
+ job_name = job["name"]
+ logging.debug('Getting status for buildkite job "{}"'.format(job_name))
status[bot_key(job_name)] = get_last_finished_build_status(
- organisation, job_name,
- job['buildkite_pipeline'])
+ organisation, job_name, job["buildkite_pipeline"]
+ )
return status