generated from pythoninthegrasses/python_template
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathci_dir.py
More file actions
executable file
·50 lines (36 loc) · 1.05 KB
/
ci_dir.py
File metadata and controls
executable file
·50 lines (36 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python3
import subprocess
from pathlib import Path
"""
Over-engineered python solution to local directory for GitHub Actions.
cf. bash:
w=$(basename $(echo $PWD)); echo "./${w}" > ../BASE_DIR
USAGE
cd <dir>
python ../ci_dir.py
"""
# get path of working directory
cwd = Path.cwd()
# basename of working directory
cwd_bn = cwd.name
# add './' prefix to cwd_bn
rel = "./" + cwd_bn
# add 'CWD=' prefix to rel
cwd_str = "CWD=" + rel
# call git via subprocess to find name of repo
abs = subprocess.check_output(["git", "rev-parse", "--show-toplevel"]).decode("utf-8").strip()
# split at last '/' and assign last element to repo
raw = abs.split("/")
repo = raw[-1]
# path to relative directory
up = str(Path(f"{repo}/{rel}"))
# dot path to working directory
dot = f"{rel}"
# list locations right aligned up to n chars (needed for absolute path)
# print(f"abs: {abs:>30}")
# print(f"cwd: {up:>30}")
# print(f"dot: {dot:>30}")
# print(f"tld: {repo:>30}")
# write dot to "{abs}/WORKDIR"
with open(f"{abs}/BASE_DIR", "w") as f:
f.write(dot)