Skip to content

Commit d4b72cc

Browse files
committed
PR feedback
Signed-off-by: Bernát Gábor <bgabor8@bloomberg.net>
1 parent 0c030bb commit d4b72cc

File tree

9 files changed

+110
-98
lines changed

9 files changed

+110
-98
lines changed

.github/workflows/check.yml

+46-45
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,22 @@ jobs:
1919
fail-fast: false
2020
matrix:
2121
py:
22-
- "3.11"
23-
- "3.10"
24-
- "3.9"
25-
- "3.8"
26-
- "3.7"
27-
- pypy-3.9
28-
- pypy-3.8
29-
- pypy-3.7
22+
- "3.12.0-alpha.7"
23+
# - "3.11"
24+
# - "3.10"
25+
# - "3.9"
26+
# - "3.8"
27+
# - "3.7"
28+
# - pypy-3.9
29+
# - pypy-3.8
30+
# - pypy-3.7
3031
os:
3132
- ubuntu-22.04
3233
- macos-12
3334
- windows-2022
34-
include:
35-
- { os: macos-12, py: "brew@3.9" }
36-
- { os: macos-12, py: "brew@3.8" }
35+
# include:
36+
# - { os: macos-12, py: "brew@3.9" }
37+
# - { os: macos-12, py: "brew@3.8" }
3738
steps:
3839
- uses: taiki-e/install-action@cargo-binstall
3940
- name: Install OS dependencies
@@ -90,37 +91,37 @@ jobs:
9091
PYTEST_ADDOPTS: "-vv --durations=20"
9192
CI_RUN: "yes"
9293
DIFF_AGAINST: HEAD
93-
94-
check:
95-
name: ${{ matrix.tox_env }} - ${{ matrix.os }}
96-
if: github.event_name != 'schedule' || github.repository_owner == 'pypa'
97-
runs-on: ${{ matrix.os }}
98-
strategy:
99-
fail-fast: false
100-
matrix:
101-
os:
102-
- ubuntu-22.04
103-
- windows-2022
104-
tox_env:
105-
- dev
106-
- docs
107-
- readme
108-
- upgrade
109-
- zipapp
110-
exclude:
111-
- { os: windows-2022, tox_env: readme }
112-
- { os: windows-2022, tox_env: docs }
113-
steps:
114-
- uses: actions/checkout@v3
115-
with:
116-
fetch-depth: 0
117-
- name: Setup Python "3.11"
118-
uses: actions/setup-python@v4
119-
with:
120-
python-version: "3.11"
121-
- name: Install tox
122-
run: python -m pip install tox
123-
- name: Run check for ${{ matrix.tox_env }}
124-
run: python -m tox -e ${{ matrix.tox_env }}
125-
env:
126-
UPGRADE_ADVISORY: "yes"
94+
#
95+
# check:
96+
# name: ${{ matrix.tox_env }} - ${{ matrix.os }}
97+
# if: github.event_name != 'schedule' || github.repository_owner == 'pypa'
98+
# runs-on: ${{ matrix.os }}
99+
# strategy:
100+
# fail-fast: false
101+
# matrix:
102+
# os:
103+
# - ubuntu-22.04
104+
# - windows-2022
105+
# tox_env:
106+
# - dev
107+
# - docs
108+
# - readme
109+
# - upgrade
110+
# - zipapp
111+
# exclude:
112+
# - { os: windows-2022, tox_env: readme }
113+
# - { os: windows-2022, tox_env: docs }
114+
# steps:
115+
# - uses: actions/checkout@v3
116+
# with:
117+
# fetch-depth: 0
118+
# - name: Setup Python "3.11"
119+
# uses: actions/setup-python@v4
120+
# with:
121+
# python-version: "3.11"
122+
# - name: Install tox
123+
# run: python -m pip install tox
124+
# - name: Run check for ${{ matrix.tox_env }}
125+
# run: python -m tox -e ${{ matrix.tox_env }}
126+
# env:
127+
# UPGRADE_ADVISORY: "yes"

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ optional-dependencies.test = [
5757
"packaging>=23.1",
5858
"pytest>=7.3.1",
5959
"pytest-env>=0.8.1",
60-
"pytest-freezegun>=0.4.2",
6160
"pytest-mock>=3.10",
6261
"pytest-randomly>=3.12",
6362
"pytest-timeout>=2.1",
63+
"time-machine>=2.9",
6464
]
6565
urls.Documentation = "https://virtualenv.pypa.io"
6666
urls.Homepage = "https://github.com/pypa/virtualenv"

