Skip to content

Commit d0d5b42

Browse files
authored
Merge pull request #11288 from uranusjr/virtualenv-20-try2
2 parents d66d751 + 50e194f commit d0d5b42

16 files changed

+236
-131
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ jobs:
122122
if: matrix.os == 'MacOS'
123123
run: brew install breezy
124124

125-
- run: pip install nox 'virtualenv<20' 'setuptools != 60.6.0'
125+
- run: pip install nox
126126

127127
# Main check
128128
- name: Run unit tests
@@ -179,7 +179,7 @@ jobs:
179179
$acl.AddAccessRule($rule)
180180
Set-Acl "R:\Temp" $acl
181181
182-
- run: pip install nox 'virtualenv<20'
182+
- run: pip install nox
183183
env:
184184
TEMP: "R:\\Temp"
185185

@@ -261,7 +261,7 @@ jobs:
261261
- name: Install Ubuntu dependencies
262262
run: sudo apt-get install bzr
263263

264-
- run: pip install nox 'virtualenv<20'
264+
- run: pip install nox
265265

266266
- name: Run unit tests
267267
run: >-

setup.cfg

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ xfail_strict = True
6363
markers =
6464
network: tests that need network
6565
incompatible_with_sysconfig
66-
incompatible_with_test_venv
6766
incompatible_with_venv
6867
no_auto_tempdir_manager
6968
unit: unit tests

src/pip/_internal/utils/virtualenv.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def _running_under_venv() -> bool:
1919
return sys.prefix != getattr(sys, "base_prefix", sys.prefix)
2020

2121

22-
def _running_under_regular_virtualenv() -> bool:
22+
def _running_under_legacy_virtualenv() -> bool:
2323
"""Checks if sys.real_prefix is set.
2424
2525
This handles virtual environments created with pypa's virtualenv.
@@ -29,8 +29,8 @@ def _running_under_regular_virtualenv() -> bool:
2929

3030

3131
def running_under_virtualenv() -> bool:
32-
"""Return True if we're running inside a virtualenv, False otherwise."""
33-
return _running_under_venv() or _running_under_regular_virtualenv()
32+
"""True if we're running inside a virtual environment, False otherwise."""
33+
return _running_under_venv() or _running_under_legacy_virtualenv()
3434

3535

3636
def _get_pyvenv_cfg_lines() -> Optional[List[str]]:
@@ -77,7 +77,7 @@ def _no_global_under_venv() -> bool:
7777
return False
7878

7979

80-
def _no_global_under_regular_virtualenv() -> bool:
80+
def _no_global_under_legacy_virtualenv() -> bool:
8181
"""Check if "no-global-site-packages.txt" exists beside site.py
8282
8383
This mirrors logic in pypa/virtualenv for determining whether system
@@ -98,7 +98,7 @@ def virtualenv_no_global() -> bool:
9898
if _running_under_venv():
9999
return _no_global_under_venv()
100100

101-
if _running_under_regular_virtualenv():
102-
return _no_global_under_regular_virtualenv()
101+
if _running_under_legacy_virtualenv():
102+
return _no_global_under_legacy_virtualenv()
103103

104104
return False

tests/conftest.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,6 @@ def pytest_collection_modifyitems(config: Config, items: List[pytest.Function])
108108
if item.get_closest_marker("network") is not None:
109109
item.add_marker(pytest.mark.flaky(reruns=3, reruns_delay=2))
110110

111-
if item.get_closest_marker("incompatible_with_test_venv") and config.getoption(
112-
"--use-venv"
113-
):
114-
item.add_marker(pytest.mark.skip("Incompatible with test venv"))
115111
if (
116112
item.get_closest_marker("incompatible_with_venv")
117113
and sys.prefix != sys.base_prefix
@@ -474,9 +470,6 @@ def virtualenv_template(
474470
):
475471
(venv.bin / exe).unlink()
476472

477-
# Enable user site packages.
478-
venv.user_site_packages = True
479-
480473
# Rename original virtualenv directory to make sure
481474
# it's not reused by mistake from one of the copies.
482475
venv_template = tmpdir / "venv_template"
@@ -742,3 +735,8 @@ def mock_server() -> Iterator[MockServer]:
742735
@pytest.fixture
743736
def proxy(request: pytest.FixtureRequest) -> str:
744737
return request.config.getoption("proxy")
738+
739+
740+
@pytest.fixture
741+
def enable_user_site(virtualenv: VirtualEnvironment) -> None:
742+
virtualenv.user_site_packages = True

tests/functional/test_build_env.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def test_build_env_overlay_prefix_has_priority(script: PipTestEnvironment) -> No
204204
assert result.stdout.strip() == "2.0", str(result)
205205

206206

207-
@pytest.mark.incompatible_with_test_venv
207+
@pytest.mark.usefixtures("enable_user_site")
208208
def test_build_env_isolation(script: PipTestEnvironment) -> None:
209209

210210
# Create dummy `pkg` wheel.

tests/functional/test_freeze.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ def test_freeze_with_requirement_option_package_repeated_multi_file(
862862

863863

864864
@pytest.mark.network
865-
@pytest.mark.incompatible_with_test_venv
865+
@pytest.mark.usefixtures("enable_user_site")
866866
def test_freeze_user(
867867
script: PipTestEnvironment, virtualenv: VirtualEnvironment, data: TestData
868868
) -> None:
@@ -900,7 +900,7 @@ def test_freeze_path(tmpdir: Path, script: PipTestEnvironment, data: TestData) -
900900

901901

902902
@pytest.mark.network
903-
@pytest.mark.incompatible_with_test_venv
903+
@pytest.mark.usefixtures("enable_user_site")
904904
def test_freeze_path_exclude_user(
905905
tmpdir: Path, script: PipTestEnvironment, data: TestData
906906
) -> None:

tests/functional/test_install.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def test_pep518_allows_missing_requires(
171171
assert result.files_created
172172

173173

174-
@pytest.mark.incompatible_with_test_venv
174+
@pytest.mark.usefixtures("enable_user_site")
175175
def test_pep518_with_user_pip(
176176
script: PipTestEnvironment, pip_src: Path, data: TestData, common_wheels: Path
177177
) -> None:
@@ -2106,7 +2106,7 @@ def test_target_install_ignores_distutils_config_install_prefix(
21062106
result.did_not_create(relative_script_base)
21072107

21082108

2109-
@pytest.mark.incompatible_with_test_venv
2109+
@pytest.mark.usefixtures("enable_user_site")
21102110
def test_user_config_accepted(script: PipTestEnvironment) -> None:
21112111
# user set in the config file is parsed as 0/1 instead of True/False.
21122112
# Check that this doesn't cause a problem.

tests/functional/test_install_reqs.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,7 @@ def test_install_local_with_subdirectory(script: PipTestEnvironment) -> None:
305305
result.assert_installed("version_subpkg.py", editable=False)
306306

307307

308-
@pytest.mark.incompatible_with_test_venv
309-
@pytest.mark.usefixtures("with_wheel")
308+
@pytest.mark.usefixtures("enable_user_site", "with_wheel")
310309
def test_wheel_user_with_prefix_in_pydistutils_cfg(
311310
script: PipTestEnvironment, data: TestData
312311
) -> None:

0 commit comments

Comments
 (0)