Skip to content

gh-125398: Convert paths in venv activate script when using Git Bash under Windows #125399

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 19, 2024

Conversation

julienp
Copy link
Contributor

@julienp julienp commented Oct 13, 2024

With #112508 the check to convert paths when running on Windows was changed from using the non-posix environment variable $OSTYPE to using uname instead.

However this missed the fact that when running under Git Bash on Windows, uname reports MINGW* ($OSTYPE is still msys).

This results in $PATH being set to something like D:\a\github-actions-shells\github-actions-shells\venv/Scripts:…, instead of /d/a/github-actions-shells/github-actions-shells/venv/Scripts.

Notably, the Git Bash is the bash shell that’s used for GitHub Actions Windows runners, and ships with VSCode.

Fixes #125398

@julienp julienp requested a review from vsajip as a code owner October 13, 2024 14:40
@ghost
Copy link

ghost commented Oct 13, 2024

All commit authors signed the Contributor License Agreement.
CLA signed

@bedevere-app
Copy link

bedevere-app bot commented Oct 13, 2024

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

With python#112508 the check to converts paths when running on Windows was changed from using the non-posix environment variable `$OSTYPE` to using `uname` instead.

However this missed the fact that when running under Git Bash on Windows, uname reports `MINGW*` (`$OSTYPE` is still `msys`).

This results in `$PATH` being set to something like `D:\a\github-actions-shells\github-actions-shells\venv/Scripts:…`, instead of `/d/a/github-actions-shells/github-actions-shells/venv/Scripts`.

Notably, the Git Bash is the bash shell that’s used for GitHub Actions Windows runners, and ships with VSCode.
@julienp julienp force-pushed the julienp/venv-mingw branch from 344c038 to 61ab573 Compare October 13, 2024 15:06
@@ -0,0 +1 @@
Fix the conversion of the VIRTUAL_ENV path in the activate script in :mod:`venv` when running in Git Bash for Windows.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommend used this.

Suggested change
Fix the conversion of the VIRTUAL_ENV path in the activate script in :mod:`venv` when running in Git Bash for Windows.
Fix the conversion of the ``VIRTUAL_ENV`` path in the activate script in :mod:`venv` when running in Git Bash for Windows.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, the correct markup would be :envvar: :) See also the relevant parts of the devguide.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I edited the PR to use the :envvar: role, but it seems to fail documentation linting:

WARNING: 'envvar' reference target not found: VIRTUAL_ENV [ref.envvar]

Perhaps a nits file needs updating? @erlend-aasland, any ideas?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use :envvar:`!VIRTUAL_ENV` :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally though, VIRTUAL_ENV should be documented in Doc/library/venv.rst.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty sure VIRTUAL_ENV is undocumented on purpose. It's sys.argv[0] that determines whether you're in a venv or not (and if argv[0] is a relative path, it's resolved using PATH, which makes that the other relevant environment variable).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, but it's not undocumented; it is mentioned multiple places in our docs, but it lacks a "formal" .. envvar:: definition ;)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the documentation in the venv module for it, I'd be okay with adding the reference location to there (in short, it says "don't use or rely on this variable, but it might be set")

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I'm minded to commit this as it is currently (with !VIRTUAL_ENV), and that envvar definition can be added in a subsequent PR. Any objections?

…W7Ndv.rst

Co-authored-by: RUANG (Roy James) <longjinyii@outlook.com>
@vsajip vsajip added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Oct 15, 2024
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @vsajip for commit a81e9cd 🤖

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Oct 15, 2024
@erlend-aasland erlend-aasland requested a review from a team October 15, 2024 10:49
@vsajip vsajip merged commit 2a378db into python:main Oct 19, 2024
34 checks passed
@vsajip vsajip added needs backport to 3.12 only security fixes needs backport to 3.13 bugs and security fixes labels Oct 19, 2024
@miss-islington-app
Copy link

Thanks @julienp for the PR, and @vsajip for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Thanks @julienp for the PR, and @vsajip for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Sorry, @julienp and @vsajip, I could not cleanly backport this to 3.12 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 2a378dba987e125521b678364f0cd44b92dd5d52 3.12

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Oct 19, 2024
… Bash under Windows (pythonGH-125399)

* Convert paths in venv activate script when using Git Bash under Windows

With python#112508 the check to converts paths when running on Windows was changed from using the non-posix environment variable `$OSTYPE` to using `uname` instead.

However this missed the fact that when running under Git Bash on Windows, uname reports `MINGW*` (`$OSTYPE` is still `msys`).

This results in `$PATH` being set to something like `D:\a\github-actions-shells\github-actions-shells\venv/Scripts:…`, instead of `/d/a/github-actions-shells/github-actions-shells/venv/Scripts`.

Notably, the Git Bash is the bash shell that’s used for GitHub Actions Windows runners, and ships with VSCode.
(cherry picked from commit 2a378db)

Co-authored-by: Julien <julien@caffeine.lu>
@bedevere-app
Copy link

bedevere-app bot commented Oct 19, 2024

GH-125733 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Oct 19, 2024
vsajip pushed a commit that referenced this pull request Oct 19, 2024
@julienp
Copy link
Contributor Author

julienp commented Oct 22, 2024

Thank you for merging this! I see the bot comment about the backport to 3.12 failing. I think that's expected, as this was a regression in 3.13.0, and the change that introduced the regression was not applied to 3.12.

@julienp julienp deleted the julienp/venv-mingw branch October 22, 2024 22:33
ebonnal pushed a commit to ebonnal/cpython that referenced this pull request Jan 12, 2025
… Bash under Windows (pythonGH-125399)

* Convert paths in venv activate script when using Git Bash under Windows

With python#112508 the check to converts paths when running on Windows was changed from using the non-posix environment variable `$OSTYPE` to using `uname` instead.

However this missed the fact that when running under Git Bash on Windows, uname reports `MINGW*` (`$OSTYPE` is still `msys`).

This results in `$PATH` being set to something like `D:\a\github-actions-shells\github-actions-shells\venv/Scripts:…`, instead of `/d/a/github-actions-shells/github-actions-shells/venv/Scripts`.

Notably, the Git Bash is the bash shell that’s used for GitHub Actions Windows runners, and ships with VSCode.
@hugovk hugovk removed the needs backport to 3.12 only security fixes label Feb 25, 2025
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.

The virtualenv activate script does not correctly detect the Windows Git Bash shell
7 participants