Skip to content

Commit b982dfa

Browse files
committed
amlio
1 parent 4d06acd commit b982dfa

3 files changed

Lines changed: 162 additions & 1 deletion

File tree

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
# Copyright 2026 Ague Samuel Amen
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
from __future__ import annotations
17+
18+
# Engine-controlled auto builder for PyInstaller
19+
# Signature required by host: (matched: dict, pkg_to_import: dict) -> list[str]
20+
from engine_sdk import register_auto_builder # type: ignore
21+
22+
23+
def AUTO_BUILDER(
24+
matched: dict[str, dict[str, object]], pkg_to_import: dict[str, str]
25+
) -> list[str]:
26+
"""
27+
Build PyInstaller arguments from the engine-owned mapping.
28+
29+
Mapping conventions supported for an entry value under key "pyinstaller":
30+
- str: a single CLI argument (e.g., "--collect-all=numpy")
31+
- list[str]: multiple CLI arguments
32+
- dict: expects 'args' or 'flags' -> str | list[str]
33+
- True: ignored by default (no generic meaning)
34+
"""
35+
out: list[str] = []
36+
seen = set()
37+
38+
for pkg, entry in matched.items():
39+
if not isinstance(entry, dict):
40+
continue
41+
val = entry.get("pyinstaller")
42+
if val is None:
43+
continue
44+
args: list[str] = []
45+
if isinstance(val, str):
46+
tmpl_import = pkg_to_import.get(pkg, pkg)
47+
args = [val.replace("{import_name}", tmpl_import)]
48+
elif isinstance(val, list):
49+
tmpl_import = pkg_to_import.get(pkg, pkg)
50+
args = [str(x).replace("{import_name}", tmpl_import) for x in val]
51+
elif isinstance(val, dict):
52+
tmpl_import = pkg_to_import.get(pkg, pkg)
53+
a = val.get("args") or val.get("flags")
54+
if isinstance(a, list):
55+
args = [str(x).replace("{import_name}", tmpl_import) for x in a]
56+
elif isinstance(a, str):
57+
args = [str(a).replace("{import_name}", tmpl_import)]
58+
for a in args:
59+
if a not in seen:
60+
out.append(a)
61+
seen.add(a)
62+
63+
return out
64+
65+
66+
# Register at import time via the SDK facade
67+
try:
68+
register_auto_builder("pyinstaller", AUTO_BUILDER)
69+
except Exception:
70+
pass

ENGINES/pyinstaller/engine.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ class PyInstallerEngine(CompilerEngine):
1616
required_core_version: str = "1.0.0"
1717
required_sdk_version: str = "1.0.0"
1818

19+
def _dedupe_args(self, seq: list[str]) -> list[str]:
20+
seen = set()
21+
out: list[str] = []
22+
for x in seq:
23+
if x not in seen:
24+
out.append(x)
25+
seen.add(x)
26+
return out
27+
1928
def preflight(self, gui, file: str) -> bool:
2029
try:
2130
import shutil
@@ -104,7 +113,19 @@ def build_command(self, gui, file: str) -> list[str]:
104113

105114
# Fichier cible
106115
cmd.append(file)
107-
return cmd
116+
117+
# Auto-plugins mapping for PyInstaller
118+
try:
119+
from engine_sdk import auto_build_command as _ap # type: ignore
120+
121+
auto_args = _ap.compute_auto_for_engine(gui, "pyinstaller") or []
122+
except Exception:
123+
auto_args = []
124+
try:
125+
cmd = self._dedupe_args(cmd)
126+
except Exception:
127+
pass
128+
return cmd + auto_args
108129

109130
def program_and_args(self, gui, file: str) -> Optional[tuple[str, list[str]]]:
110131
# Utilise le python du venv résolu par le VenvManager si disponible

