Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Bernát Gábor <[email protected]>
  • Loading branch information
gaborbernat committed Apr 27, 2023
1 parent 0c030bb commit d4b72cc
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 98 deletions.
91 changes: 46 additions & 45 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,22 @@ jobs:
fail-fast: false
matrix:
py:
- "3.11"
- "3.10"
- "3.9"
- "3.8"
- "3.7"
- pypy-3.9
- pypy-3.8
- pypy-3.7
- "3.12.0-alpha.7"
# - "3.11"
# - "3.10"
# - "3.9"
# - "3.8"
# - "3.7"
# - pypy-3.9
# - pypy-3.8
# - pypy-3.7
os:
- ubuntu-22.04
- macos-12
- windows-2022
include:
- { os: macos-12, py: "[email protected]" }
- { os: macos-12, py: "[email protected]" }
# include:
# - { os: macos-12, py: "[email protected]" }
# - { os: macos-12, py: "[email protected]" }
steps:
- uses: taiki-e/install-action@cargo-binstall
- name: Install OS dependencies
Expand Down Expand Up @@ -90,37 +91,37 @@ jobs:
PYTEST_ADDOPTS: "-vv --durations=20"
CI_RUN: "yes"
DIFF_AGAINST: HEAD

check:
name: ${{ matrix.tox_env }} - ${{ matrix.os }}
if: github.event_name != 'schedule' || github.repository_owner == 'pypa'
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-22.04
- windows-2022
tox_env:
- dev
- docs
- readme
- upgrade
- zipapp
exclude:
- { os: windows-2022, tox_env: readme }
- { os: windows-2022, tox_env: docs }
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Python "3.11"
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Install tox
run: python -m pip install tox
- name: Run check for ${{ matrix.tox_env }}
run: python -m tox -e ${{ matrix.tox_env }}
env:
UPGRADE_ADVISORY: "yes"
#
# check:
# name: ${{ matrix.tox_env }} - ${{ matrix.os }}
# if: github.event_name != 'schedule' || github.repository_owner == 'pypa'
# runs-on: ${{ matrix.os }}
# strategy:
# fail-fast: false
# matrix:
# os:
# - ubuntu-22.04
# - windows-2022
# tox_env:
# - dev
# - docs
# - readme
# - upgrade
# - zipapp
# exclude:
# - { os: windows-2022, tox_env: readme }
# - { os: windows-2022, tox_env: docs }
# steps:
# - uses: actions/checkout@v3
# with:
# fetch-depth: 0
# - name: Setup Python "3.11"
# uses: actions/setup-python@v4
# with:
# python-version: "3.11"
# - name: Install tox
# run: python -m pip install tox
# - name: Run check for ${{ matrix.tox_env }}
# run: python -m tox -e ${{ matrix.tox_env }}
# env:
# UPGRADE_ADVISORY: "yes"
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ optional-dependencies.test = [
"packaging>=23.1",
"pytest>=7.3.1",
"pytest-env>=0.8.1",
"pytest-freezegun>=0.4.2",
"pytest-mock>=3.10",
"pytest-randomly>=3.12",
"pytest-timeout>=2.1",
"time-machine>=2.9",
]
urls.Documentation = "https://virtualenv.pypa.io"
urls.Homepage = "https://github.com/pypa/virtualenv"
Expand Down
22 changes: 12 additions & 10 deletions src/virtualenv/seed/embed/base_embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ def __init__(self, options):
self.enabled = False

@classmethod
def distributions(cls):
def distributions(cls) -> dict[str, Version]:
return {
"pip": Version.bundle,
"setuptools": Version.bundle,
"wheel": Version.bundle,
}

def distribution_to_versions(self):
def distribution_to_versions(self) -> dict[str, str]:
return {
distribution: getattr(self, f"{distribution}_version")
for distribution in self.distributions()
if getattr(self, f"no_{distribution}") is False
if getattr(self, f"no_{distribution}") is False and getattr(self, f"{distribution}_version") != "none"
}

