-
Notifications
You must be signed in to change notification settings - Fork 2
/
print_deps.py
executable file
·64 lines (50 loc) · 1.84 KB
/
print_deps.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
#!/usr/bin/env python3
""" Echo dependencies for given environment
"""
import os
from pathlib import Path
from argparse import ArgumentParser, RawDescriptionHelpFormatter
try:
import tomllib as tlib
except ImportError:
import tomli as tlib
IS_MUSL = os.environ.get('MB_ML_LIBC') == 'musllinux'
def get_phase_requirements(repo_path, phase='build'):
toml = (Path(repo_path) / 'pyproject.toml').read_text()
config = tlib.loads(toml)
if phase == 'build':
requires = config.get('build-system', {}).get('requires', [])
else:
deps = config.get('project', {}).get('dependencies', [])
opt_dict = config.get('project', {}).get('optional-dependencies', {})
requires = deps + opt_dict.get(phase, [])
base_req = [R for R in requires if not 'numpy' in R]
return ' '.join(base_req)
def get_numpy_requirement(py_ver):
major, minor, *_ = py_ver.split('.')
assert major == "3"
minor = int(minor)
if minor <= 8:
if IS_MUSL:
raise RuntimeError("MUSL doesn't have 3.8 wheels")
# SPEC0-minimum as of Dec 23, 2023
return "1.22.0"
if minor == 9:
return "2.0.2"
return "2.1.2"
def get_parser():
parser = ArgumentParser(description=__doc__, # Usage from docstring
formatter_class=RawDescriptionHelpFormatter)
parser.add_argument("py_ver", help='Python version e.g. 3.11')
parser.add_argument("repo_dir", help='Path to source repo')
parser.add_argument('-p', '--phase', default='build',
help='Phase ("build" or "test")')
return parser
def main():
parser = get_parser()
args = parser.parse_args()
base = get_phase_requirements(args.repo_dir, args.phase)
np_req = get_numpy_requirement(args.py_ver)
print(f'numpy=={np_req} {base}')
if __name__ == '__main__':
main()