Skip to content

Honor a safe path on Python 3.10 via the compat.py310 shim - #28

Merged
jaraco merged 1 commit into
mainfrom
bugfix/py310-safe-path
Aug 28, 2026
Merged

jaraco merged 1 commit into
mainfrom
bugfix/py310-safe-path

Conversation

@jaraco

@jaraco jaraco commented Aug 28, 2026

Copy link
Copy Markdown
Member

PYTHONSAFEPATH keeps the cwd off sys.path so a project module can't shadow a stdlib import — but it was added in 3.11 and is a silent no-op on 3.10. So when coherent.test runs from a repo root that contains stdlib-shadowing modules (e.g. compilers.common ships platform/ and logging.py), the 3.10 matrix leg crashes: first in coherent.test's own import chain (pip_run -> jaraco.context -> platform.system()), then in the inner python -m pytest subprocess (_pytest.logging -> import logging).

Retain PYTHONSAFEPATH as the preferred mechanism and cover 3.10 with the jaraco.compat.py310.safe_path shim:

  • Import it ahead of pip_run in core.py so its side effect strips the cwd before the shadow-prone imports run.
  • Run the pytest subprocess through a -c bootstrap on 3.10 that imports the shim (stripping cwd) before importing pytest. Isolated mode (-I) would also drop PYTHONPATH, which build_env relies on, so it can't be used here.

Verified on 3.10 and 3.13: compilers.common now passes (15) and coherent.test's own suite is unaffected (12).

Ref coherent-oss/system#34.

@jaraco
jaraco merged commit 50b0ce4 into main Aug 28, 2026
28 checks passed
@jaraco
jaraco deleted the bugfix/py310-safe-path branch August 28, 2026 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant