Newer
Older
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
#!/usr/bin/env python3
import os
import stat
import sys
import subprocess
from pathlib import Path
USAGE = "USAGE: %s ROOTPATH" % os.path.basename(sys.argv[0])
POULPE_DIR = Path(__file__).absolute().parent.parent
RESULT_DIR = "results"
BIN_ENV_DIR = "bin-envs"
DATA_ENV_DIR = "data-envs"
BENCHMARK_DIR = "benchmarks"
SUITE_DIR = "suites"
def install_poulpe():
"""setup a venv and install poulpe in it"""
print("Installing poulpe (editable) into a new venv")
install_venv = [sys.executable, "-m", "venv", ".venv"]
update_pip = [
str(Path(".venv") / "bin" / "pip"),
"install",
"--quiet",
"--upgrade",
"pip",
]
install_poulpe = [
str(Path(".venv") / "bin" / "pip"),
"install",
"--quiet",
"--editable",
str(POULPE_DIR),
]
commands = [install_venv, update_pip, install_poulpe]
for command in commands:
subprocess.run(command, check=True)
POULPE_PROXY = """#!/usr/bin/bash
base="`dirname $0`"
"$base"/../.venv/bin/poulpe "$@"
BASH_PROXY = """#!/usr/bin/bash
base="`dirname $0`"
. "$base"/../.venv/bin/activate
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
"$@"
"""
def setup_quick_access():
print('Creating a "bin/" directory with some utility')
Path("bin").mkdir(parents=True)
env_bin = Path("..") / ".venv" / "bin"
dir_bin = Path("bin")
poulpe_proxy = dir_bin / "poulpe"
poulpe_proxy.write_text(POULPE_PROXY)
poulpe_proxy.chmod(poulpe_proxy.stat().st_mode | stat.S_IEXEC)
os.symlink(env_bin / "activate", dir_bin / "activate")
bash_proxy = dir_bin / "shell"
bash_proxy.write_text(BASH_PROXY)
bash_proxy.chmod(bash_proxy.stat().st_mode | stat.S_IEXEC)
def setup_base_dir(path):
base_path = Path(path).absolute()
print("Creating folders")
base_path.mkdir(parents=True)
base_path.joinpath(RESULT_DIR).mkdir()
base_path.joinpath(BIN_ENV_DIR).mkdir()
base_path.joinpath(DATA_ENV_DIR).mkdir()
old_dir = os.curdir
os.chdir(base_path)
try:
install_poulpe()
setup_quick_access()
print("Create symlinks to development Poulpe for suites")
source = (POULPE_DIR / SUITE_DIR).resolve()
os.symlink(source, SUITE_DIR)
finally:
os.chdir(old_dir)
# TODO HGPERFPATH
if __name__ == "__main__":
if len(sys.argv) != 2:
print(USAGE, file=sys.stderr)
sys.exit(128)
else:
ret = setup_base_dir(sys.argv[1])
sys.exit(ret)