@classmethod
Expand Down Expand Up @@ -71,11 +71,13 @@ def add_parser_arguments(cls, parser, interpreter, app_data): # noqa: U100
default=[],
)
for distribution, default in cls.distributions().items():
if interpreter.version_info > (3, 11) and distribution in {"wheel", "setuptools"}:
default = "none"
parser.add_argument(
f"--{distribution}",
dest=distribution,
metavar="version",
help=f"version of {distribution} to install as seed: embed, bundle or exact version",
help=f"version of {distribution} to install as seed: embed, bundle, none or exact version",
default=default,
)
for distribution in cls.distributions():
Expand All @@ -84,10 +86,7 @@ def add_parser_arguments(cls, parser, interpreter, app_data): # noqa: U100
dest=f"no_{distribution}",
action="store_true",
help=f"do not install {distribution}",
default=True
if (float(interpreter.version.split(" ")[0].rsplit(".", 1)[0]) >= 12)
and (distribution in {"wheel", "setuptools"})
else False,
default=False,
)
parser.add_argument(
"--no-periodic-update",
Expand All @@ -97,7 +96,7 @@ def add_parser_arguments(cls, parser, interpreter, app_data): # noqa: U100
default=not PERIODIC_UPDATE_ON_BY_DEFAULT,
)

def __repr__(self):
def __repr__(self) -> str:
result = self.__class__.__name__
result += "("
if self.extra_search_dir:
Expand All @@ -106,7 +105,10 @@ def __repr__(self):
for distribution in self.distributions():
if getattr(self, f"no_{distribution}"):
continue
ver = f"={getattr(self, f'{distribution}_version', None) or 'latest'}"
version = getattr(self, f"{distribution}_version", None)
if version == "none":
continue
ver = f"={version or 'latest'}"
result += f" {distribution}{ver},"
return result[:-1] + ")"

Expand Down
6 changes: 4 additions & 2 deletions tests/integration/test_run_int.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

from pathlib import Path

import pytest

from virtualenv import cli_run
Expand All @@ -8,8 +10,8 @@


@pytest.mark.skipif(IS_PYPY, reason="setuptools distutils patching does not work")
def test_app_data_pinning(tmp_path):
version = "19.3.1"
def test_app_data_pinning(tmp_path: Path) -> None:
version = "23.0"
result = cli_run([str(tmp_path), "--pip", version, "--activators", "", "--seeder", "app-data"])
code, out, _ = run_cmd([str(result.creator.script("pip")), "list", "--disable-pip-version-check"])
assert not code
Expand Down
5 changes: 3 additions & 2 deletions tests/unit/config/test___main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import re
import sys
from pathlib import Path
from subprocess import PIPE, Popen, check_output

import pytest
Expand Down Expand Up @@ -59,8 +60,8 @@ def test_fail_with_traceback(raise_on_session_done, tmp_path, capsys):


@pytest.mark.usefixtures("session_app_data")
def test_session_report_full(tmp_path, capsys):
run_with_catch([str(tmp_path)])
def test_session_report_full(tmp_path: Path, capsys: pytest.CaptureFixture[str]) -> None:
run_with_catch([str(tmp_path), "--setuptools", "bundle", "--wheel", "bundle"])
out, err = capsys.readouterr()
assert err == ""
lines = out.splitlines()
Expand Down
23 changes: 9 additions & 14 deletions tests/unit/seed/embed/test_base_embed.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import sys
from pathlib import Path

import pytest

Expand All @@ -16,17 +17,11 @@ def test_download_cli_flag(args, download, tmp_path):
assert session.seeder.download is download


