Skip to content

Commit

Permalink
Support prereleases in python requires
Browse files Browse the repository at this point in the history
  • Loading branch information
frostming committed Feb 23, 2022
1 parent 2447a5e commit 8e72609
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: |
Expand Down
8 changes: 4 additions & 4 deletions pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions pdm/models/specifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion pdm/project/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8e72609

Please sign in to comment.