Skip to content

Commit a15bd55

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 a15bd55

File tree

3 files changed

+55
-28
lines changed

3 files changed

+55
-28
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

+22-16
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

@@ -83,15 +87,17 @@ def add_parser_arguments(cls, parser, interpreter, app_data): # noqa: ARG003
8387
default=[],
8488
)
8589
for distribution, default in cls.distributions().items():
86-
if interpreter.version_info[:2] >= (3, 12) and distribution == "setuptools":
90+
help_ = f"version of {distribution} to install as seed: embed, bundle, none or exact version"
91+
if interpreter.version_info[:2] >= (3, 12) and distribution in {"wheel", "setuptools"}:
8792
default = "none" # noqa: PLW2901
8893
if interpreter.version_info[:2] >= (3, 9) and distribution == "wheel":
89-
continue
94+
default = None # noqa: PLW2901
95+
help_ = SUPPRESS
9096
parser.add_argument(
9197
f"--{distribution}",
9298
dest=distribution,
9399
metavar="version",
94-
help=f"version of {distribution} to install as seed: embed, bundle, none or exact version",
100+
help=help_,
95101
default=default,
96102
)
97103
for distribution in cls.distributions():

tests/unit/seed/embed/test_base_embed.py

+32-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,38 @@ 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 still bundle wheel for Python 3.8")
43+
def test_unused_wheel_cli_flags_dont_warn(tmp_path, capsys):
44+
session_via_cli([str(tmp_path)])
45+
out, err = capsys.readouterr()
46+
assert "The --no-wheel and --wheel options are deprecated." not in out + err
47+
48+
49+
@pytest.mark.skipif(sys.version_info[:2] != (3, 8), reason="We only bundle wheel for Python 3.8")
50+
@pytest.mark.parametrize("flag", ["--no-wheel", "--wheel=none", "--wheel=embed", "--wheel=bundle"])
51+
def test_wheel_cli_flags_dont_warn_on_38(tmp_path, flag, capsys):
52+
session_via_cli([flag, str(tmp_path)])
53+
out, err = capsys.readouterr()
54+
assert "The --no-wheel and --wheel options are deprecated." not in out + err
3555

3656

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

0 commit comments

Comments
 (0)