Skip to content

Commit 780ef7b

Browse files
author
Bastien Orivel
committed
Run black, it's been a while
1 parent dd41e0c commit 780ef7b

14 files changed

+254
-120
lines changed

decision_task.py

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from decisionlib import CONFIG
1111
from tasks import *
1212

13+
1314
def tasks(task_for: str):
1415
repo_name = os.environ["REPO_NAME"]
1516
if "[ci skip]" in CONFIG.commit_message:

decisionlib.py

+55-32
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444

4545
DEPLOY_BRANCHES = ["main", "master"]
4646

47+
4748
class Config:
4849
"""
4950
Global configuration, for users of the library to modify.
@@ -102,8 +103,12 @@ def index_path(self):
102103
def commit_message(self):
103104
if self._commit_message is None:
104105
print("Getting commit message")
105-
print(f"https://github.com/{os.environ['REPO_FULL_NAME']}/commit/{self.git_sha}.patch")
106-
commit = requests.get(f"https://github.com/{os.environ['REPO_FULL_NAME']}/commit/{self.git_sha}.patch").text
106+
print(
107+
f"https://github.com/{os.environ['REPO_FULL_NAME']}/commit/{self.git_sha}.patch"
108+
)
109+
commit = requests.get(
110+
f"https://github.com/{os.environ['REPO_FULL_NAME']}/commit/{self.git_sha}.patch"
111+
).text
107112
print(commit)
108113
self._commit_message = commit.split("diff --git a/")[0]
109114
print(self._commit_message)
@@ -140,7 +145,6 @@ def task_root_for(self, platform):
140145
raise NotImplementedError
141146

142147

143-
144148
CONFIG = Config()
145149
SHARED = Shared()
146150

@@ -234,9 +238,10 @@ def get_proxy_url(self) -> str:
234238

235239
def with_script(self, *script: str, as_gha=False):
236240
if as_gha:
237-
self.with_gha("script_%s" % len(self.gh_actions), gha.GithubActionScript(
238-
"\n".join(script)
239-
))
241+
self.with_gha(
242+
"script_%s" % len(self.gh_actions),
243+
gha.GithubActionScript("\n".join(script)),
244+
)
240245
else:
241246
self.scripts.extend(script)
242247
return self
@@ -345,7 +350,15 @@ def find(index_path: str) -> str:
345350

346351
def create_index_at(self, index_path: str, task_id: str):
347352
full_index_path = "%s.%s" % (CONFIG.index_prefix, index_path)
348-
SHARED.index_service.insertTask(full_index_path, { "taskId": task_id, "data": {}, "expires": SHARED.from_now_json(self.index_and_artifacts_expire_in), "rank": 0})
353+
SHARED.index_service.insertTask(
354+
full_index_path,
355+
{
356+
"taskId": task_id,
357+
"data": {},
358+
"expires": SHARED.from_now_json(self.index_and_artifacts_expire_in),
359+
"rank": 0,
360+
},
361+
)
349362

350363
def find_or_create(self, index_path: str) -> str:
351364
"""
@@ -381,7 +394,9 @@ def find_or_create(self, index_path: str) -> str:
381394
SHARED.found_or_created_indexed_tasks[index_path] = task_id
382395
return task_id
383396

384-
def with_additional_repo(self, repo_url: str, target: str, enabled=True, branch=None):
397+
def with_additional_repo(
398+
self, repo_url: str, target: str, enabled=True, branch=None
399+
):
385400
if not enabled:
386401
return self
387402

