-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmono.py
141 lines (118 loc) · 4.07 KB
/
mono.py
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
51
52
53
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/env python
"""
For now we'll run most with shell=True so that we can move away from this quickly if necessary
"""
import argparse
import os
import platform
from typing import List
import sys
import logging
import subprocess
LOGLEVEL = os.environ.get("LOGLEVEL", "INFO").upper()
logging.basicConfig(level=LOGLEVEL)
log = logging.getLogger(__name__)
CIBUILDWHEEL_VERSION = "2.16.2"
CIBUILDWHEEL_PLATFORM = "auto"
def parseargs(args: list[str]) -> argparse.Namespace:
parser = argparse.ArgumentParser()
parser.add_argument(
"--mode",
choices=["install_ci_deps", "cicd_dpf_ssw_aligner_rs", "cicd_dpf_mrcfile"],
help="mode to run",
required=True,
)
parser.add_argument(
"--cibw_platform",
choices=["auto", "linux", "macos", "windows"],
help="cibuildwheel platform to build",
default=CIBUILDWHEEL_PLATFORM,
)
return parser.parse_args(args)
def run_l(cmd: list[str]) -> None:
str_cmd = " ".join(cmd)
log.debug(f"Running: {str_cmd}")
ret = subprocess.run(cmd)
if ret.returncode:
raise RuntimeError(f"Failure with command: {str_cmd}")
def run_s(cmd: str, env_add: dict[str, str]) -> None:
log.debug(f"Running: {cmd}")
env = dict(os.environ)
env.update(env_add)
ret = subprocess.run(cmd, env=env, shell=True)
if ret.returncode:
raise RuntimeError(f"Failure with command: {cmd}")
def install_rust_cibw_command():
return (
"curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs"
" | sh -s -- --default-toolchain none -y"
" && rustup toolchain install nightly --allow-downgrade --profile minimal --component clippy"
" && rustup show"
)
def install_ci_deps():
cmds = f"""
python -m pip install cibuildwheel=={CIBUILDWHEEL_VERSION}
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --default-toolchain none -y
rustup toolchain install nightly --allow-downgrade --profile minimal --component clippy
rustup show
pip install pipx
"""
match platform.system():
case "Darwin":
cmds += "rustup target add aarch64-apple-darwin x86_64-apple-darwin"
case "Windows":
cmds += "rustup target add x86_64-pc-windows-msvc i686-pc-windows-msvc"
for cmd in cmds.split("\n"):
if cmd:
run_s(cmd, {})
def cicd_dpf_ssw_aligner_rs():
env = {
"CIBW_PLATFORM": CIBUILDWHEEL_PLATFORM,
"CIBW_ARCHS": "auto",
"CIBW_ENVIRONMENT": 'PATH="$HOME/.cargo/bin:$PATH" CARGO_TERM_COLOR="always"',
"CIBW_ENVIRONMENT_WINDOWS": 'PATH="$UserProfile\\.cargo\\bin;$PATH"',
"CIBW_BEFORE_BUILD": install_rust_cibw_command(),
"CIBW_BUILD_VERBOSITY": "1",
}
cmds = """
python -m cibuildwheel ./src/python/dpf-ssw-aligner-rs --output-dir wheelhouse
ls wheelhouse
pipx run build --sdist --outdir wheelhouse ./src/python/dpf-ssw-aligner-rs
ls wheelhouse
"""
for cmd in cmds.split("\n"):
if cmd:
run_s(cmd, env)
def cicd_dpf_mrcfile():
env = {
"CIBW_PLATFORM": CIBUILDWHEEL_PLATFORM,
"CIBW_ARCHS": "auto",
"CIBW_ENVIRONMENT": 'PATH="$HOME/.cargo/bin:$PATH" CARGO_TERM_COLOR="always"',
"CIBW_ENVIRONMENT_WINDOWS": 'PATH="$UserProfile\\.cargo\\bin;$PATH"',
"CIBW_BEFORE_BUILD": install_rust_cibw_command(),
"CIBW_BUILD_VERBOSITY": "1",
}
cmds = """
python -m cibuildwheel ./src/python/dpf-mrcfile --output-dir wheelhouse
ls wheelhouse
pipx run build --sdist --outdir wheelhouse ./src/python/dpf-mrcfile
ls wheelhouse
"""
for cmd in cmds.split("\n"):
if cmd:
run_s(cmd, env)
def main(_args: List[str]) -> None:
args = parseargs(_args)
global CIBUILDWHEEL_PLATFORM
CIBUILDWHEEL_PLATFORM = args.cibw_platform
match args.mode:
case "install_ci_deps":
install_ci_deps()
case "cicd_dpf_ssw_aligner_rs":
install_ci_deps()
cicd_dpf_ssw_aligner_rs()
case "cicd_dpf_mrcfile":
install_ci_deps()
cicd_dpf_mrcfile()
if __name__ == "__main__":
main(sys.argv[1:])