Skip to content

Commit

Permalink
Merge pull request #11288 from uranusjr/virtualenv-20-try2
Browse files Browse the repository at this point in the history
  • Loading branch information
uranusjr authored Oct 27, 2022
2 parents d66d751 + 50e194f commit d0d5b42
Show file tree
Hide file tree
Showing 16 changed files with 236 additions and 131 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ jobs:
if: matrix.os == 'MacOS'
run: brew install breezy

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

# Main check
- name: Run unit tests
Expand Down Expand Up @@ -179,7 +179,7 @@ jobs:
$acl.AddAccessRule($rule)
Set-Acl "R:\Temp" $acl
- run: pip install nox 'virtualenv<20'
- run: pip install nox
env:
TEMP: "R:\\Temp"

Expand Down Expand Up @@ -261,7 +261,7 @@ jobs:
- name: Install Ubuntu dependencies
run: sudo apt-get install bzr

- run: pip install nox 'virtualenv<20'
- run: pip install nox

- name: Run unit tests
run: >-
Expand Down
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ xfail_strict = True
markers =
network: tests that need network
incompatible_with_sysconfig
incompatible_with_test_venv
incompatible_with_venv
no_auto_tempdir_manager
unit: unit tests
Expand Down
12 changes: 6 additions & 6 deletions src/pip/_internal/utils/virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def _running_under_venv() -> bool:
return sys.prefix != getattr(sys, "base_prefix", sys.prefix)


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


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


def _get_pyvenv_cfg_lines() -> Optional[List[str]]:
Expand Down Expand Up @@ -77,7 +77,7 @@ def _no_global_under_venv() -> bool:
return False


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

if _running_under_regular_virtualenv():
return _no_global_under_regular_virtualenv()
if _running_under_legacy_virtualenv():
return _no_global_under_legacy_virtualenv()

return False
12 changes: 5 additions & 7 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,6 @@ def pytest_collection_modifyitems(config: Config, items: List[pytest.Function])
if item.get_closest_marker("network") is not None:
item.add_marker(pytest.mark.flaky(reruns=3, reruns_delay=2))

if item.get_closest_marker("incompatible_with_test_venv") and config.getoption(
"--use-venv"
):
item.add_marker(pytest.mark.skip("Incompatible with test venv"))
if (
item.get_closest_marker("incompatible_with_venv")
and sys.prefix != sys.base_prefix
Expand Down Expand Up @@ -474,9 +470,6 @@ def virtualenv_template(
):
(venv.bin / exe).unlink()

# Enable user site packages.
venv.user_site_packages = True

# Rename original virtualenv directory to make sure
# it's not reused by mistake from one of the copies.
venv_template = tmpdir / "venv_template"
Expand Down Expand Up @@ -742,3 +735,8 @@ def mock_server() -> Iterator[MockServer]:
@pytest.fixture
def proxy(request: pytest.FixtureRequest) -> str:
return request.config.getoption("proxy")


@pytest.fixture
def enable_user_site(virtualenv: VirtualEnvironment) -> None:
virtualenv.user_site_packages = True
2 changes: 1 addition & 1 deletion tests/functional/test_build_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def test_build_env_overlay_prefix_has_priority(script: PipTestEnvironment) -> No
assert result.stdout.strip() == "2.0", str(result)


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

# Create dummy `pkg` wheel.
Expand Down
4 changes: 2 additions & 2 deletions tests/functional/test_freeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ def test_freeze_with_requirement_option_package_repeated_multi_file(


@pytest.mark.network
@pytest.mark.incompatible_with_test_venv
@pytest.mark.usefixtures("enable_user_site")
def test_freeze_user(
script: PipTestEnvironment, virtualenv: VirtualEnvironment, data: TestData
) -> None:
Expand Down Expand Up @@ -900,7 +900,7 @@ def test_freeze_path(tmpdir: Path, script: PipTestEnvironment, data: TestData) -


@pytest.mark.network
@pytest.mark.incompatible_with_test_venv
@pytest.mark.usefixtures("enable_user_site")
def test_freeze_path_exclude_user(
tmpdir: Path, script: PipTestEnvironment, data: TestData
) -> None:
Expand Down
4 changes: 2 additions & 2 deletions tests/functional/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def test_pep518_allows_missing_requires(
assert result.files_created


@pytest.mark.incompatible_with_test_venv
@pytest.mark.usefixtures("enable_user_site")
def test_pep518_with_user_pip(
script: PipTestEnvironment, pip_src: Path, data: TestData, common_wheels: Path
) -> None:
Expand Down Expand Up @@ -2106,7 +2106,7 @@ def test_target_install_ignores_distutils_config_install_prefix(
result.did_not_create(relative_script_base)


@pytest.mark.incompatible_with_test_venv
@pytest.mark.usefixtures("enable_user_site")
def test_user_config_accepted(script: PipTestEnvironment) -> None:
# user set in the config file is parsed as 0/1 instead of True/False.
# Check that this doesn't cause a problem.
Expand Down
3 changes: 1 addition & 2 deletions tests/functional/test_install_reqs.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,7 @@ def test_install_local_with_subdirectory(script: PipTestEnvironment) -> None:
result.assert_installed("version_subpkg.py", editable=False)


@pytest.mark.incompatible_with_test_venv
@pytest.mark.usefixtures("with_wheel")
@pytest.mark.usefixtures("enable_user_site", "with_wheel")
def test_wheel_user_with_prefix_in_pydistutils_cfg(
script: PipTestEnvironment, data: TestData
) -> None:
Expand Down
Loading

0 comments on commit d0d5b42

Please sign in to comment.