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

Create proxies for pip, wheel, etc. to get around problems with long paths #1004

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import pkgutil
import tempfile
import textwrap
import stat
from distutils.util import strtobool
from os.path import join

Expand Down Expand Up @@ -904,6 +905,34 @@ def space_path2url(p):
logger.end_progress()


def create_proxies(py_executable, bin_dir):
scripts = glob.glob(os.path.join(bin_dir, "pip*"))
scripts += glob.glob(os.path.join(bin_dir, "easy_install*"))
scripts += glob.glob(os.path.join(bin_dir, "wheel*"))

execute_bits = stat.S_IEXEC | stat.S_IXGRP | stat.S_IXOTH

for script in scripts:
head, tail = os.path.split(script)
hidden_destination = os.path.join(head, '.' + tail)

os.rename(script, hidden_destination)

with open(script, "w") as script_proxy:
text = "#!/usr/bin/env sh"
Copy link
Member

Choose a reason for hiding this comment

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

Should this not force an appropriate encoding? What if the venv name contains non-ASCII characters?

text += "\n'%s' '%s' $@" % (
py_executable,
hidden_destination,
)
script_proxy.write(text)

os.chmod(script, os.stat(script).st_mode | execute_bits)
os.chmod(
hidden_destination,
os.stat(hidden_destination).st_mode & ~execute_bits,
)


def create_environment(home_dir, site_packages=False, clear=False,
unzip_setuptools=False,
prompt=None, search_dirs=None, download=False,
Expand Down Expand Up @@ -945,8 +974,13 @@ def create_environment(home_dir, site_packages=False, clear=False,
download=download,
)

install_activate(home_dir, bin_dir, prompt)
if not is_win:
create_proxies(
py_executable=py_executable,
bin_dir=bin_dir
)

install_activate(home_dir, bin_dir, prompt)
install_python_config(home_dir, bin_dir, prompt)

def is_executable_file(fpath):
Expand Down