-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
71 lines (53 loc) · 2.39 KB
/
build.py
File metadata and controls
71 lines (53 loc) · 2.39 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python
import compileall
import sys
import tomllib
from pathlib import Path
def parse_python_version_requirement():
"""Parse Python version requirement from pyproject.toml"""
pyproject_path = Path(__file__).parent / "pyproject.toml"
with open(pyproject_path, "rb") as f:
data = tomllib.load(f)
python_req = data["tool"]["poetry"]["dependencies"]["python"]
# Parse version constraint like "^3.12"
if python_req.startswith("^"):
min_version = python_req[1:]
major, minor = map(int, min_version.split("."))
return major, minor
elif python_req.startswith(">="):
min_version = python_req[2:]
major, minor = map(int, min_version.split("."))
return major, minor
else:
# Default fallback
return 3, 12
def get_compatible_python_versions(min_major, min_minor):
"""Generate list of compatible Python versions"""
versions = []
current_major, current_minor = sys.version_info[:2]
# Start from the minimum required version
for major in range(min_major, min_major + 1): # Only Python 3.x for now
start_minor = min_minor if major == min_major else 0
# Go up to current Python version + 2 minor versions for future compatibility
end_minor = max(current_minor + 2, 12) if major == current_major else 12
for minor in range(start_minor, end_minor + 1):
if major == 3 and minor >= min_minor:
versions.append(f"{major}.{minor}")
return versions
def build():
"""Build bytecode for all compatible Python versions"""
try:
min_major, min_minor = parse_python_version_requirement()
compatible_versions = get_compatible_python_versions(min_major, min_minor)
print(f"Building for Python versions: {', '.join(compatible_versions)}")
# Compile for current Python version
print(f"Compiling for Python {sys.version_info.major}.{sys.version_info.minor}")
compileall.compile_dir('pythonDatabases', force=True)
# Note: For actual cross-version bytecode, you'd need multiple Python interpreters
# This compiles with current interpreter but documents compatibility
print("Build completed successfully")
except Exception as e:
print(f"Build failed: {e}")
sys.exit(1)
if __name__ == "__main__":
build()