src/virtualenv/seed/embed/base_embed.py

+12-10
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,18 @@ def __init__(self, options):
3030
self.enabled = False
3131

3232
@classmethod
33-
def distributions(cls):
33+
def distributions(cls) -> dict[str, Version]:
3434
return {
3535
"pip": Version.bundle,
3636
"setuptools": Version.bundle,
3737
"wheel": Version.bundle,
3838
}
3939

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

4747
@classmethod
@@ -71,11 +71,13 @@ def add_parser_arguments(cls, parser, interpreter, app_data): # noqa: U100
7171
default=[],
7272
)
7373
for distribution, default in cls.distributions().items():
74+
if interpreter.version_info > (3, 11) and distribution in {"wheel", "setuptools"}:
75+
default = "none"
7476
parser.add_argument(
7577
f"--{distribution}",
7678
dest=distribution,
7779
metavar="version",
78-
help=f"version of {distribution} to install as seed: embed, bundle or exact version",
80+
help=f"version of {distribution} to install as seed: embed, bundle, none or exact version",
7981
default=default,
8082
)
8183
for distribution in cls.distributions():
@@ -84,10 +86,7 @@ def add_parser_arguments(cls, parser, interpreter, app_data): # noqa: U100
8486
dest=f"no_{distribution}",
8587
action="store_true",
8688
help=f"do not install {distribution}",
87-
default=True
88-
if (float(interpreter.version.split(" ")[0].rsplit(".", 1)[0]) >= 12)
89-
and (distribution in {"wheel", "setuptools"})
90-
else False,
89+
default=False,
9190
)
9291
parser.add_argument(
9392
"--no-periodic-update",
@@ -97,7 +96,7 @@ def add_parser_arguments(cls, parser, interpreter, app_data): # noqa: U100
9796
default=not PERIODIC_UPDATE_ON_BY_DEFAULT,
9897
)
9998

100-
def __repr__(self):
99+
def __repr__(self) -> str:
101100
result = self.__class__.__name__
102101
result += "("
103102
if self.extra_search_dir:
@@ -106,7 +105,10 @@ def __repr__(self):
106105
for distribution in self.distributions():
107106
if getattr(self, f"no_{distribution}"):
108107
continue
109-
ver = f"={getattr(self, f'{distribution}_version', None) or 'latest'}"
108+
version = getattr(self, f"{distribution}_version", None)
109+
if version == "none":
110+
continue
111+
ver = f"={version or 'latest'}"
110112
result += f" {distribution}{ver},"
111113
return result[:-1] + ")"
112114

tests/integration/test_run_int.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import annotations
22

3+
from pathlib import Path
4+
35
import pytest
46

57
from virtualenv import cli_run
@@ -8,8 +10,8 @@
810

911

1012
@pytest.mark.skipif(IS_PYPY, reason="setuptools distutils patching does not work")
11-
def test_app_data_pinning(tmp_path):
12-
version = "19.3.1"
13+
def test_app_data_pinning(tmp_path: Path) -> None:
14+
version = "23.0"
1315
result = cli_run([str(tmp_path), "--pip", version, "--activators", "", "--seeder", "app-data"])
1416
code, out, _ = run_cmd([str(result.creator.script("pip")), "list", "--disable-pip-version-check"])
1517
assert not code

