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

Python 3.12 venv activate script has 2 occurences of VIRTUAL_ENV export, venvctrl-relocate stops to first one #35

Closed
ArthurGarnier opened this issue Nov 7, 2024 · 2 comments

Comments

@ArthurGarnier
Copy link

ArthurGarnier commented Nov 7, 2024

Hi,

When creating a new venv with python 3.12 (RHEL8 or RHEL9, python 3.12.1, venvctrl 0.8.0), the activate script contains 2 occurence of "VIRTUAL_ENV" export :

[root@f0c8018ae854 ~]# python3.12 -m venv test
[root@f0c8018ae854 ~]# grep "export VIRTUAL_ENV=" test/bin/activate
    export VIRTUAL_ENV=$(cygpath "/root/test")
    export VIRTUAL_ENV="/root/test"

Running a relocate seems to only replace the first occurence :

[root@f0c8018ae854 ~]# venvctrl-relocate --source /root/test/ --destination /root/test2
[root@f0c8018ae854 ~]# grep "export VIRTUAL_ENV=" test/bin/activate
    export VIRTUAL_ENV=/root/test2
    export VIRTUAL_ENV="/root/test"

The line

return match.group(0), match.group(1), count
seems responsible of the bug, by ending the function processing and stopping to the first matching line.

Regards,

@kevinconway
Copy link
Owner

The root cause ended up being a bug in the regular expression pattern used to find the first occurrence of VIRTUAL_ENV= and capture the assigned value. The code was already supposed to rewrite multiple occurrences but the extracted path value only ever matched a single occurrence. One issue is that the regular expression matched on ^ *export VIRTUAL_ENV=["']?(.*)["']?$ which matched the first line in your example and captured the value $(cygpath "/root/test"). It then rewrote all occurrences of that value to the new path but there is only one occurrence. The pattern was meant to match the second example and result in /root/test as the captured value. There were two other, smaller bugs in the pattern as well. I made a patch to fix this here: #36

@kevinconway
Copy link
Owner

You should be able to pull in 0.9.0 and resolve the issue

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

2 participants