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

Fix virtualenv creation when WORKON_HOME lives within a symlink dir #145

Merged
merged 1 commit into from
Oct 1, 2017
Merged

Conversation

zopieux
Copy link
Collaborator

@zopieux zopieux commented Jul 27, 2017

For creating virtualenvs, pew used to cd into WORKON_HOME and then invoke virtualenv. If WORKON_HOME happens to be in a symlinked directory, the path resolution will consider the real path, not the symlinked one. If the symlink target changes at a later time, all the shebangs that use the real path, which is now obsolete, will be broken.

Eg. if WORKON_HOME is /home/user/.local/venvs and /home/user/.local is a symlink to /opt/local,
then current pew will create the virtualenv with /opt/local as the root, thus creating scripts with #!/opt/local/venvs/foo/bin/python instead of #!/home/user/.local/venvs/foo/bin/python

Before:

>>> check_call(['virtualenv', 'foo'], cwd='/home/user/.local/venvs')
New python executable in /opt/local/venvs/foo/bin/python

This patch changes the check_call() for virtualenv to not cd anywhere and instead passes the absolute (but not resolved/real) path to the virtualenv home (eg. /home/user/.local/venvs/foo).

After:

>>> check_call(['virtualenv', '/home/user/.local/venvs/foo'])
# New python executable in /home/user/.local/venvs/foo/bin/python

For creating virtualenvs, pew used to cd into WORKON_HOME and then
invoke 'virtualenv'. If WORKON_HOME happens to be in a symlinked
directory, the path resolution will consider the real path, not the
symlinked one. If the symlink target changes at a later time, all the
shebangs that use the real path, which is now obsolete, will be
broken.

Eg. if WORKON_HOME is /home/user/.local/venvs
and /home/user/.local is a symlink to /opt/local,
then current pew will create the virtualenv with /opt/local as the root,
thus creating scripts with #!/opt/local/venvs/foo/bin/python
                instead of #!/home/user/.local/venvs/foo/bin/python

Before:

  >>> check_call(['virtualenv', 'foo'], cwd='/home/user/.local/venvs')
  New python executable in /opt/local/venvs/foo/bin/python

This patch changes the check_call() for virtualenv to *not* cd anywhere
and instead passes the absolute (but *not* resolved/real) path to the
virtualenv home (eg. /home/user/.local/venvs/foo).

After:

  >>> check_call(['virtualenv', '/home/user/.local/venvs/foo'])
  # New python executable in /home/user/.local/venvs/foo/bin/python
@berdario
Copy link
Collaborator

berdario commented Oct 1, 2017

Thank you!
Sorry for the delay

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.

2 participants