Fix rmg_env_command dropping PYTHONPATH needed for source-tree RMG-Py - #994
Fix rmg_env_command dropping PYTHONPATH needed for source-tree RMG-Py#994alongd wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #994 +/- ##
==========================================
+ Coverage 64.46% 64.51% +0.05%
==========================================
Files 119 119
Lines 39636 39641 +5
Branches 10276 10277 +1
==========================================
+ Hits 25550 25575 +25
+ Misses 11102 11082 -20
Partials 2984 2984
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR fixes rmg_env_command()’s direct-interpreter (RMG_PYTHON) execution path so it can still import rmgpy/arkane when those are provided via a source checkout on PYTHONPATH, while still scrubbing ARC’s leaked activation variables to avoid ABI/library mismatches.
Changes:
- In the
RMG_PYTHONbranch, restorePYTHONPATHfromRMG_PATHafter unsetting ARC activation variables. - Add regression tests covering (a)
PYTHONPATHre-export whenRMG_PATHis truthy and (b) noPYTHONPATHexport whenRMG_PATHis falsy.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
arc/job/env_run.py |
Re-exports PYTHONPATH from RMG_PATH in the direct-interpreter branch after scrubbing leaked activation variables. |
arc/job/env_run_test.py |
Adds regression tests asserting PYTHONPATH re-export behavior in the RMG_PYTHON branch. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Suppressed comments (1)
arc/job/env_run_test.py:410
- The new test hard-codes a developer-specific absolute path (
/home/alon/...) and duplicates it in bothsettings_overridesand the assertion. Using a generic placeholder path (as other tests in this file do, e.g./home/alice/...) and storing it in a variable avoids leaking a real username and makes the test easier to maintain.
settings_overrides = {'RMG_ENV_NAME': 'rmg_env', 'RMG_PYTHON': self.fake_rmg_python,
'RMG_PATH': '/home/alon/Code/RMG-Py-t3pes'}
with patch.dict('arc.job.env_run.settings', settings_overrides):
script = rmg_env_command("-c 'pass'")
self.assertIn(f'export PYTHONPATH={shlex.quote("/home/alon/Code/RMG-Py-t3pes")}', script)
fc55722 to
1078239
Compare
The RMG_PYTHON branch unsets _ARC_ENV_ACTIVATION_VARS (including PYTHONPATH) before invoking rmg_env's interpreter directly, correctly scrubbing ARC's env leakage. But on hosts where RMG-Py/Arkane are used from a source checkout reachable only via PYTHONPATH (not pip-installed into rmg_env), this left the child unable to import rmgpy/arkane at all, e.g. "No module named arkane". Re-export PYTHONPATH from ARC's own RMG_PATH setting after the unset, so a source checkout stays importable while ARC's leaked activation vars are still scrubbed. Only emit the export when RMG_PATH is truthy, to avoid exporting an empty PYTHONPATH. The MAMBA_EXE and launcher-hunt branches never unset PYTHONPATH in the first place (they route through the launcher's `run`, or a login shell that sources the user's profile), so they don't have this gap.
1078239 to
7d86561
Compare
Failure mode
rmg_env_command()'sRMG_PYTHONbranch (direct-interpreter invocation, usedon conda/mambaforge installs where micromamba's
condashim is broken)unsets
_ARC_ENV_ACTIVATION_VARSbefore invokingrmg_env's interpreter,to scrub ARC's env leakage (
BABEL_LIBDIR,LD_LIBRARY_PATH,CONDA_*,etc. — otherwise bound to
arc_env's tree and causing ABI-mismatchcrashes).
PYTHONPATHis included in that unset list.That's correct when RMG-Py/Arkane are pip-installed into
rmg_env. But ona host where RMG-Py/Arkane are used from a source checkout reachable
only via
PYTHONPATH, unsetting it and stopping there leaves the childinterpreter unable to import
rmgpy/arkaneat all. Every call throughthis branch dies with:
Real-run evidence:
/home/alon/runs/t3-pes-CH2O2/iteration_1/PDep_SA/network1_1/MSC/stderr.logcontains exactly that line. Consequence: T3's master-equation sensitivity
job can never run on such a host, so no P-dep network can ever qualify for
QM refinement — the entire PDep→QM feature is silently dead, surfaced only
as the bland "No PDep networks qualified for QM refinement".
Why unsetting PYTHONPATH is still right
Leaving ARC's own
PYTHONPATHbound in the child is exactly the kind ofenv leakage this branch exists to scrub (see the module docstring / the
_ARC_ENV_ACTIVATION_VARScomment) — a stale entry (e.g. an old checkouton the caller's
PYTHONPATH) could shadowrmg_env's own site-packagesor ARC's own modules could bleed into the child. The unset is correct; the
bug is stopping there instead of restoring the target env's own path.
The fix
After the unset, re-export
PYTHONPATHfrom ARC's ownRMG_PATHsetting(already resolved in
arc/settings/settings.py, alongsideRMG_PYTHON),shell-quoted like the neighbouring lines, and only when
RMG_PATHistruthy (never emit an empty
export PYTHONPATH=, which would be worsethan leaving it unset):
Verified manually on the affected host before implementing.
The other two branches
MAMBA_EXEbranch and the launcher-hunt (bash -l) branch never unsetPYTHONPATHin the first place — they route through a launcher'srun(which re-fires the target env's own activation hooks) or a login shell
that sources the user's profile. Neither has this gap, so neither was
changed.
Test plan
python -m pytest arc/job/env_run_test.py— 36 passed (unmodified branch)PYTHONPATHis re-exported fromRMG_PATH(afterthe
unset) in theRMG_PYTHONbranch, and that nothing is emittedwhen
RMG_PATHis falsy. Settings are patched viapatch.dict, sothe tests don't depend on this machine's real paths.
ruff check arc/job/env_run.py arc/job/env_run_test.py— clean