From 31e1c035e1af514d5d2a9ed6630f71663df7b265 Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Sat, 7 Jun 2025 15:01:21 -0400 Subject: [PATCH 1/2] 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"`. --- test/lib/helper.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/test/lib/helper.py b/test/lib/helper.py index 5d91447ea..241d27341 100644 --- a/test/lib/helper.py +++ b/test/lib/helper.py @@ -415,9 +415,15 @@ def __init__(self, env_dir, *, with_pip): if with_pip: # The upgrade_deps parameter to venv.create is 3.9+ only, so do it this way. - command = [self.python, "-m", "pip", "install", "--upgrade", "pip"] - if sys.version_info < (3, 12): - command.append("setuptools") + command = [ + self.python, + "-m", + "pip", + "install", + "--upgrade", + "pip", + 'setuptools; python_version<"3.12"', + ] subprocess.check_output(command) @property From 727f4e9e54362d0356066a26d0c22028a465cccd Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Sat, 7 Jun 2025 15:21:00 -0400 Subject: [PATCH 2/2] Use static notation for `setuptools` in CI `pip` commands `setuptools` may potentially be needed for installation to work fully as desired prior to Python 3.12, so in those versions it is installed automatically in any virtual environment that is created with `pip` available. This is a behavior of the `venv` module that is not specific to CI. However, on CI we upgrade packages that are preinstalled in the virtual environment, or that we may otherwise wish to be present. This took the form of unconditionally installing/upgrading the `pip` and `wheel` packages, but conditionally upgrading the `setuptools` package only if we find that it is already installed. This commit changes the behavior to statically specify the same list of package specifications to `pip` in all environments and in all versions of Python, but to use the static notation recognized by `pip` to indicate that `setuptools` is to be instaled/upgraded only if the Python version is strictly less than Python 3.12. This seems to be more readable. It also avoids using unquoted shell parameter expansion in a way that is potentially confusing (for example, if we were running our CI script steps through ShellCheck, then it would automatically balk at that construction). It is also more consistent with how `test_installation` sets up its environment (especially since 31e1c03, but actually even before that, because it was still conditioning `setuptools` on the Python version rather than whether it was already installed). Finally, this behavior is what the preexisting comment already described. This also adjusts the shell quoting style slightly in other related commands (in the same workflows) that pass package specifications to `pip`, for consistency. (For now, `".[test]"` rather than `.[test]` remains written in the readme because it works in `cmd.exe` as well as other shells, but it may be changed there in the future too.) --- .github/workflows/alpine-test.yml | 4 ++-- .github/workflows/cygwin-test.yml | 4 ++-- .github/workflows/pythonpackage.yml | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/alpine-test.yml b/.github/workflows/alpine-test.yml index 513c65bb8..a3361798d 100644 --- a/.github/workflows/alpine-test.yml +++ b/.github/workflows/alpine-test.yml @@ -55,12 +55,12 @@ jobs: run: | # Get the latest pip, wheel, and prior to Python 3.12, setuptools. . .venv/bin/activate - python -m pip install -U pip $(pip freeze --all | grep -ow ^setuptools) wheel + python -m pip install -U pip 'setuptools; python_version<"3.12"' wheel - name: Install project and test dependencies run: | . .venv/bin/activate - pip install ".[test]" + pip install '.[test]' - name: Show version and platform information run: | diff --git a/.github/workflows/cygwin-test.yml b/.github/workflows/cygwin-test.yml index 7c3eeedca..6943db09c 100644 --- a/.github/workflows/cygwin-test.yml +++ b/.github/workflows/cygwin-test.yml @@ -79,11 +79,11 @@ jobs: - name: Update PyPA packages run: | # Get the latest pip, wheel, and prior to Python 3.12, setuptools. - python -m pip install -U pip $(pip freeze --all | grep -ow ^setuptools) wheel + python -m pip install -U pip 'setuptools; python_version<"3.12"' wheel - name: Install project and test dependencies run: | - pip install ".[test]" + pip install '.[test]' - name: Show version and platform information run: | diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index e7cb06cc0..c56d45df7 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -72,11 +72,11 @@ jobs: - name: Update PyPA packages run: | # Get the latest pip, wheel, and prior to Python 3.12, setuptools. - python -m pip install -U pip $(pip freeze --all | grep -ow ^setuptools) wheel + python -m pip install -U pip 'setuptools; python_version<"3.12"' wheel - name: Install project and test dependencies run: | - pip install ".[test]" + pip install '.[test]' - name: Show version and platform information run: | @@ -114,5 +114,5 @@ jobs: - name: Documentation if: matrix.python-version != '3.7' run: | - pip install ".[doc]" + pip install '.[doc]' make -C doc html