Skip to content

Commit 6d8039a

Browse files
authored
fix: ignore installed when running pip (#1040)
1 parent ebf6eba commit 6d8039a

6 files changed

Lines changed: 24 additions & 3 deletions

File tree

docs/changelog/1040.bugfix.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Add ``--ignore-installed`` to pip install command to prevent issues with packages already present in the isolated build
2+
environment - by :user:`henryiii` (:issue:`1037`)

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ test = [
9292
'setuptools >= 56.0.0; python_version == "3.11"',
9393
'setuptools >= 67.8.0; python_version >= "3.12"',
9494
"setuptools_scm >= 6",
95+
"pip >= 22.3",
9596
{ include-group = "extra" },
9697
]
9798
typing = [

src/build/env.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ def install_dependencies(self, requirements: Collection[str], constraints: Colle
333333
if (verbosity := _ctx.verbosity) > 1:
334334
cmd += [f'-{"v" * (verbosity - 1)}']
335335

336-
cmd += ['install', '--use-pep517', '--no-warn-script-location', '--no-compile', '--no-input']
336+
cmd += ['install', '--ignore-installed', '--use-pep517', '--no-warn-script-location', '--no-compile', '--no-input']
337337

338338
# pip does not honour environment markers in command line arguments
339339
# but it does from requirement files.

tests/constraints.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
importlib-metadata==4.6
22
packaging==24.0
3+
pip==22.3; python_version < "3.12"
4+
pip==23.2; python_version >= "3.12"
35
pyproject_hooks==1.0
46
setuptools==42.0.0; python_version < "3.10"
57
setuptools==56.0.0; python_version == "3.10"

tests/test_env.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import importlib.util
55
import logging
6+
import pathlib
67
import shutil
78
import subprocess
89
import sys
@@ -235,6 +236,7 @@ def test_default_impl_install_cmd_well_formed(
235236
'pip',
236237
*([f'-{"v" * (verbosity - 1)}'] if verbosity > 1 else []),
237238
'install',
239+
'--ignore-installed',
238240
'--use-pep517',
239241
'--no-warn-script-location',
240242
'--no-compile',
@@ -573,3 +575,19 @@ def test_uv_install_respects_existing_keyring_env( # pragma: no cover -- uv tes
573575

574576
(install_call,) = run_subprocess.call_args_list
575577
assert install_call.kwargs['env']['UV_KEYRING_PROVIDER'] == 'disabled'
578+
579+
580+
@pytest.mark.network
581+
def test_pythonpath_does_not_interfere_with_outer_pip(
582+
monkeypatch: pytest.MonkeyPatch,
583+
tmp_path: pathlib.Path,
584+
) -> None:
585+
flit_core = tmp_path.joinpath('flit_core-0.0.0.dist-info/')
586+
flit_core.mkdir()
587+
588+
monkeypatch.setenv('PYTHONPATH', str(tmp_path))
589+
590+
with build.env.DefaultIsolatedEnv(installer='pip') as env:
591+
env.install({'flit_core'})
592+
593+
assert subprocess.check_call([env.python_executable, '-c', 'import flit_core']) == 0

tox.ini

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ skip_missing_interpreters = true
1414
[testenv]
1515
description =
1616
run test suite with {basepython}
17-
deps =
18-
pip
1917
pass_env =
2018
LC_ALL
2119
PIP_*

0 commit comments

Comments
 (0)