Skip to content

Commit

Permalink
Link or copy PyPy headers instead of include directory as a whole (#1302
Browse files Browse the repository at this point in the history
)

This pull request changes method of virtualenv's include directory population - instead of linking Python include directory (for example ``/usr/include/python3.7m``) it links or copies distinct header files from that directory. The reason for this change is to make virtualenv'` ``include`` directory not to be symlink in case of PyPy.

Closes #1198
  • Loading branch information
daa authored and gaborbernat committed Jan 31, 2019
1 parent 23e7f7a commit d53a3c4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/changelog/1302.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Copy or link PyPy header files instead of include directory itself
4 changes: 4 additions & 0 deletions tests/test_virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,10 @@ def test_install_python_bin():

for pth in required_executables:
assert os.path.exists(os.path.join(bin_dir, pth)), "%s should exist in bin_dir" % pth
if not virtualenv.IS_JYTHON:
assert os.path.exists(inc_dir)
root_inc_dir = os.path.join(home_dir, "include")
assert not os.path.islink(root_inc_dir)
finally:
shutil.rmtree(tmp_virtualenv)

Expand Down
17 changes: 15 additions & 2 deletions virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -1269,6 +1269,19 @@ def copy_required_files(src_dir, lib_dir, symlink):
copyfile(join(src_dir, fn), join(lib_dir, fn), symlink)


def copy_include_dir(include_src, include_dest, symlink):
"""Copy headers from *include_src* to *include_dest* symlinking if required"""
if not os.path.isdir(include_src):
return
# PyPy headers are located in ``pypy-dir/include`` and following code
# avoids making ``venv-dir/include`` symlink to it
if IS_PYPY:
for fn in os.listdir(include_src):
copyfile(join(include_src, fn), join(include_dest, fn), symlink)
else:
copyfile(include_src, include_dest, symlink)


def copy_tcltk(src, dest, symlink):
""" copy tcl/tk libraries on Windows (issue #93) """
for lib_version in "8.5", "8.6":
Expand Down Expand Up @@ -1355,7 +1368,7 @@ def install_python(home_dir, lib_dir, inc_dir, bin_dir, site_packages, clear, sy
else:
standard_lib_include_dir = join(prefix, "include", PY_VERSION + ABI_FLAGS)
if os.path.exists(standard_lib_include_dir):
copyfile(standard_lib_include_dir, inc_dir, symlink)
copy_include_dir(standard_lib_include_dir, inc_dir, symlink)
else:
logger.debug("No include dir %s", standard_lib_include_dir)

Expand All @@ -1371,7 +1384,7 @@ def install_python(home_dir, lib_dir, inc_dir, bin_dir, site_packages, clear, sy
# (traversing virtualenvs), whereas the platinc_dir is relative to
# the inner virtualenv and ignores the prefix argument.
# This seems more evolved than designed.
copyfile(platform_include_dir, platform_include_dest, symlink)
copy_include_dir(platform_include_dir, platform_include_dest, symlink)

# pypy never uses exec_prefix, just ignore it
if os.path.realpath(sys.exec_prefix) != os.path.realpath(prefix) and not IS_PYPY:
Expand Down

0 comments on commit d53a3c4

Please sign in to comment.