-
Notifications
You must be signed in to change notification settings - Fork 23
/
compile.py
executable file
·105 lines (93 loc) · 2.72 KB
/
compile.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
#!/usr/bin/env python
from __future__ import annotations
import os
import subprocess
import sys
from pathlib import Path
COMPILE_SETTINGS = {
"py39-dj32-cms41": [],
"py310-dj32-cms41": [],
"py39-dj40-cms41": [],
"py310-dj40-cms41": [],
"py311-dj40-cms41": [],
"py39-dj41-cms41": [],
"py310-dj41-cms41": [],
"py311-dj41-cms41": [],
"py39-dj42-cms41": [],
"py310-dj42-cms41": [],
"py311-dj42-cms41": [],
"py312-dj42-cms41": [],
"py310-dj50-cms41": [],
"py311-dj50-cms41": [],
"py312-dj50-cms41": [],
"py311-djmain-cms4dev": [],
"py311-djmain-cms41": [],
}
django_dict = {
"djmain": "https://github.com/django/django/tarball/main#egg=Django",
"dj32": "Django>=3.2,<4",
"dj40": "Django>=4.0,<4.1",
"dj41": "Django>=4.1,<4.2",
"dj42": "Django>=4.2,<5",
"dj50": "Django>=5.0,<5.1",
}
cms_dict = {
"cms40": "https://github.com/django-cms/django-cms/tarball/release/4.0.1.x#egg=django-cms",
"cms41": "django-cms>=4.1,<4.2",
"cms4dev": "https://github.com/django-cms/django-cms/tarball/develop-4#egg=django-cms",
}
def get_args(key, value, common_args):
py_ver, dj_ver, cms_ver, mode = key.split("-")
assert py_ver[:2] == "py"
assert mode.endswith(".txt")
return [
f"python{py_ver[2]}.{py_ver[3:]}",
*common_args,
"-P",
django_dict[dj_ver],
"-P",
cms_dict[cms_ver],
*value,
"-o",
key,
]
def run(*args, **kwargs):
try:
print(" ".join(args[0]))
subprocess.run(*args, **kwargs)
except Exception as e:
print(f'Failed {" ".join(args[0])}: {e}')
if __name__ == "__main__":
os.chdir(Path(__file__).parent)
os.environ["CUSTOM_COMPILE_COMMAND"] = "requirements/compile.py"
os.environ.pop("PIP_REQUIRE_VIRTUALENV", None)
common_args = [
"-m",
"piptools",
"compile",
# temporarily remove "--generate-hashes", until all dependencies are actual releases
"--allow-unsafe",
] + sys.argv[1:]
print("Upgrading pip-tools")
for py_ver in {key.split("-")[0] for key in COMPILE_SETTINGS.keys()}:
args = [
f"python{py_ver[2]}.{py_ver[3:]}",
"-m",
"pip",
"install",
"--upgrade",
"pip-tools",
]
subprocess.run(args, capture_output=True)
print("Creating requirement files")
for key, value in COMPILE_SETTINGS.items():
run(
get_args(key + "-default.txt", value, common_args),
check=True,
capture_output=True,
)
run(
get_args(key + "-versioning.txt", value, common_args),
check=True,
capture_output=True,
)