Skip to content

Commit 31e1c03

Browse files
committed
Use static notation for setuptools in installation test
The `VirtualEnvironment` test helper is used in multiple places, but it is only told to install/upgrade `pip` when used from `test_installation`. It implements the functionality it would ideally obtain by `upgrade_deps`, since the `upgrade_deps` parameter is only avaiilable in `venv` when using Python 3.9 and later. When `pip` is installed, `upgrade_deps` would install `setuptools` when using Python 3.11 or lower, but not when using Python 3.12 or higher. `VirtualEnvironment` does the same. (The reason for this is not just to avoid needlessly departing from what `upgrade_deps` would do. Rather, it should not generally be necessary to have `setuptools` installed for package management since Python 3.12, and if it were necessary then this would a bug we would want to detect while running tests.) Previously this conditional specification of `setuptools` was done by building different lists of package arguments to pass to `pip`, by checking `sys.version_info` to decide whether to append the string `setuptools`. This commit changes how it is done, to use a static list of package arguments instead. (The Python intepreter path continues to be obtained dynamically, but all its positional arguments, including those specifying packages, are now string literals.) The conditional `setuptools` requirement is now expressed statically using notation recognized by `pip`, as the string `setuptools; python_version<"3.12"`.
1 parent e337e99 commit 31e1c03

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

test/lib/helper.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -415,9 +415,15 @@ def __init__(self, env_dir, *, with_pip):
415415

416416
if with_pip:
417417
# The upgrade_deps parameter to venv.create is 3.9+ only, so do it this way.
418-
command = [self.python, "-m", "pip", "install", "--upgrade", "pip"]
419-
if sys.version_info < (3, 12):
420-
command.append("setuptools")
418+
command = [
419+
self.python,
420+
"-m",
421+
"pip",
422+
"install",
423+
"--upgrade",
424+
"pip",
425+
'setuptools; python_version<"3.12"',
426+
]
421427
subprocess.check_output(command)
422428

423429
@property

0 commit comments

Comments
 (0)