Skip to content
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

Conflict with venv on Python 3.12 #34

Open
nfg opened this issue Nov 22, 2024 · 0 comments
Open

Conflict with venv on Python 3.12 #34

nfg opened this issue Nov 22, 2024 · 0 comments

Comments

@nfg
Copy link

nfg commented Nov 22, 2024

Hello!

We ran into a weird issue at work today when we tried upgrading from Python 3.11 to Python 3.12. When we run virtualenv-tools --update-path, we get an error:

(venv) 😿  cristina ./venv/bin/virtualenv-tools --update-path /newpath/venv venv/
Traceback (most recent call last):
  File "/Users/local_nigel/cristina/./venv/bin/virtualenv-tools", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/Users/local_nigel/cristina/venv/lib/python3.12/site-packages/virtualenv_tools.py", line 351, in main
    venv = _get_original_state(path=args.path)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/local_nigel/cristina/venv/lib/python3.12/site-packages/virtualenv_tools.py", line 317, in _get_original_state
    orig_path=get_orig_path(path),
              ^^^^^^^^^^^^^^^^^^^
  File "/Users/local_nigel/cristina/venv/lib/python3.12/site-packages/virtualenv_tools.py", line 263, in get_orig_path
    raise AssertionError(
AssertionError: Could not find VIRTUAL_ENV= in activation script: venv/bin/activate

I did some investigation. The activate script installed by venv on 3.12 looks like this:

# on Windows, a path can contain colons and backslashes and has to be converted:
if [ "${OSTYPE:-}" = "cygwin" ] || [ "${OSTYPE:-}" = "msys" ] ; then
    # transform D:\path\to\venv to /d/path/to/venv on MSYS
    # and to /cygdrive/d/path/to/venv on Cygwin
    export VIRTUAL_ENV=$(cygpath "/Users/local_nigel/cristina/venv")
else
    # use the path as-is
    export VIRTUAL_ENV="/Users/local_nigel/cristina/venv"
fi

When I set up a virtual environment using virtualenv, it looks like this:

VIRTUAL_ENV='/Users/local_nigel/cristina/venv'
if ([ "$OSTYPE" = "cygwin" ] || [ "$OSTYPE" = "msys" ]) && $(command -v cygpath &> /dev/null) ; then
    VIRTUAL_ENV=$(cygpath -u "$VIRTUAL_ENV")
fi
export VIRTUAL_ENV

We're using venv to generate our virtual environments because it's part of the standard library. I can update our build scripts to use virtualenv, but it'd be really nice if this tool worked with activate as generated by venv. 😁

Cheers!

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

No branches or pull requests

1 participant