tests/unit/config/test___main__.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import re
44
import sys
5+
from pathlib import Path
56
from subprocess import PIPE, Popen, check_output
67

78
import pytest
@@ -59,8 +60,8 @@ def test_fail_with_traceback(raise_on_session_done, tmp_path, capsys):
5960

6061

6162
@pytest.mark.usefixtures("session_app_data")
62-
def test_session_report_full(tmp_path, capsys):
63-
run_with_catch([str(tmp_path)])
63+
def test_session_report_full(tmp_path: Path, capsys: pytest.CaptureFixture[str]) -> None:
64+
run_with_catch([str(tmp_path), "--setuptools", "bundle", "--wheel", "bundle"])
6465
out, err = capsys.readouterr()
6566
assert err == ""
6667
lines = out.splitlines()
+9-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import sys
4+
from pathlib import Path
45

56
import pytest
67

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

1819

19-
@pytest.mark.parametrize(
20-
("args", "install"),
21-
[([], True)],
22-
)
23-
def test_embed_optional_wheels(args, install, tmp_path):
24-
session = session_via_cli(args + [str(tmp_path)])
25-
if float(sys.version.split(" ")[0].rsplit(".", 1)[0]) >= 12:
26-
assert session.seeder.no_setuptools is install
27-
assert session.seeder.no_wheel is install
28-
assert session.seeder.no_pip is not install
29-
else:
30-
assert session.seeder.no_setuptools is not install
31-
assert session.seeder.no_wheel is not install
32-
assert session.seeder.no_pip is not install
20+
def test_embed_wheel_versions(tmp_path: Path) -> None:
21+
session = session_via_cli([str(tmp_path)])
22+
expected = (
23+
{"pip": "bundle"}
24+
if sys.version_info[:2] >= (3, 12)
25+
else {"pip": "bundle", "setuptools": "bundle", "wheel": "bundle"}
26+
)
27+
assert session.seeder.distribution_to_versions() == expected

tests/unit/seed/embed/test_bootstrap_link_via_app_data.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
import contextlib
44
import os
55
import sys
6+
from pathlib import Path
67
from stat import S_IWGRP, S_IWOTH, S_IWUSR
78
from subprocess import Popen, check_call
89
from threading import Thread
910

1011
import pytest
12+
from pytest_mock import MockerFixture
1113

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

217219

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

231233
def _run(name):
232234
try:
233-
cli_run(["--seeder", "app-data", str(tmp_path / name), "--no-pip", "--no-setuptools"])
235+
cli_run(["--seeder", "app-data", str(tmp_path / name), "--no-pip", "--no-setuptools", "--wheel", "bundle"])
234236
except Exception as exception:
235237
as_str = str(exception)
236238
exceptions.append(as_str)

tests/unit/seed/wheels/test_acquire.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
import os
44
import sys
5-
from datetime import datetime
5+
from datetime import UTC, datetime
66
from pathlib import Path
77
from subprocess import CalledProcessError
8+
from unittest.mock import MagicMock
89

910
import pytest
11+
from pytest_mock import MockerFixture
12+
from time_machine import TimeMachineFixture
1013

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

115118

116-
@pytest.mark.usefixtures("freezer")
117-
def test_get_wheel_download_cached(tmp_path, mocker, for_py_version, downloaded_wheel):
119+
def test_get_wheel_download_cached(
120+
tmp_path: Path,
121+
mocker: MockerFixture,
122+
for_py_version: str,
123+
downloaded_wheel: tuple[Wheel, MagicMock],
124+
time_machine: TimeMachineFixture,
125+
) -> None:
126+
time_machine.move_to(datetime.now(tz=UTC), tick=False)
118127
from virtualenv.app_data.via_disk_folder import JSONStoreDisk
119128

120129
app_data = AppDataDiskFolder(folder=str(tmp_path))

0 commit comments

Comments
 (0)