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 343d855
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 89 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
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
1 change: 0 additions & 1 deletion tests/unit/seed/wheels/test_acquire.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ 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):
from virtualenv.app_data.via_disk_folder import JSONStoreDisk

Expand Down
36 changes: 18 additions & 18 deletions tests/unit/seed/wheels/test_periodic_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ def wheel_path(wheel, of, pre_release=""):


@pytest.mark.parametrize("u_log", list(_UPDATE_SKIP.values()), ids=list(_UPDATE_SKIP.keys()))
def test_periodic_update_skip(u_log, mocker, for_py_version, session_app_data, freezer):
freezer.move_to(_UP_NOW)
def test_periodic_update_skip(u_log, mocker, for_py_version, session_app_data, time_machine):
time_machine.move_to(_UP_NOW)
mocker.patch("virtualenv.app_data.via_disk_folder.JSONStoreDisk.read", return_value=u_log.to_dict())
mocker.patch("virtualenv.seed.wheels.periodic_update.trigger_update", side_effect=RuntimeError)

Expand All @@ -235,8 +235,8 @@ def test_periodic_update_skip(u_log, mocker, for_py_version, session_app_data, f


@pytest.mark.parametrize("u_log", list(_UPDATE_YES.values()), ids=list(_UPDATE_YES.keys()))
def test_periodic_update_trigger(u_log, mocker, for_py_version, session_app_data, freezer):
freezer.move_to(_UP_NOW)
def test_periodic_update_trigger(u_log, mocker, for_py_version, session_app_data, time_machine):
time_machine.move_to(_UP_NOW)
mocker.patch("virtualenv.app_data.via_disk_folder.JSONStoreDisk.read", return_value=u_log.to_dict())
write = mocker.patch("virtualenv.app_data.via_disk_folder.JSONStoreDisk.write")
trigger_update_ = mocker.patch("virtualenv.seed.wheels.periodic_update.trigger_update")
Expand Down Expand Up @@ -343,8 +343,8 @@ def test_trigger_update_debug(for_py_version, session_app_data, tmp_path, mocker
assert process.communicate.call_count == 1


def test_do_update_first(tmp_path, mocker, freezer):
freezer.move_to(_UP_NOW)
def test_do_update_first(tmp_path, mocker, time_machine):
time_machine.move_to(_UP_NOW)
wheel = get_embed_wheel("pip", "3.9")
app_data_outer = AppDataDiskFolder(str(tmp_path / "app"))
extra = tmp_path / "extra"
Expand Down Expand Up @@ -421,8 +421,8 @@ def _release(of, context):
}


def test_do_update_skip_already_done(tmp_path, mocker, freezer):
freezer.move_to(_UP_NOW + timedelta(hours=1))
def test_do_update_skip_already_done(tmp_path, mocker, time_machine):
time_machine.move_to(_UP_NOW + timedelta(hours=1))
wheel = get_embed_wheel("pip", "3.9")
app_data_outer = AppDataDiskFolder(str(tmp_path / "app"))
extra = tmp_path / "extra"
Expand Down Expand Up @@ -535,8 +535,8 @@ def download():
)


def test_download_stop_with_embed(tmp_path, mocker, freezer):
freezer.move_to(_UP_NOW)
def test_download_stop_with_embed(tmp_path, mocker, time_machine):
time_machine.move_to(_UP_NOW)
wheel = get_embed_wheel("pip", "3.9")
app_data_outer = AppDataDiskFolder(str(tmp_path / "app"))
pip_version_remote = [wheel_path(wheel, (0, 0, 2)), wheel_path(wheel, (0, 0, 1)), wheel_path(wheel, (-1, 0, 0))]
Expand All @@ -558,8 +558,8 @@ def test_download_stop_with_embed(tmp_path, mocker, freezer):
assert write.call_count == 1


def test_download_manual_stop_after_one_download(tmp_path, mocker, freezer):
freezer.move_to(_UP_NOW)
def test_download_manual_stop_after_one_download(tmp_path, mocker, time_machine):
time_machine.move_to(_UP_NOW)
wheel = get_embed_wheel("pip", "3.9")
app_data_outer = AppDataDiskFolder(str(tmp_path / "app"))
pip_version_remote = [wheel_path(wheel, (0, 1, 1))]
Expand All @@ -580,8 +580,8 @@ def test_download_manual_stop_after_one_download(tmp_path, mocker, freezer):
assert write.call_count == 1


def test_download_manual_ignores_pre_release(tmp_path, mocker, freezer):
freezer.move_to(_UP_NOW)
def test_download_manual_ignores_pre_release(tmp_path, mocker, time_machine):
time_machine.move_to(_UP_NOW)
wheel = get_embed_wheel("pip", "3.9")
app_data_outer = AppDataDiskFolder(str(tmp_path / "app"))
pip_version_remote = [wheel_path(wheel, (0, 0, 1))]
Expand Down Expand Up @@ -613,8 +613,8 @@ def test_download_manual_ignores_pre_release(tmp_path, mocker, freezer):
]


def test_download_periodic_stop_at_first_usable(tmp_path, mocker, freezer):
freezer.move_to(_UP_NOW)
def test_download_periodic_stop_at_first_usable(tmp_path, mocker, time_machine):
time_machine.move_to(_UP_NOW)
wheel = get_embed_wheel("pip", "3.9")
app_data_outer = AppDataDiskFolder(str(tmp_path / "app"))
pip_version_remote = [wheel_path(wheel, (0, 1, 1)), wheel_path(wheel, (0, 1, 0))]
Expand All @@ -641,8 +641,8 @@ def test_download_periodic_stop_at_first_usable(tmp_path, mocker, freezer):
assert write.call_count == 1


def test_download_periodic_stop_at_first_usable_with_previous_minor(tmp_path, mocker, freezer):
freezer.move_to(_UP_NOW)
def test_download_periodic_stop_at_first_usable_with_previous_minor(tmp_path, mocker, time_machine):
time_machine.move_to(_UP_NOW)
wheel = get_embed_wheel("pip", "3.9")
app_data_outer = AppDataDiskFolder(str(tmp_path / "app"))
pip_version_remote = [wheel_path(wheel, (0, 1, 1)), wheel_path(wheel, (0, 1, 0)), wheel_path(wheel, (0, -1, 0))]
Expand Down

0 comments on commit 343d855

Please sign in to comment.