Skip to content

Commit 1a1cbb4

Browse files
committed
Reintroduce the --wheel CLI option, even though it has no effect on Python > 3.8
Also, make the warning visible to the users. And, fix the message to say > 3.8 instead of >= 3.8.
1 parent e9b6ba7 commit 1a1cbb4

File tree

3 files changed

+50
-29
lines changed

3 files changed

+50
-29
lines changed

src/virtualenv/run/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def session_via_cli(args, options=None, setup_logging=True, env=None): # noqa:
4848
env = os.environ if env is None else env
4949
parser, elements = build_parser(args, options, setup_logging, env)
5050
options = parser.parse_args(args)
51+
options.py_version = parser._interpreter.version_info # noqa: SLF001
5152
creator, seeder, activators = tuple(e.create(options) for e in elements) # create types
5253
return Session(
5354
options.verbosity,

src/virtualenv/seed/embed/base_embed.py

+24-17
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
from __future__ import annotations
22

3+
import logging
34
from abc import ABC
45
from argparse import SUPPRESS
56
from pathlib import Path
6-
from warnings import warn
77

88
from virtualenv.seed.seeder import Seeder
99
from virtualenv.seed.wheels import Version
1010

11+
LOGGER = logging.getLogger(__name__)
1112
PERIODIC_UPDATE_ON_BY_DEFAULT = True
1213

1314

@@ -20,24 +21,27 @@ def __init__(self, options) -> None:
2021

2122
self.pip_version = options.pip
2223
self.setuptools_version = options.setuptools
23-
if hasattr(options, "wheel"):
24-
# Python 3.8
25-
self.wheel_version = options.wheel
26-
self.no_wheel = options.no_wheel
27-
elif options.no_wheel:
28-
warn(
29-
"The --no-wheel option is deprecated. "
30-
"It has no effect for Python >= 3.8 as wheel is no longer "
31-
"bundled in virtualenv.",
32-
DeprecationWarning,
33-
stacklevel=1,
34-
)
24+
25+
# wheel version needs special handling
26+
# on Python > 3.8, the default is None (as in not used)
27+
# so we can differentiate between explicit and implicit none
28+
self.wheel_version = options.wheel or "none"
3529

3630
self.no_pip = options.no_pip
3731
self.no_setuptools = options.no_setuptools
32+
self.no_wheel = options.no_wheel
3833
self.app_data = options.app_data
3934
self.periodic_update = not options.no_periodic_update
4035

36+
if options.py_version[:2] >= (3, 9):
37+
if options.wheel is not None or options.no_wheel:
38+
LOGGER.warning(
39+
"The --no-wheel and --wheel options are deprecated. "
40+
"They have no effect for Python > 3.8 as wheel is no longer "
41+
"bundled in virtualenv.",
42+
)
43+
self.no_wheel = True
44+
4145
if not self.distribution_to_versions():
4246
self.enabled = False
4347

@@ -53,7 +57,8 @@ def distribution_to_versions(self) -> dict[str, str]:
5357
return {
5458
distribution: getattr(self, f"{distribution}_version")
5559
for distribution in self.distributions()
56-
if getattr(self, f"no_{distribution}", None) is False and getattr(self, f"{distribution}_version") != "none"
60+
if getattr(self, f"no_{distribution}", None) is False
61+
and getattr(self, f"{distribution}_version") != "none"
5762
}
5863

5964
@classmethod
@@ -83,15 +88,17 @@ def add_parser_arguments(cls, parser, interpreter, app_data): # noqa: ARG003
8388
default=[],
8489
)
8590
for distribution, default in cls.distributions().items():
86-
if interpreter.version_info[:2] >= (3, 12) and distribution == "setuptools":
91+
help_ = f"version of {distribution} to install as seed: embed, bundle, none or exact version"
92+
if interpreter.version_info[:2] >= (3, 12) and distribution in {"wheel", "setuptools"}:
8793
default = "none" # noqa: PLW2901
8894
if interpreter.version_info[:2] >= (3, 9) and distribution == "wheel":
89-
continue
95+
default = None # noqa: PLW2901
96+
help_ = SUPPRESS
9097
parser.add_argument(
9198
f"--{distribution}",
9299
dest=distribution,
93100
metavar="version",
94-
help=f"version of {distribution} to install as seed: embed, bundle, none or exact version",
101+
help=help_,
95102
default=default,
96103
)
97104
for distribution in cls.distributions():

tests/unit/seed/embed/test_base_embed.py

+25-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import annotations
22

33
import sys
4-
import warnings
54
from typing import TYPE_CHECKING
65

76
import pytest
@@ -21,17 +20,31 @@ def test_download_cli_flag(args, download, tmp_path):
2120
assert session.seeder.download is download
2221

2322

24-
@pytest.mark.skipif(sys.version_info[:2] == (3, 8), reason="We still bundle wheels for Python 3.8")
25-
def test_download_deprecated_cli_flag(tmp_path):
26-
with warnings.catch_warnings(record=True) as w:
27-
warnings.simplefilter("always")
28-
session_via_cli(["--no-wheel", str(tmp_path)])
29-
assert len(w) == 1
30-
assert issubclass(w[-1].category, DeprecationWarning)
31-
assert str(w[-1].message) == (
32-
"The --no-wheel option is deprecated. It has no effect for Python >= "
33-
"3.8 as wheel is no longer bundled in virtualenv."
34-
)
23+
@pytest.mark.skipif(sys.version_info[:2] == (3, 8), reason="We still bundle wheel for Python 3.8")
24+
@pytest.mark.parametrize("flag", ["--no-wheel", "--wheel=none", "--wheel=embed", "--wheel=bundle"])
25+
def test_wheel_cli_flags_do_nothing(tmp_path, flag):
26+
session = session_via_cli([flag, str(tmp_path)])
27+
if sys.version_info[:2] >= (3, 12):
28+
expected = {"pip": "bundle"}
29+
else:
30+
expected = {"pip": "bundle", "setuptools": "bundle"}
31+
assert session.seeder.distribution_to_versions() == expected
32+
33+
34+
@pytest.mark.skipif(sys.version_info[:2] == (3, 8), reason="We still bundle wheel for Python 3.8")
35+
@pytest.mark.parametrize("flag", ["--no-wheel", "--wheel=none", "--wheel=embed", "--wheel=bundle"])
36+
def test_wheel_cli_flags_warn(tmp_path, flag, capsys):
37+
session_via_cli([flag, str(tmp_path)])
38+
out, err = capsys.readouterr()
39+
assert "The --no-wheel and --wheel options are deprecated." in out + err
40+
41+
42+
@pytest.mark.skipif(sys.version_info[:2] != (3, 8), reason="We only bundle wheel for Python 3.8")
43+
@pytest.mark.parametrize("flag", ["--no-wheel", "--wheel=none", "--wheel=embed", "--wheel=bundle"])
44+
def test_wheel_cli_flags_dont_warn_on_38(tmp_path, flag, capsys):
45+
session_via_cli([flag, str(tmp_path)])
46+
out, err = capsys.readouterr()
47+
assert "The --no-wheel and --wheel options are deprecated." not in out + err
3548

3649

3750
def test_embed_wheel_versions(tmp_path: Path) -> None:

0 commit comments

Comments
 (0)