Skip to content

Commit 92bacd3

Browse files
committed
Switch to requirements.txt-style Python package installation
1 parent d77c54a commit 92bacd3

File tree

2 files changed

+70
-129
lines changed

2 files changed

+70
-129
lines changed

compile_all.py

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,6 @@ def compile_all(self):
206206
print(f"Building {item['name']}")
207207
build_function = getattr(self, build_function_name)
208208
build_function(item)
209-
elif "pip-install" in item:
210-
print(f"Installing {item['name']} with pip")
211-
self._build_with_pip(item)
212209
else:
213210
print(
214211
f"No '{build_function_name}' found in compile_all.py -- "
@@ -225,7 +222,7 @@ def python_exe(self):
225222
return os.path.join(self.install_dir, "bin", "python") + to_exe()
226223
return os.path.join(self.install_dir, "bin", "python_d") + to_exe()
227224

228-
def build_python(self, _=None):
225+
def build_python(self, args=None):
229226
if self.skip_existing:
230227
if os.path.exists(os.path.join(self.install_dir, "bin", "DLLs")):
231228
print(" Not rebuilding Python, it is already in the LibPack")
@@ -343,6 +340,9 @@ def build_python(self, _=None):
343340
os.rename(pyconfig, target)
344341
else:
345342
raise NotImplemented("Non-Windows compilation of Python is not implemented yet")
343+
self._build_pip()
344+
if "requirements" in args:
345+
self._install_python_requirements(args["requirements"])
346346

347347
def get_python_version(self, exe: str = None) -> str:
348348
if exe is None:
@@ -361,18 +361,42 @@ def get_python_version(self, exe: str = None) -> str:
361361
print(e.stderr.decode("utf-8"))
362362
exit(1)
363363

364-
def build_pip(self, _=None):
364+
def _build_pip(self, _=None):
365+
print(" Installing the latest pip")
365366
path_to_python = self.python_exe()
366367
try:
367368
subprocess.run(
368369
[path_to_python, "-m", "ensurepip", "--upgrade"], capture_output=True, check=True
369370
)
371+
subprocess.run(
372+
[path_to_python, "-m", "pip", "install", "--upgrade", "pip"],
373+
capture_output=True,
374+
check=True,
375+
)
370376
except subprocess.CalledProcessError as e:
371377
print("ERROR: Failed to run LibPack's Python executable")
372378
print(e.stdout.decode("utf-8"))
373379
print(e.stderr.decode("utf-8"))
374380
exit(1)
375381

382+
def _install_python_requirements(self, requirements):
383+
print(" Installing the following requirements (and their dependencies) using pip:")
384+
for req in requirements:
385+
print(" " + req)
386+
path_to_python = self.python_exe()
387+
call_args = [path_to_python, "-m", "pip", "install", "--ignore-installed"]
388+
call_args.extend(requirements)
389+
try:
390+
subprocess.run(
391+
call_args,
392+
check=True,
393+
capture_output=True,
394+
)
395+
except subprocess.CalledProcessError as e:
396+
print(f"ERROR: Failed to pip install requirements")
397+
print(e.output.decode("utf-8"))
398+
exit(1)
399+
376400
def build_qt(self, options: dict):
377401
"""Doesn't really "build" Qt, just copies the pre-compiled libraries from the configured path"""
378402
qt_dir = options["install-directory"]
@@ -516,23 +540,20 @@ def _build_standard_cmake(self, extra_args: List[str] = None):
516540

517541
def _pip_install(self, requirement: str) -> None:
518542
path_to_python = self.python_exe()
519-
if self.skip_existing:
543+
try:
544+
# Get rid of any version that's already there.
520545
package_name = requirement.split("==")[0]
521-
try:
522-
result = subprocess.run(
523-
[path_to_python, "-m", "pip", "show", package_name],
524-
check=True,
525-
capture_output=True,
526-
)
527-
if "WARNING:" not in result.stdout.decode("utf-8"):
528-
print(f" Not reinstalling {package_name}, it is already in the LibPack")
529-
return
530-
except subprocess.CalledProcessError:
531-
pass
532-
546+
subprocess.run(
547+
[path_to_python, "-m", "pip", "uninstall", "--yes", package_name],
548+
check=True,
549+
capture_output=True,
550+
)
551+
except subprocess.CalledProcessError as e:
552+
print(f"{package_name} was not uninstalled... continuing")
553+
pass
533554
try:
534555
subprocess.run(
535-
[path_to_python, "-m", "pip", "install", requirement],
556+
[path_to_python, "-m", "pip", "install", "--ignore-installed", requirement],
536557
check=True,
537558
capture_output=True,
538559
)

config.json

Lines changed: 30 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -1,119 +1,39 @@
11
{
22
"FreeCAD-version":"1.0.0",
3-
"LibPack-version":"3.0.0RC3",
3+
"LibPack-version":"3.0.0RC4",
44
"content": [
55
{
66
"name":"python",
77
"git-repo":"https://github.com/python/cpython.git",
8-
"git-ref":"v3.12.4"
9-
},
10-
{
11-
"name":"pip",
12-
"note":"Uses the ensure_pip Python module to install pip after compiling Python"
13-
},
14-
{
15-
"name":"area",
16-
"pip-install":"area==1.1.1"
17-
},
18-
{
19-
"name":"cmake",
20-
"pip-install":"cmake==3.29.3"
21-
},
22-
{
23-
"name":"cog",
24-
"pip-install":"cog==0.6.1"
25-
},
26-
{
27-
"name":"configparser",
28-
"pip-install":"configparser==7.0.0"
29-
},
30-
{
31-
"name":"debugpy",
32-
"pip-install":"debugpy==1.8.2"
33-
},
34-
{
35-
"name":"defusedxml",
36-
"pip-install":"defusedxml==0.7.1"
37-
},
38-
{
39-
"name":"ifcopenshell",
40-
"pip-install":"ifcopenshell==0.7.0.240521"
41-
},
42-
{
43-
"name":"ladybug-core",
44-
"pip-install":"ladybug-core==0.43.0"
45-
},
46-
{
47-
"name":"matplotlib",
48-
"pip-install":"matplotlib==3.9.0"
49-
},
50-
{
51-
"name":"numpy",
52-
"pip-install":"numpy==1.26.4"
53-
},
54-
{
55-
"name":"opencv",
56-
"pip-install":"opencv-python==4.10.0.82"
57-
},
58-
{
59-
"name":"packaging",
60-
"pip-install":"packaging==24.1"
61-
},
62-
{
63-
"name":"pillow",
64-
"pip-install":"Pillow==10.3.0"
65-
},
66-
{
67-
"name":"ply",
68-
"pip-install":"ply==3.11"
69-
},
70-
{
71-
"name":"pycollada",
72-
"pip-install":"pycollada==0.8"
73-
},
74-
{
75-
"name":"pyNastran",
76-
"pip-install":"pyNastran==1.4.1"
77-
},
78-
{
79-
"name":"pyshp",
80-
"pip-install":"pyshp==2.3.1"
81-
},
82-
{
83-
"name":"pysolar",
84-
"pip-install":"pysolar==0.11"
85-
},
86-
{
87-
"name":"pyyaml",
88-
"pip-install":"PyYAML==6.0.1"
89-
},
90-
{
91-
"name":"requests",
92-
"pip-install":"requests==2.32.3"
93-
},
94-
{
95-
"name":"rpdb2",
96-
"pip-install":"rpdb2==2.0.0.1.2"
97-
},
98-
{
99-
"name":"scipy",
100-
"pip-install":"scipy==1.13.1"
101-
},
102-
{
103-
"name":"sets",
104-
"pip-install":"sets==0.3.2"
105-
},
106-
{
107-
"name":"setuptools",
108-
"pip-install":"setuptools==70.0.0"
109-
},
110-
{
111-
"name":"vermin",
112-
"pip-install":"vermin==1.6.0"
113-
},
114-
{
115-
"name":"wheel",
116-
"pip-install":"wheel==0.43.0"
8+
"git-ref":"v3.12.4",
9+
"requirements": [
10+
"area==1.1.1",
11+
"cmake==3.29.3",
12+
"cog==0.6.1",
13+
"configparser==7.0.0",
14+
"debugpy==1.8.2",
15+
"defusedxml==0.7.1",
16+
"ifcopenshell==0.7.0.240627",
17+
"ladybug-core==0.43.0",
18+
"matplotlib==3.9.1",
19+
"numpy==1.26.4",
20+
"opencv-python==4.10.0.84",
21+
"packaging==24.1",
22+
"pillow==10.3.0",
23+
"ply==3.11",
24+
"pycollada==0.8",
25+
"pyNastran==1.4.1",
26+
"pyshp==2.3.1",
27+
"pysolar==0.11",
28+
"PyYAML==6.0.1",
29+
"requests==2.32.3",
30+
"rpdb2==2.0.0.1.2",
31+
"scipy==1.13.1",
32+
"sets==0.3.2",
33+
"setuptools==70.0.0",
34+
"vermin==1.6.0",
35+
"wheel==0.43.0"
36+
]
11737
},
11838
{
11939
"name":"zlib",

0 commit comments

Comments
 (0)