Skip to content

Commit f272148

Browse files
committed
refactor: intégration d'EngineRunner comme source de vérité unique pour la GUI
1 parent 9ca5570 commit f272148

3 files changed

Lines changed: 113 additions & 297 deletions

File tree

Core/Compiler/engine_runner.py

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,17 @@ def resolve_engine_command(
4646
engine_id: str,
4747
context: BuildContext,
4848
engine_config: dict[str, Any] | None = None,
49-
) -> tuple[str, list[str]]:
49+
) -> tuple[str, list[str], dict[str, str]]:
5050
"""
51-
Load *engine_id* and derive the (program, args) pair for *context*.
51+
Load *engine_id* and derive (program, args, env) for *context*.
5252
5353
Args:
5454
engine_id: Registered engine identifier (e.g. ``"pyinstaller"``).
5555
context: BuildContext describing the project.
5656
engine_config: Optional per-engine config overrides.
5757
5858
Returns:
59-
A ``(program, args)`` tuple ready to be passed to subprocess.
59+
A ``(program, args, env)`` tuple ready to be passed to subprocess.
6060
6161
Raises:
6262
EngineRunnerError: When the engine cannot be loaded, does not support
@@ -76,11 +76,11 @@ def resolve_engine_command(
7676
pass
7777

7878
try:
79-
resolved = engine.program_and_args_from_context(context)
80-
except NotImplementedError as exc:
79+
resolved = engine.program_and_args(context)
80+
except NotImplementedError:
8181
raise EngineRunnerError(
82-
f"Engine '{engine_id}' does not support BuildContext builds"
83-
) from exc
82+
f"Engine '{engine_id}' does not implement build_command"
83+
)
8484
except Exception as exc:
8585
raise EngineRunnerError(
8686
f"Engine '{engine_id}' failed to build command: {exc}"
@@ -90,7 +90,16 @@ def resolve_engine_command(
9090
raise EngineRunnerError(f"Engine '{engine_id}' returned no command")
9191

9292
program, args = resolved
93-
return str(program), list(args)
93+
94+
# Retrieve engine-specific environment
95+
try:
96+
env = engine.environment() if hasattr(engine, "environment") else {}
97+
if env is None:
98+
env = {}
99+
except Exception:
100+
env = {}
101+
102+
return str(program), list(args), dict(env)
94103

95104

96105
def run_engine_compile(
@@ -138,16 +147,20 @@ def run_engine_compile(
138147
f"Entrypoint missing or obsolete: {context.entry_point}"
139148
)
140149

141-
# ── 2. Resolve (program, args) from engine ───────────────────────────────
150+
# ── 2. Resolve (program, args, env) from engine ──────────────────────────
142151
try:
143-
program, args = resolve_engine_command(engine_id, context, engine_config)
152+
program, args, engine_env = resolve_engine_command(engine_id, context, engine_config)
144153
except EngineRunnerError as exc:
145154
return _failure(str(exc))
146155

147156
# ── 3. Security hardening ────────────────────────────────────────────────
148157
try:
158+
# Merge engine env with mandatory ARK variables
159+
full_env = dict(engine_env)
160+
full_env["ARK_WORKSPACE"] = str(workspace)
161+
149162
safe_program, safe_args, safe_env = secure_command(
150-
program, args, {"ARK_WORKSPACE": str(workspace)}
163+
program, args, full_env
151164
)
152165
except Exception as exc:
153166
return _failure(f"Unsafe compile command blocked: {exc}")

Core/Compiler/mainprocess.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ def compile_from_context(
406406
"""
407407
Start an async compilation from a :class:`BuildContext`.
408408
409-
Resolves ``(program, args)`` via the engine, then delegates to
409+
Resolves ``(program, args, env)`` via the engine, then delegates to
410410
:class:`CompilerCore` (Qt thread) for non-blocking execution.
411411
412412
Args:
@@ -422,18 +422,21 @@ def compile_from_context(
422422

423423
# Resolve command via engine (pure-Python, no Qt)
424424
try:
425-
program, args = resolve_engine_command(engine_id, context, engine_config)
425+
program, args, engine_env = resolve_engine_command(engine_id, context, engine_config)
426426
except EngineRunnerError as exc:
427427
self.log_message.emit("error", str(exc))
428428
return False
429429

430-
env = {"ARK_WORKSPACE": str(workspace)}
430+
# Merge engine env with mandatory ARK variables
431+
full_env = dict(engine_env)
432+
full_env["ARK_WORKSPACE"] = str(workspace)
433+
431434
file_path = str(workspace / context.entry_point)
432435

433436
return self.compile(
434437
program=program,
435438
args=args,
436-
env=env,
439+
env=full_env,
437440
engine_id=engine_id,
438441
file_path=file_path,
439442
workspace_dir=str(workspace),

0 commit comments

Comments
 (0)