Commit c5e700b
authored
Fix rmg_env_command dropping PYTHONPATH needed for source-tree RMG-Py (#994)
## Failure mode
`rmg_env_command()`'s `RMG_PYTHON` branch (direct-interpreter
invocation, used
on conda/mambaforge installs where micromamba's `conda` shim is broken)
unsets `_ARC_ENV_ACTIVATION_VARS` before invoking `rmg_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-mismatch
crashes). `PYTHONPATH` is included in that unset list.
That's correct when RMG-Py/Arkane are pip-installed into `rmg_env`. But
on
a host where RMG-Py/Arkane are used from a **source checkout reachable
only via `PYTHONPATH`**, unsetting it and stopping there leaves the
child
interpreter unable to import `rmgpy`/`arkane` at all. Every call through
this branch dies with:
```
/home/alon/anaconda3/envs/rmg_env/bin/python: No module named arkane
```
Real-run evidence:
`/home/alon/runs/t3-pes-CH2O2/iteration_1/PDep_SA/network1_1/MSC/stderr.log`
contains 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 `PYTHONPATH` bound in the child is exactly the kind of
env leakage this branch exists to scrub (see the module docstring / the
`_ARC_ENV_ACTIVATION_VARS` comment) — a stale entry (e.g. an old
checkout
on the caller's `PYTHONPATH`) could shadow `rmg_env`'s own site-packages
or 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 `PYTHONPATH` from ARC's own `RMG_PATH`
setting
(already resolved in `arc/settings/settings.py`, alongside
`RMG_PYTHON`),
shell-quoted like the neighbouring lines, and only when `RMG_PATH` is
truthy (never emit an empty `export PYTHONPATH=`, which would be worse
than leaving it unset):
```bash
unset CONDA_PREFIX ... PYTHONPATH PYTHONHOME
export PATH=/home/alon/anaconda3/envs/rmg_env/bin:"$PATH"
export PYTHONPATH=/home/alon/Code/RMG-Py-t3pes # <-- restored
/home/alon/anaconda3/envs/rmg_env/bin/python -c "import arkane; print(arkane.__file__)"
# -> arkane OK
```
Verified manually on the affected host before implementing.
## The other two branches
- `MAMBA_EXE` branch and the launcher-hunt (`bash -l`) branch never
unset
`PYTHONPATH` in the first place — they route through a launcher's `run`
(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
- [x] Baseline: `python -m pytest arc/job/env_run_test.py` — 36 passed
(unmodified branch)
- [x] Post-fix: same command — 38 passed (36 + 2 new regression tests)
- [x] New tests assert `PYTHONPATH` is re-exported from `RMG_PATH`
(after
the `unset`) in the `RMG_PYTHON` branch, and that nothing is emitted
when `RMG_PATH` is falsy. Settings are patched via `patch.dict`, so
the tests don't depend on this machine's real paths.
- [x] `ruff check arc/job/env_run.py arc/job/env_run_test.py` — clean2 files changed
Lines changed: 128 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
168 | 168 | | |
169 | 169 | | |
170 | 170 | | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
176 | 181 | | |
177 | 182 | | |
178 | 183 | | |
| |||
182 | 187 | | |
183 | 188 | | |
184 | 189 | | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
185 | 215 | | |
186 | 216 | | |
187 | 217 | | |
| |||
196 | 226 | | |
197 | 227 | | |
198 | 228 | | |
199 | | - | |
200 | | - | |
201 | | - | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
202 | 242 | | |
203 | 243 | | |
204 | 244 | | |
| |||
224 | 264 | | |
225 | 265 | | |
226 | 266 | | |
| 267 | + | |
227 | 268 | | |
228 | 269 | | |
229 | 270 | | |
| |||
235 | 276 | | |
236 | 277 | | |
237 | 278 | | |
238 | | - | |
| 279 | + | |
239 | 280 | | |
240 | 281 | | |
241 | 282 | | |
242 | 283 | | |
243 | | - | |
| 284 | + | |
244 | 285 | | |
245 | 286 | | |
246 | | - | |
247 | | - | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
248 | 291 | | |
249 | 292 | | |
250 | 293 | | |
251 | 294 | | |
252 | 295 | | |
253 | 296 | | |
254 | | - | |
| 297 | + | |
255 | 298 | | |
256 | 299 | | |
257 | 300 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
384 | 384 | | |
385 | 385 | | |
386 | 386 | | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
387 | 459 | | |
388 | 460 | | |
0 commit comments