From 8e7260968acf55ccf3ac0a3c94c3a7f385773229 Mon Sep 17 00:00:00 2001 From: Frost Ming Date: Wed, 23 Feb 2022 17:19:27 +0800 Subject: [PATCH] Support prereleases in python requires --- .github/workflows/ci.yml | 12 ++++++++++++ pdm.lock | 8 ++++---- pdm/models/specifiers.py | 14 ++++++++++++++ pdm/project/core.py | 2 +- 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ba72aa5bb5..2105ae0c82 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,10 +29,16 @@ jobs: python-version: [3.7, 3.8, 3.9, "3.10", "3.11.0-alpha - 3.11.0"] os: [ubuntu-latest, windows-latest, macos-latest] install-via: [pip] + arch: [x64] include: - python-version: 3.9 os: ubuntu-latest install-via: script + arch: x64 + - python-version: 3.9 + os: windows-latest + install-via: pip + arch: x86 continue-on-error: ${{ startsWith(matrix.python-version, '3.11') }} steps: - uses: actions/checkout@v2 @@ -42,29 +48,35 @@ jobs: uses: actions/setup-python@v2 with: python-version: 2.7 + architecture: ${{ matrix.arch }} - name: Set Python 3.6 uses: actions/setup-python@v2 with: python-version: 3.6 + architecture: ${{ matrix.arch }} - name: Set Python 3.7 uses: actions/setup-python@v2 if: matrix.python-version != '3.7' with: python-version: 3.7 + architecture: ${{ matrix.arch }} - name: Set Python 3.8 uses: actions/setup-python@v2 if: matrix.python-version != '3.8' with: python-version: 3.8 + architecture: ${{ matrix.arch }} - name: Set Python 3.9 uses: actions/setup-python@v2 if: matrix.python-version != '3.9' with: python-version: 3.9 + architecture: ${{ matrix.arch }} - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} + architecture: ${{ matrix.arch }} - name: Set Variables id: set_variables run: | diff --git a/pdm.lock b/pdm.lock index eba2bbff9d..8f97732190 100644 --- a/pdm.lock +++ b/pdm.lock @@ -99,7 +99,7 @@ summary = "execnet: rapid multi-Python deployment" [[package]] name = "findpython" -version = "0.1.2" +version = "0.1.3" requires_python = ">=3.7" summary = "A utility to find python versions on your system" dependencies = [ @@ -716,9 +716,9 @@ content_hash = "sha256:10013526fea19dec4436180b0eb53cb826f87db9c52540aab6a8dc7cd {file = "execnet-1.9.0-py2.py3-none-any.whl", hash = "sha256:a295f7cc774947aac58dde7fdc85f4aa00c42adf5d8f5468fc630c1acf30a142"}, {file = "execnet-1.9.0.tar.gz", hash = "sha256:8f694f3ba9cc92cab508b152dcfe322153975c29bda272e2fd7f3f00f36e47c5"}, ] -"findpython 0.1.2" = [ - {file = "findpython-0.1.2-py3-none-any.whl", hash = "sha256:973666f27f67bc2a3c1a2c2df2acafe4f890a5255cea023b2a68823bb9520a6e"}, - {file = "findpython-0.1.2.tar.gz", hash = "sha256:2eebd61f5e50ac6a74ed7773cf41f23cd80be402ca94556001cff27d3948bbd2"}, +"findpython 0.1.3" = [ + {file = "findpython-0.1.3-py3-none-any.whl", hash = "sha256:ec64268d4120173bf713761ae15335c811102debfd1c96d2ef782b85c2380a26"}, + {file = "findpython-0.1.3.tar.gz", hash = "sha256:b55a416b9fcf2d28721bfbea1ceb2a6cb67a00f99ec4b94a76da22c7a2002870"}, ] "ghp-import 2.0.2" = [ {file = "ghp_import-2.0.2-py3-none-any.whl", hash = "sha256:5f8962b30b20652cdffa9c5a9812f7de6bcb56ec475acac579807719bf242c46"}, diff --git a/pdm/models/specifiers.py b/pdm/models/specifiers.py index 458a8e5243..04d591fc25 100644 --- a/pdm/models/specifiers.py +++ b/pdm/models/specifiers.py @@ -5,6 +5,7 @@ from pathlib import Path from typing import Any, Iterable, List, Set, Tuple, Union, cast +from packaging.version import Version as PackageVersion from pip._vendor.packaging.specifiers import SpecifierSet from pdm.exceptions import InvalidPyVersion @@ -99,6 +100,19 @@ def _analyze_specifiers(self) -> None: raise InvalidPyVersion(f"Unsupported version specifier: {op}{version}") self._rearrange(lower_bound, upper_bound, excludes) + @classmethod + def equal_to(cls, version: PackageVersion) -> "PySpecSet": + """Create a specifierset that is equal to the given version.""" + if not version.is_prerelease: + return cls(f"=={version}") + spec = cls(f"=={version}", analyze=False) + spec._upper_bound = Version((version.major, version.minor, 0)) + lower_bound = Version((version.major, version.minor - 1)) + spec._lower_bound = lower_bound.complete( + cls.PY_MAX_MINOR_VERSION[lower_bound] + 1 + ) + return spec + @classmethod def _merge_bounds_and_excludes( cls, diff --git a/pdm/project/core.py b/pdm/project/core.py index 191b0eba22..5fc6bf1af9 100644 --- a/pdm/project/core.py +++ b/pdm/project/core.py @@ -209,7 +209,7 @@ def get_environment(self) -> Environment: env = GlobalEnvironment(self) # Rewrite global project's python requires to be # compatible with the exact version - env.python_requires = PySpecSet(f"=={self.python.version}") + env.python_requires = PySpecSet.equal_to(self.python.version) return env if self.config["python.use_venv"] and get_venv_like_prefix( self.python.executable