@@ -402,7 +417,7 @@ def with_curl_script(self, url: str, file_path: str, as_gha=False):
402417
curl --compressed --ssl-no-revoke --retry 5 --connect-timeout 10 -Lf "%s" -o "%s"
403418
"""
404419
% (url, file_path),
405-
as_gha=as_gha
420+
as_gha=as_gha,
406421
)
407422

408423
def with_curl_artifact_script(
@@ -413,27 +428,30 @@ def with_curl_artifact_script(
413428
directory="public",
414429
rename=None,
415430
extract=False,
416-
as_gha=False
431+
as_gha=False,
417432
):
418433
queue_service = self.get_proxy_url() + "/api/queue"
419434
ret = self.with_dependencies(task_id).with_curl_script(
420435
queue_service
421436
+ "/v1/task/%s/artifacts/%s/%s" % (task_id, directory, artifact_name),
422437
os.path.join(out_directory, rename or url_basename(artifact_name)),
423-
as_gha=as_gha
438+
as_gha=as_gha,
424439
)
425440
if extract:
426441
ret = self.with_script(
427442
"tar xvf %s"
428443
% os.path.join(out_directory, rename or url_basename(artifact_name)),
429-
as_gha=as_gha
444+
as_gha=as_gha,
430445
)
431446

432447
return ret
433448

434449
def with_repo_bundle(self, name, dest, **kwargs):
435450
return self.with_curl_artifact_script(
436-
CONFIG.decision_task_id, f"{name}.bundle", "$HOME/tasks/$TASK_ID", directory="private"
451+
CONFIG.decision_task_id,
452+
f"{name}.bundle",
453+
"$HOME/tasks/$TASK_ID",
454+
directory="private",
437455
).with_repo(
438456
"$HOME/tasks/$TASK_ID/" + dest,
439457
f"$HOME/tasks/$TASK_ID/{name}.bundle",
@@ -452,10 +470,15 @@ def with_gha(self, name: str, gha: gha.GithubAction, enabled=True):
452470
return self
453471

454472
if gha.git_fetch_url and gha.git_fetch_url not in self.action_paths:
455-
self.with_additional_repo(gha.git_fetch_url, os.path.join(SHARED.task_root_for(self.platform()), gha.repo_name))
473+
self.with_additional_repo(
474+
gha.git_fetch_url,
475+
os.path.join(SHARED.task_root_for(self.platform()), gha.repo_name),
476+
)
456477
self.action_paths.add(gha.git_fetch_url)
457478

458-
if not any(CONFIG.git_ref == "refs/heads/%s" % branch for branch in DEPLOY_BRANCHES) and not CONFIG.git_ref.startswith("refs/tags/"):
479+
if not any(
480+
CONFIG.git_ref == "refs/heads/%s" % branch for branch in DEPLOY_BRANCHES
481+
) and not CONFIG.git_ref.startswith("refs/tags/"):
459482
gha = gha.with_env("PAHKAT_NO_DEPLOY", "true")
460483

461484
if "[no deploy]" in CONFIG.commit_message:
@@ -641,6 +664,7 @@ class WindowsGenericWorkerTask(GenericWorkerTask):
641664
642665
Scripts are written as `.bat` files executed with `cmd.exe`.
643666
"""
667+
644668
def platform(self):
645669
return "win"
646670

@@ -673,7 +697,11 @@ def build_worker_payload(self):
673697
)
674698

675699
def build_command(self):
676-
return ['cmd.exe /C "{}"'.format(deindent("\n".join(self.scripts + self.late_scripts)))]
700+
return [
701+
'cmd.exe /C "{}"'.format(
702+
deindent("\n".join(self.scripts + self.late_scripts))
703+
)
704+
]
677705

