Skip to content

🐛 fix(xonsh): retain environment path bytes - #3729

Closed
gaborbernat wants to merge 37 commits into
pypa:mainfrom
gaborbernat:fix/xonsh-legacy-path-3631
Closed

gaborbernat wants to merge 37 commits into
pypa:mainfrom
gaborbernat:fix/xonsh-legacy-path-3631

Conversation

@gaborbernat

Copy link
Copy Markdown
Contributor

The Xonsh activation script embedded the destination as Unicode. An environment created under UTF-8 could then activate a different byte-spelled directory when Xonsh ran under ISO-8859-1, putting that directory first on PATH. The script now records non-ASCII destination paths as bytes and decodes them in the sourcing session. Fixes #3631.

Xonsh re-encoded the destination

Python converts environment paths using the process filesystem codec. At generation time, ActivationSelector.create permits shell scripts only when the destination's filesystem bytes match its UTF-8 encoding. For non-ASCII paths, the Xonsh substitution now embeds those bytes for __VIRTUAL_ENV__ as it already did for Tcl and Tk paths. os.fsdecode gives the sourcing session a string that encodes back to the original bytes.

Behavior changes

On POSIX, Xonsh activation keeps the created destination in VIRTUAL_ENV, PATH, and PKG_CONFIG_PATH when the sourcing session uses another filesystem codec. Windows continues to embed the Unicode path. Existing environments need their activation scripts regenerated to receive the fix.

Reported by oss-scanner: ANT-2026-PQW92I38.

Replaces #3671 after its merge was reverted.

gaborbernat and others added 30 commits November 19, 2026 22:36
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Pin the pre-commit hook to [simplint
0.14.2](https://github.com/gaborbernat/simplint/releases/tag/0.14.2).
This release starts larger files earlier during parallel checks and
sizes cache reads to the archive on disk.

Give bare `Final` annotations explicit types across virtualenv,
maintenance tasks and tests. The wheel installer also declares its lazy
`posixpath` import. Refresh the CodeQL mutant patches for the new
annotations.

The macOS GraalPy reseeding test timed out while uninstalling pip.
Collect each package directory once when cleaning up files from pip's
RECORD. The test also uses the existing fixture that keeps coverage out
of pip's subprocesses.
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Complete the cache creation fix from pypa#3642.
Preserve Tcl and Tk paths across UTF-7 Xonsh activation.
EnvBuilder writes activation scripts before virtualenv applies the selected
activators. A fresh environment could therefore retain an unselected script
that sources destination path text as shell code. Remove the stdlib scripts
before writing virtualenv's selected scripts.
An interrupt could let session cleanup remove temporary app-data while a
seed worker still used it. Wait for active lookups and installations before
propagating the interrupt so cleanup runs after they finish.

Fixes pypa#3636
Delayed expansion in cmd.exe changed literal exclamation marks in saved PATH
entries. Read and restore those values according to the shell mode at each
activation step so entries round-trip if the mode changes.

Fixes pypa#3617
site.addsitedir executes environment .pth hooks before the old script moved
environment paths ahead of host paths. Put interpreter and environment paths
first while those hooks run, then retain their path additions after activation.

Fixes pypa#3623
CPython 3.14 searches upward from a copied libpython for its standard library.
A writable sibling library directory could redirect startup in a private
copy-mode environment. Check that search location before copying the library
and keep the copy needed by relative loader paths.
Without HOME or a passwd entry, platformdirs can leave the default home path
unresolved. Configuration and cache lookup then use paths under the invoking
tree. Skip the default configuration and use temporary app-data when no
absolute default cache path exists. An explicit path remains available.
A migrated default cache could expose group-writable wheel files through a
traversable root. Restrict the root before moving or copying its descendants.
Setgid caches retain group access while other accounts lose access.
Under a non-UTF-8 POSIX locale, seeded pip launchers could spell the
interpreter path with different bytes and fail to start. Use an ASCII shell
wrapper with octal escapes when the path's filesystem bytes differ from UTF-8;
keep direct shebangs otherwise.

Fixes pypa#3632
Xonsh re-encodes the embedded destination with its session's filesystem
codec. After creation under UTF-8, activation under another codec could name
a different directory in PATH.

Record the destination bytes and decode them in the sourcing session, as the
Tcl and Tk paths already do.

Fixes pypa#3631
gaborbernat added a commit to gaborbernat/virtualenv that referenced this pull request Nov 20, 2026
Tcl library paths and Xonsh activation values could change when a script
was sourced under a different text or filesystem codec. Check recorded
Tcl bytes, emit encoding-independent Xonsh source, and refuse path text
that cannot round-trip through the active filesystem codec.

Refs pypa#3743
Refs pypa#3708
Refs pypa#3709
Refs pypa#3729
Refs pypa#3717
@gaborbernat
gaborbernat deleted the fix/xonsh-legacy-path-3631 branch November 23, 2026 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Xonsh activation selects wrong PATH directory after locale change

2 participants