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

Prevent infinite recursion with pip wheel with $TMPDIR in $PWD #7873

Merged
merged 2 commits into from
Apr 10, 2020
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions news/7872.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Prevent an infinite recursion with ``pip wheel`` when ``$TMPDIR`` is within the source directory.
22 changes: 17 additions & 5 deletions src/pip/_internal/operations/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,25 @@ def _copy2_ignoring_special_files(src, dest):

def _copy_source_tree(source, target):
# type: (str, str) -> None
target_abspath = os.path.abspath(target)
target_basename = os.path.basename(target_abspath)
target_dirname = os.path.dirname(target_abspath)

def ignore(d, names):
# type: (str, List[str]) -> List[str]
# Pulling in those directories can potentially be very slow,
# exclude the following directories if they appear in the top
# level dir (and only it).
# See discussion at https://github.com/pypa/pip/pull/6770
return ['.tox', '.nox'] if d == source else []
skipped = [] # type: List[str]
if d == source:
# Pulling in those directories can potentially be very slow,
# exclude the following directories if they appear in the top
# level dir (and only it).
# See discussion at https://github.com/pypa/pip/pull/6770
skipped += ['.tox', '.nox']
if os.path.abspath(d) == target_dirname:
# Prevent an infinite recursion if the target is in source.
# This can happen when TMPDIR is set to ${PWD}/...
pradyunsg marked this conversation as resolved.
Show resolved Hide resolved
# and we copy PWD to TMPDIR.
skipped += [target_basename]
return skipped

kwargs = dict(ignore=ignore, symlinks=True) # type: CopytreeKwargs

Expand Down
Empty file.
4 changes: 4 additions & 0 deletions tests/data/src/extension/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from setuptools import Extension, setup

module = Extension('extension', sources=['extension.c'])
setup(name='extension', version='0.0.1', ext_modules = [module])
19 changes: 19 additions & 0 deletions tests/functional/test_wheel.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""'pip wheel' tests"""
import os
import re
import sys
from os.path import exists

import pytest
Expand Down Expand Up @@ -289,6 +290,24 @@ def test_pip_wheel_with_user_set_in_config(script, data, common_wheels):
assert "Successfully built withpyproject" in result.stdout, result.stdout


@pytest.mark.skipif(sys.platform.startswith('win'),
reason='The empty extension module does not work on Win')
def test_pip_wheel_ext_module_with_tmpdir_inside(script, data, common_wheels):
hroncok marked this conversation as resolved.
Show resolved Hide resolved
tmpdir = data.src / 'extension/tmp'
tmpdir.mkdir()
script.environ['TMPDIR'] = str(tmpdir)

# To avoid a test dependency on a C compiler, we set the env vars to "noop"
# The .c source is empty anyway
script.environ['CC'] = script.environ['LDSHARED'] = str('true')

result = script.pip(
'wheel', data.src / 'extension',
'--no-index', '-f', common_wheels
)
assert "Successfully built extension" in result.stdout, result.stdout


@pytest.mark.network
def test_pep517_wheels_are_not_confused_with_other_files(script, tmpdir, data):
"""Check correct wheels are copied. (#6196)
Expand Down