678706
def with_path_from_homedir(self, *paths: str):
679707
"""
@@ -760,10 +788,11 @@ def with_git(self):
760788
)
761789

762790
def with_cmake(self):
763-
return (
764-
self
765-
.with_path_from_homedir("cmake\\cmake-3.23.1-windows-x86_64\\bin")
766-
.with_directory_mount("https://github.com/Kitware/CMake/releases/download/v3.23.1/cmake-3.23.1-windows-x86_64.zip", path="cmake")
791+
return self.with_path_from_homedir(
792+
"cmake\\cmake-3.23.1-windows-x86_64\\bin"
793+
).with_directory_mount(
794+
"https://github.com/Kitware/CMake/releases/download/v3.23.1/cmake-3.23.1-windows-x86_64.zip",
795+
path="cmake",
767796
)
768797

769798
def with_curl_script(self, url, file_path, as_gha=False):
@@ -1078,7 +1107,9 @@ def make_repo_bundle(path: str, bundle_name: str, sha: str, *, shallow=True):
10781107
if shallow:
10791108
subprocess.check_call(["git", "config", "user.name", "Decision task"])
10801109
subprocess.check_call(["git", "config", "user.email", "[email protected]"])
1081-
tree = subprocess.check_output(["git", "show", sha, "--pretty=%T", "--no-patch"])
1110+
tree = subprocess.check_output(
1111+
["git", "show", sha, "--pretty=%T", "--no-patch"]
1112+
)
10821113
message = "Shallow version of commit " + sha
10831114
commit = subprocess.check_output(
10841115
["git", "commit-tree", tree.strip(), "-m", message]
@@ -1094,19 +1125,11 @@ def make_repo_bundle(path: str, bundle_name: str, sha: str, *, shallow=True):
10941125
"create",
10951126
f"../{bundle_name}",
10961127
CONFIG.git_bundle_shallow_ref,
1097-
]
1128+
]
10981129
else:
10991130
subprocess.check_call(["git", "fetch", "--unshallow", CONFIG.git_url])
1100-
subprocess.check_call(
1101-
["git", "update-ref", CONFIG.git_bundle_shallow_ref, sha]
1102-
)
1103-
create = [
1104-
"git",
1105-
"bundle",
1106-
"create",
1107-
f"../{bundle_name}",
1108-
"--all"
1109-
]
1131+
subprocess.check_call(["git", "update-ref", CONFIG.git_bundle_shallow_ref, sha])
1132+
create = ["git", "bundle", "create", f"../{bundle_name}", "--all"]
11101133

11111134
with subprocess.Popen(create) as p:
11121135
os.chdir(cwd)

gha.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ def __init__(self, path, args, *, run_if=None, npm_install=False, enable_post=Tr
1212
Args will all be put in the env as INPUT_{key} = {value}
1313
"""
1414
# Path can be None from GithubActionScript
15-
if path and '@' in path:
16-
self.path, self.version = path.split('@', 1)
15+
if path and "@" in path:
16+
self.path, self.version = path.split("@", 1)
1717
else:
1818
self.path = path
19-
self.version = 'master'
19+
self.version = "master"
2020
self.args = {}
2121
self.post_path = None
2222
self.run_path = "index.js"

runner.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,6 @@ def to_string(value):
273273
# Take milliseconds so we can start hight than the current github run id at the time of writing
274274
env["GITHUB_RUN_NUMBER"] = str(int(time.time() * 1000))
275275

276-
277276
if EXTRA_PATH:
278277
if platform.system() == "Windows":
279278
env["PATH"] = env["PATH"] + ";" + ";".join(EXTRA_PATH)
@@ -302,11 +301,11 @@ async def run_action(action_name: str, action: Dict[str, Any], post=False):
302301

303302
extra_args = {}
304303

305-
cwd = action.get('cwd')
304+
cwd = action.get("cwd")
306305
if platform.system() == "Windows":
307306
shell = action.get("shell", "pwsh")
308307
if shell == "cmd":
309-
tmp = tempfile.NamedTemporaryFile("w", suffix=".bat", delete=False);
308+
tmp = tempfile.NamedTemporaryFile("w", suffix=".bat", delete=False)
310309
tmp.write(action[script_index])
311310
cmdargs = ["cmd", "/C", "call " + tmp.name]
312311
print("Writing", action[script_index], " to", tmp.name)
@@ -323,7 +322,7 @@ async def run_action(action_name: str, action: Dict[str, Any], post=False):
323322
cwd=cwd,
324323
stdout=subprocess.PIPE,
325324
stderr=subprocess.STDOUT,
326-
limit=1024*256,
325+
limit=1024 * 256,
327326
**extra_args,
328327
)
329328
else:
@@ -335,7 +334,7 @@ async def run_action(action_name: str, action: Dict[str, Any], post=False):
335334
action[script_index],
336335
env=env,
337336
cwd=cwd,
338-
limit=1024*256,
337+
limit=1024 * 256,
339338
stdout=subprocess.PIPE,
340339
stderr=subprocess.STDOUT,
341340
**extra_args,
@@ -566,7 +565,6 @@ async def main():
566565
await run_action(name, action, post=True)
567566

568567

569-
570568
if __name__ == "__main__":
571569
try:
572570
asyncio.run(main())

0 commit comments

Comments
 (0)