beeware / briefcase

Tools to support converting a Python project into a standalone native application.
https://briefcase.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
2.69k stars 375 forks source link

Requires-python checks don't work with pre-release Python versions #2034

Closed freakboy3742 closed 1 month ago

freakboy3742 commented 1 month ago

Describe the bug

2029 added support for PEP 621 requires-python declarations. However, these version checks appear to always fail if the Python version is a prerelease.

Steps to reproduce

  1. Use a prerelease Python (e.g. 3.13.0.rc2, or 3.14.0a1)
  2. Run the Briefcase test suite.

In this CI run, using Python 3.14.0a1, there are 4 test failures:

=========================== short test summary info ============================
FAILED tests/commands/base/test_verify_requires_python.py::test_requires_python_met[!= 3.2] - briefcase.exceptions.UnsupportedPythonVersion: Unable to run Briefcase command. The project configuration requires Python versions != 3.2, but the environment's Python version is 3.14.0a0. Please run Briefcase using a Python version that satisfies the project's requirements.
FAILED tests/commands/base/test_verify_requires_python.py::test_requires_python_met[>= 3.2] - briefcase.exceptions.UnsupportedPythonVersion: Unable to run Briefcase command. The project configuration requires Python versions >= 3.2, but the environment's Python version is 3.14.0a0. Please run Briefcase using a Python version that satisfies the project's requirements.
FAILED tests/commands/base/test_verify_requires_python.py::test_requires_python_met[> 3.2] - briefcase.exceptions.UnsupportedPythonVersion: Unable to run Briefcase command. The project configuration requires Python versions > 3.2, but the environment's Python version is 3.14.0a0. Please run Briefcase using a Python version that satisfies the project's requirements.
FAILED tests/commands/base/test_verify_requires_python.py::test_requires_python_met[< 3.100] - briefcase.exceptions.UnsupportedPythonVersion: Unable to run Briefcase command. The project configuration requires Python versions < 3.100, but the environment's Python version is 3.14.0a0. Please run Briefcase using a Python version that satisfies the project's requirements.

Expected behavior

3.14.0a1 should pass requires-python checks that require !=3.2, >3.2, and <3.100.

Screenshots

No response

Environment

Logs

Additional context

This came up in the context of trying to add Python 3.14 to Briefcase's CI matrix.

freakboy3742 commented 1 month ago

Tagging @sarayourfriend since you were working on this recently; no obligation to look into it, but if you've got the interest and spare cycles.

sarayourfriend commented 1 month ago

Interesting! I think it will be an easy fix by passing preeleases=True to spec.contains. I'll try that out and open a PR here shortly if it works.

sarayourfriend commented 1 month ago

I'll drop a note here to the PyPA docs on pre-release handling in version specifiers, because the defaults/intentions here were new to me: https://packaging.python.org/en/latest/specifications/version-specifiers/#handling-of-pre-releases

It's somewhat different for Briefcase's requires-python check because it isn't trying to resolve a particular version of a dependency, rather just checking that the active one matches the specifier. In that case, "accept already installed pre-releases for all version specifiers" from the set of default behaviours makes sense to follow.