@pytest.mark.parametrize(
("args", "install"),
[([], True)],
)
def test_embed_optional_wheels(args, install, tmp_path):
session = session_via_cli(args + [str(tmp_path)])
if float(sys.version.split(" ")[0].rsplit(".", 1)[0]) >= 12:
assert session.seeder.no_setuptools is install
assert session.seeder.no_wheel is install
assert session.seeder.no_pip is not install
else:
assert session.seeder.no_setuptools is not install
assert session.seeder.no_wheel is not install
assert session.seeder.no_pip is not install
def test_embed_wheel_versions(tmp_path: Path) -> None:
session = session_via_cli([str(tmp_path)])
expected = (
{"pip": "bundle"}
if sys.version_info[:2] >= (3, 12)
else {"pip": "bundle", "setuptools": "bundle", "wheel": "bundle"}
)
assert session.seeder.distribution_to_versions() == expected
8 changes: 5 additions & 3 deletions tests/unit/seed/embed/test_bootstrap_link_via_app_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import contextlib
import os
import sys
from pathlib import Path
from stat import S_IWGRP, S_IWOTH, S_IWUSR
from subprocess import Popen, check_call
from threading import Thread

import pytest
from pytest_mock import MockerFixture

from virtualenv.discovery import cached_py_info
from virtualenv.discovery.py_info import PythonInfo
Expand Down Expand Up @@ -202,7 +204,7 @@ def test_populated_read_only_cache_and_copied_app_data(tmp_path, current_fastest
@pytest.mark.parametrize("pkg", ["pip", "setuptools", "wheel"])
@pytest.mark.usefixtures("session_app_data", "current_fastest", "coverage_env")
def test_base_bootstrap_link_via_app_data_no(tmp_path, pkg):
create_cmd = [str(tmp_path), "--seeder", "app-data", f"--no-{pkg}"]
create_cmd = [str(tmp_path), "--seeder", "app-data", f"--no-{pkg}", "--wheel", "bundle", "--setuptools", "bundle"]
result = cli_run(create_cmd)
assert not (result.creator.purelib / pkg).exists()
for key in {"pip", "setuptools", "wheel"} - {pkg}:
Expand All @@ -216,7 +218,7 @@ def test_app_data_parallel_ok(tmp_path):


@pytest.mark.usefixtures("temp_app_data")
def test_app_data_parallel_fail(tmp_path, mocker):
def test_app_data_parallel_fail(tmp_path: Path, mocker: MockerFixture) -> None:
mocker.patch("virtualenv.seed.embed.via_app_data.pip_install.base.PipInstall.build_image", side_effect=RuntimeError)
exceptions = _run_parallel_threads(tmp_path)
assert len(exceptions) == 2
Expand All @@ -230,7 +232,7 @@ def _run_parallel_threads(tmp_path):

def _run(name):
try:
cli_run(["--seeder", "app-data", str(tmp_path / name), "--no-pip", "--no-setuptools"])
cli_run(["--seeder", "app-data", str(tmp_path / name), "--no-pip", "--no-setuptools", "--wheel", "bundle"])
except Exception as exception:
as_str = str(exception)
exceptions.append(as_str)
Expand Down
15 changes: 12 additions & 3 deletions tests/unit/seed/wheels/test_acquire.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

import os
import sys
from datetime import datetime
from datetime import UTC, datetime
from pathlib import Path
from subprocess import CalledProcessError
from unittest.mock import MagicMock

import pytest
from pytest_mock import MockerFixture
from time_machine import TimeMachineFixture

from virtualenv.app_data import AppDataDiskFolder
from virtualenv.seed.wheels.acquire import download_wheel, get_wheel, pip_wheel_env_run
Expand Down Expand Up @@ -113,8 +116,14 @@ def test_get_wheel_download_not_called(mocker, for_py_version, session_app_data,
assert write.call_count == 0


@pytest.mark.usefixtures("freezer")
def test_get_wheel_download_cached(tmp_path, mocker, for_py_version, downloaded_wheel):
def test_get_wheel_download_cached(
tmp_path: Path,
mocker: MockerFixture,
for_py_version: str,
downloaded_wheel: tuple[Wheel, MagicMock],
time_machine: TimeMachineFixture,
) -> None:
time_machine.move_to(datetime.now(tz=UTC), tick=False)
from virtualenv.app_data.via_disk_folder import JSONStoreDisk

app_data = AppDataDiskFolder(folder=str(tmp_path))
Expand Down
Loading

0 comments on commit d4b72cc

Please sign in to comment.