ENGINES/pyinstaller/mapping.json

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,74 @@
11
{
2+
"__aliases__": {
3+
"package_to_import_name": {
4+
"Pillow": "PIL",
5+
"opencv-python": "cv2",
6+
"opencv-contrib-python": "cv2",
7+
"scikit-learn": "sklearn",
8+
"Jinja2": "jinja2",
9+
"wxPython": "wx"
10+
},
11+
"import_to_package": {
12+
"cv2": "opencv-python",
13+
"PIL": "Pillow",
14+
"sklearn": "scikit-learn",
15+
"wx": "wxPython"
16+
}
17+
},
18+
19+
"numpy": {"pyinstaller": ["--collect-all", "{import_name}"]},
20+
"scipy": {"pyinstaller": ["--collect-all", "{import_name}"]},
21+
"pandas": {"pyinstaller": ["--collect-all", "{import_name}"]},
22+
"matplotlib": {"pyinstaller": ["--collect-all", "{import_name}"]},
23+
"scikit-learn": {"pyinstaller": ["--collect-all", "{import_name}"]},
24+
"scikit-image": {"pyinstaller": ["--collect-all", "{import_name}"]},
25+
"Pillow": {"pyinstaller": ["--collect-all", "{import_name}"]},
26+
"imageio": {"pyinstaller": ["--collect-all", "{import_name}"]},
27+
"opencv-python": {"pyinstaller": ["--collect-all", "{import_name}"]},
28+
"opencv-contrib-python": {"pyinstaller": ["--collect-all", "{import_name}"]},
29+
"lxml": {"pyinstaller": ["--collect-all", "{import_name}"]},
30+
31+
"PySide6": {"pyinstaller": ["--collect-all", "{import_name}"]},
32+
"PySide2": {"pyinstaller": ["--collect-all", "{import_name}"]},
33+
"PyQt6": {"pyinstaller": ["--collect-all", "{import_name}"]},
34+
"PyQt5": {"pyinstaller": ["--collect-all", "{import_name}"]},
35+
"tkinter": {"pyinstaller": ["--collect-all", "{import_name}"]},
36+
"Kivy": {"pyinstaller": ["--collect-all", "{import_name}"]},
37+
"wxPython": {"pyinstaller": ["--collect-all", "{import_name}"]},
38+
39+
"torch": {"pyinstaller": ["--collect-all", "{import_name}"]},
40+
"torchvision": {"pyinstaller": ["--collect-all", "{import_name}"]},
41+
"torchaudio": {"pyinstaller": ["--collect-all", "{import_name}"]},
42+
"tensorflow": {"pyinstaller": ["--collect-all", "{import_name}"]},
43+
"onnxruntime": {"pyinstaller": ["--collect-all", "{import_name}"]},
44+
"xgboost": {"pyinstaller": ["--collect-all", "{import_name}"]},
45+
"lightgbm": {"pyinstaller": ["--collect-all", "{import_name}"]},
46+
47+
"statsmodels": {"pyinstaller": ["--collect-all", "{import_name}"]},
48+
"Jinja2": {"pyinstaller": ["--collect-all", "{import_name}"]},
49+
"cryptography": {"pyinstaller": ["--collect-all", "{import_name}"]},
50+
"PyOpenSSL": {"pyinstaller": ["--collect-all", "{import_name}"]},
51+
"pyzmq": {"pyinstaller": ["--collect-all", "{import_name}"]},
52+
"pyaudio": {"pyinstaller": ["--collect-all", "{import_name}"]},
53+
"h5py": {"pyinstaller": ["--collect-all", "{import_name}"]},
54+
"pyserial": {"pyinstaller": ["--collect-all", "{import_name}"]},
55+
"pygame": {"pyinstaller": ["--collect-all", "{import_name}"]},
56+
"spacy": {"pyinstaller": ["--collect-all", "{import_name}"]},
57+
"transformers": {"pyinstaller": ["--collect-all", "{import_name}"]},
58+
"sentencepiece": {"pyinstaller": ["--collect-all", "{import_name}"]},
59+
60+
"shapely": {"pyinstaller": ["--collect-all", "{import_name}"]},
61+
"geopandas": {"pyinstaller": ["--collect-all", "{import_name}"]},
62+
"fiona": {"pyinstaller": ["--collect-all", "{import_name}"]},
63+
"rasterio": {"pyinstaller": ["--collect-all", "{import_name}"]},
64+
"librosa": {"pyinstaller": ["--collect-all", "{import_name}"]},
65+
"sounddevice": {"pyinstaller": ["--collect-all", "{import_name}"]},
66+
67+
"ctypes": {"pyinstaller": ["--hidden-import", "ctypes"]},
68+
"sqlite3": {"pyinstaller": ["--hidden-import", "sqlite3"]},
69+
"pkg_resources": {"pyinstaller": ["--hidden-import", "pkg_resources"]},
70+
"setuptools": {"pyinstaller": ["--hidden-import", "pkg_resources"]},
71+
272
"engine": "pyinstaller",
373
"binary": "pyinstaller",
474
"module": "PyInstaller",

0 commit comments

Comments
 (0)