Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test suite support for Python 3.12 #12127

Merged
merged 10 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ jobs:
- run: git diff --exit-code

tests-unix:
name: tests / ${{ matrix.python }} / ${{ matrix.os }}
name: tests / ${{ matrix.python.key || matrix.python }} / ${{ matrix.os }}
runs-on: ${{ matrix.os }}-latest

needs: [packaging, determine-changes]
Expand All @@ -109,12 +109,14 @@ jobs:
- "3.9"
- "3.10"
- "3.11"
- key: "3.12"
full: "3.12.0-dev"
uranusjr marked this conversation as resolved.
Show resolved Hide resolved

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
python-version: ${{ matrix.python.full || matrix.python }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use allow-prereleases: true if you don't care about the specific beta version to test.

c.f. https://github.com/actions/setup-python/blob/main/docs/advanced-usage.md#allow-pre-releases

Copy link
Member

@pradyunsg pradyunsg Jul 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
python-version: ${{ matrix.python.full || matrix.python }}
python-version: ${{ matrix.python }}-dev

This will gracefully move to using stable releases, once they are out.

Use -dev instead of a patch number (e.g., 3.12-dev) to install the latest patch version release for a given minor version, alpha and beta releases included.

Copy link
Member Author

@uranusjr uranusjr Jul 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both these solutions would cause prereleases for other versions to be picked up. I’m not sure I’m on board with that. I changed to full key to use -dev instead of -beta.3.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both these solutions would cause prereleases for other versions to be picked up.

They won't have any though?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will they not? I am not familiar with how GitHub publishes versions, but Python bug fixes do have prereleases officially.


- name: Install Ubuntu dependencies
if: matrix.os == 'Ubuntu'
Expand All @@ -129,12 +131,12 @@ jobs:
# Main check
- name: Run unit tests
run: >-
nox -s test-${{ matrix.python }} --
nox -s test-${{ matrix.python.key || matrix.python }} --
-m unit
--verbose --numprocesses auto --showlocals
- name: Run integration tests
run: >-
nox -s test-${{ matrix.python }} --
nox -s test-${{ matrix.python.key || matrix.python }} --
-m integration
--verbose --numprocesses auto --showlocals
--durations=5
Expand Down
2 changes: 1 addition & 1 deletion docs/html/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ $ pip install --upgrade pip
The current version of pip works on:

- Windows, Linux and MacOS.
- CPython 3.7, 3.8, 3.9, 3.10 and latest PyPy3.
- CPython 3.7, 3.8, 3.9, 3.10, 3.11, 3.12, and latest PyPy3.

pip is tested to work on the latest patch version of the Python interpreter,
for each of the minor versions listed above. Previous patch versions are
Expand Down
4 changes: 3 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def should_update_common_wheels() -> bool:
# -----------------------------------------------------------------------------
# Development Commands
# -----------------------------------------------------------------------------
@nox.session(python=["3.7", "3.8", "3.9", "3.10", "3.11", "pypy3"])
@nox.session(python=["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "pypy3"])
def test(session: nox.Session) -> None:
# Get the common wheels.
if should_update_common_wheels():
Expand All @@ -89,6 +89,7 @@ def test(session: nox.Session) -> None:
shutil.rmtree(sdist_dir, ignore_errors=True)

# fmt: off
session.install("setuptools")
session.run(
"python", "setup.py", "sdist", "--formats=zip", "--dist-dir", sdist_dir,
silent=True,
Expand Down Expand Up @@ -351,6 +352,7 @@ def build_dists(session: nox.Session) -> List[str]:
)

session.log("# Build distributions")
session.install("setuptools", "wheel")
session.run("python", "setup.py", "sdist", "bdist_wheel", silent=True)
produced_dists = glob.glob("dist/*")

Expand Down
9 changes: 7 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
if TYPE_CHECKING:
from typing import Protocol

from wsgi import WSGIApplication
from _typeshed.wsgi import WSGIApplication
else:
# TODO: Protocol was introduced in Python 3.8. Remove this branch when
# dropping support for Python 3.7.
Expand Down Expand Up @@ -645,7 +645,12 @@ def pip(self, *args: Union[str, Path]) -> InMemoryPipResult:
try:
returncode = pip_entry_point([os.fspath(a) for a in args])
except SystemExit as e:
returncode = e.code or 0
if isinstance(e.code, int):
returncode = e.code
elif e.code:
returncode = 1
else:
returncode = 0
finally:
sys.stdout = orig_stdout
return InMemoryPipResult(returncode, stdout.getvalue())
Expand Down
41 changes: 29 additions & 12 deletions tests/functional/test_build_env.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import sys
from textwrap import dedent
from typing import Optional

Expand Down Expand Up @@ -203,6 +204,31 @@ def test_build_env_overlay_prefix_has_priority(script: PipTestEnvironment) -> No
assert result.stdout.strip() == "2.0", str(result)


if sys.version_info < (3, 12):
BUILD_ENV_ERROR_DEBUG_CODE = r"""
from distutils.sysconfig import get_python_lib
print(
f'imported `pkg` from `{pkg.__file__}`',
file=sys.stderr)
print('system sites:\n ' + '\n '.join(sorted({
get_python_lib(plat_specific=0),
get_python_lib(plat_specific=1),
})), file=sys.stderr)
"""
else:
BUILD_ENV_ERROR_DEBUG_CODE = r"""
from sysconfig import get_paths
paths = get_paths()
print(
f'imported `pkg` from `{pkg.__file__}`',
file=sys.stderr)
print('system sites:\n ' + '\n '.join(sorted({
paths['platlib'],
paths['purelib'],
})), file=sys.stderr)
"""


@pytest.mark.usefixtures("enable_user_site")
def test_build_env_isolation(script: PipTestEnvironment) -> None:
# Create dummy `pkg` wheel.
Expand Down Expand Up @@ -231,26 +257,17 @@ def test_build_env_isolation(script: PipTestEnvironment) -> None:
run_with_build_env(
script,
"",
r"""
from distutils.sysconfig import get_python_lib
f"""
import sys

try:
import pkg
except ImportError:
pass
else:
print(
f'imported `pkg` from `{pkg.__file__}`',
file=sys.stderr)
print('system sites:\n ' + '\n '.join(sorted({
get_python_lib(plat_specific=0),
get_python_lib(plat_specific=1),
})), file=sys.stderr)
print('sys.path:\n ' + '\n '.join(sys.path), file=sys.stderr)
{BUILD_ENV_ERROR_DEBUG_CODE}
print('sys.path:\\n ' + '\\n '.join(sys.path), file=sys.stderr)
sys.exit(1)
"""
f"""
# second check: direct check of exclusion of system site packages
import os

Expand Down
20 changes: 15 additions & 5 deletions tests/functional/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -848,14 +848,18 @@ def test_editable_install__local_dir_no_setup_py(
)


@pytest.mark.skipif(
sys.version_info >= (3, 12),
reason="Setuptools<64 does not support Python 3.12+",
)
@pytest.mark.network
def test_editable_install__local_dir_no_setup_py_with_pyproject(
def test_editable_install_legacy__local_dir_no_setup_py_with_pyproject(
script: PipTestEnvironment,
) -> None:
"""
Test installing in editable mode from a local directory with no setup.py
but that does have pyproject.toml with a build backend that does not support
the build_editable hook.
Test installing in legacy editable mode from a local directory with no
setup.py but that does have pyproject.toml with a build backend that does
not support the build_editable hook.
"""
local_dir = script.scratch_path.joinpath("temp")
local_dir.mkdir()
Expand Down Expand Up @@ -1383,8 +1387,14 @@ def test_install_editable_with_prefix_setup_py(script: PipTestEnvironment) -> No
_test_install_editable_with_prefix(script, {"setup.py": setup_py})


@pytest.mark.skipif(
sys.version_info >= (3, 12),
reason="Setuptools<64 does not support Python 3.12+",
)
@pytest.mark.network
def test_install_editable_with_prefix_setup_cfg(script: PipTestEnvironment) -> None:
def test_install_editable_legacy_with_prefix_setup_cfg(
script: PipTestEnvironment,
) -> None:
setup_cfg = """[metadata]
name = pkga
version = 0.1
Expand Down
20 changes: 20 additions & 0 deletions tests/functional/test_uninstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ def test_basic_uninstall(script: PipTestEnvironment) -> None:
assert_all_changes(result, result2, [script.venv / "build", "cache"])


@pytest.mark.skipif(
sys.version_info >= (3, 12),
reason="distutils is no longer available in Python 3.12+",
)
def test_basic_uninstall_distutils(script: PipTestEnvironment) -> None:
"""
Test basic install and uninstall.
Expand Down Expand Up @@ -68,6 +72,10 @@ def test_basic_uninstall_distutils(script: PipTestEnvironment) -> None:
) in result.stderr


@pytest.mark.skipif(
sys.version_info >= (3, 12),
reason="Setuptools<64 does not support Python 3.12+",
)
@pytest.mark.network
def test_basic_uninstall_with_scripts(script: PipTestEnvironment) -> None:
"""
Expand Down Expand Up @@ -101,6 +109,10 @@ def test_uninstall_invalid_parameter(
assert expected_message in result.stderr


@pytest.mark.skipif(
sys.version_info >= (3, 12),
reason="Setuptools<64 does not support Python 3.12+",
)
@pytest.mark.network
def test_uninstall_easy_install_after_import(script: PipTestEnvironment) -> None:
"""
Expand All @@ -126,6 +138,10 @@ def test_uninstall_easy_install_after_import(script: PipTestEnvironment) -> None
)


@pytest.mark.skipif(
sys.version_info >= (3, 12),
reason="Setuptools<64 does not support Python 3.12+",
)
@pytest.mark.network
def test_uninstall_trailing_newline(script: PipTestEnvironment) -> None:
"""
Expand Down Expand Up @@ -337,6 +353,10 @@ def test_uninstall_console_scripts_uppercase_name(script: PipTestEnvironment) ->
assert not script_name.exists()


@pytest.mark.skipif(
sys.version_info >= (3, 12),
reason="Setuptools<64 does not support Python 3.12+",
)
@pytest.mark.network
def test_uninstall_easy_installed_console_scripts(script: PipTestEnvironment) -> None:
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def _create(self, clear: bool = False) -> None:
)
elif self._venv_type == "venv":
builder = _venv.EnvBuilder()
context = builder.ensure_directories(self.location)
context = builder.ensure_directories(os.fspath(self.location))
builder.create_configuration(context)
builder.setup_python(context)
self.site.mkdir(parents=True, exist_ok=True)
Expand Down