Update activation scripts from virtualenv#3376
Conversation
| let relative_site_packages = [ | ||
| interpreter.virtualenv().purelib.as_path(), | ||
| interpreter.virtualenv().platlib.as_path(), | ||
| ] |
There was a problem hiding this comment.
Technically need to include both, though we dedup just below.
| site.addsitedir(path) | ||
| sys.path[:] = sys.path[prev_length:] + sys.path[0:prev_length] | ||
|
|
||
| sys.real_prefix = sys.prefix |
There was a problem hiding this comment.
I know this is what virtualenv has done for a long time, and that this script is largely vendored from virtualenv, but it's very strange to me that this script monkeypatches a variable onto the sys module that wouldn't exist otherwise. I don't think the stdlib venv module does this, right?
There was a problem hiding this comment.
I haven't dug into the history deeply, but I think it's a legacy virtualenv thing, possibly from before various evolutions to the sys module came about? We don't rely on this anywhere (though pip and others have code to detect it). I'm inclined to just leave it as-is to avoid deviations, it doesn't really cost us anything.
There was a problem hiding this comment.
Yeah. While it's still very weird to me that a script of ours would do this, I don't mind it too much given that virtualenv has been doing it since forever.
Co-authored-by: Alex Waygood <[email protected]>
## Summary This refreshes the venv activation scripts from upstream `virtualenv` project. This was largely triggered by a problem in the activate.nu script (for nushell): - #14888 - #14914 - #14917 I was careful to respect the git history going back to #3376 (the last time this was done). Actually I looked at the complete history from back when this `uv-virtualenv` crate was named after a Pokémon (⁉️ ), but I found nothing (about activation scripts) from back then that hasn't been overwritten since. ### Some post-processing was involved - Retained license info at top of scripts - Retained template vars (eg `{{ BIN_PATH }}`) to assure current support toward relocatable venv - Retained deviation from upstream in #5640. This seems to be the only deviation that isn't in sync with upstream. ### Notable changes from upstream - (omitted due to undesirable complexity) pypa/virtualenv#2928 and its follow-up pypa/virtualenv#2940 - pypa/virtualenv#2910 (what prompted #14917 from #14888) ## Test Plan There was a request in #14917 to add unit tests to detect breakage or errors. I have added a CI job that runs the nushell activation script. But I think it is better to have the CI test all/most supported shells. See also #15294 I have tested this locally using - [x] nushell (v0.106.1) - [x] cmd.exe (Microsoft Windows [Version 10.0.26100.4946]) - [x] bash in WSL (GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu)) - [x] pwsh (PSVersion 5.1.26100.4768)
Summary
Refreshes some of the activation scripts, and fixes some bugs in
activate_this.pythat were likely the rest of some erroneous copy-pasting.Closes #3346.
Test Plan