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 PEP 518 support when pip is installed in the user site #5227

Merged
merged 1 commit into from
Apr 18, 2018
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/5524.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix PEP 518 support when pip is installed in the user site.
6 changes: 4 additions & 2 deletions src/pip/_internal/operations/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,10 @@ def format_reqs(rs):
)

if should_isolate:
with self.req.build_env as prefix:
_install_build_reqs(finder, prefix, build_requirements)
with self.req.build_env:
pass
_install_build_reqs(finder, self.req.build_env.path,
build_requirements)
else:
self.req.build_env = NoOpBuildEnvironment(no_clean=False)

Expand Down
18 changes: 11 additions & 7 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,20 +137,24 @@ def isolate(tmpdir):
)


@pytest.yield_fixture(scope='session')
def virtualenv_template(tmpdir_factory):
tmpdir = Path(str(tmpdir_factory.mktemp('virtualenv')))
# Copy over our source tree so that each virtual environment is self
# contained
pip_src = tmpdir.join("pip_src").abspath
@pytest.fixture(scope='session')
def pip_src(tmpdir_factory):
pip_src = Path(str(tmpdir_factory.mktemp('pip_src'))).join('pip_src')
# Copy over our source tree so that each use is self contained
shutil.copytree(
SRC_DIR,
pip_src,
pip_src.abspath,
ignore=shutil.ignore_patterns(
"*.pyc", "__pycache__", "contrib", "docs", "tasks", "*.txt",
"tests", "pip.egg-info", "build", "dist", ".tox", ".git",
),
)
return pip_src


@pytest.yield_fixture(scope='session')
def virtualenv_template(tmpdir_factory, pip_src):
tmpdir = Path(str(tmpdir_factory.mktemp('virtualenv')))
# Create the virtual environment
venv = VirtualEnvironment.create(
tmpdir.join("venv_orig"),
Expand Down
23 changes: 23 additions & 0 deletions tests/functional/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,29 @@ def test_pep518_uses_build_env(script, data, original_setuptools):
)


def test_pep518_with_user_pip(script, virtualenv, pip_src, data):
virtualenv.system_site_packages = True
script.pip("install", "--ignore-installed", "--user", pip_src)
system_pip_dir = script.site_packages_path / 'pip'
system_pip_dir.rmtree()
system_pip_dir.mkdir()
with open(system_pip_dir / '__init__.py', 'w') as fp:
fp.write('raise ImportError\n')
to_install = data.src.join("pep518-3.0")
for command in ('install', 'wheel'):
kwargs = {}
if sys.version_info[:2] == (3, 3):
# Ignore Python 3.3 deprecation warning...
kwargs['expect_stderr'] = True
script.run(
"python", "-c",
"import pip._internal; pip._internal.main(["
"%r, " "'-f', %r, " "%r, "
"])" % (command, str(data.packages), str(to_install)),
**kwargs
)


@pytest.mark.network
def test_pip_second_command_line_interface_works(script, data):
"""
Expand Down