Skip to content

Commit

Permalink
2.17 compatibility (#18)
Browse files Browse the repository at this point in the history
* fix 2.17 deprecationwarnings

* Dropped pdm <2.11 compat, added pdm>=2.17 compat

* fix test

* add compatibility note to docs

* cross-python fix for pdm 2.17

* update actions

* fix test pyproject

* update pre-commit-config

* test on 3.13

* disable 3.13 again due to error

---------

Co-authored-by: bputz <benedikt.putz@vector.com>
  • Loading branch information
sigma67 and vibpz authored Jul 21, 2024
1 parent fa2d929 commit 4334c8a
Show file tree
Hide file tree
Showing 10 changed files with 742 additions and 830 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8, 3.9, '3.10', '3.11', '3.12']
python-version: [3.8, 3.9, 3.10, 3.11, 3.12]
steps:
- uses: actions/checkout@master
- uses: pdm-project/setup-pdm@v3
- uses: pdm-project/setup-pdm@v4
name: Install PDM
with:
python-version: ${{ matrix.python-version }}
cache: 'true'
cache: true
- name: Generate coverage report
run: |
pdm install
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docsbuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v3
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ jobs:
- uses: actions/checkout@v4
- uses: chartboost/ruff-action@v1
with:
version: 0.4.8
version: 0.5.4
- uses: chartboost/ruff-action@v1
with:
version: 0.4.8
version: 0.5.4
args: format --check
mypy:
runs-on: ubuntu-latest
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ ci:
repos:

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 'v0.1.6'
rev: 'v0.5.4'
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix, --show-fixes]
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.7.1
rev: v1.11.0
hooks:
- id: mypy
exclude: ^(doc/src/.*\.py|tests/data/.*\.py)$
Expand Down
2 changes: 2 additions & 0 deletions doc/src/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ pdm-build-locked is a pdm plugin to enabling reproducible installs of Python CLI

It achieves this by adding the pinned packages from PDM's lockfile as additional optional dependency groups to the distribution metadata.

Compatible with ``pdm>=2.11``.


.. toctree::
:maxdepth: 2
Expand Down
535 changes: 227 additions & 308 deletions pdm.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ package-dir = "src"

[tool.pdm.dev-dependencies]
dev = [
"pdm[pytest]>=2.8.0",
"pdm[pytest]>=2.17.0",
"pytest>=7.4.0",
"pkginfo>=1.9.6",
"pytest-cov>=4.1.0",
Expand Down
29 changes: 14 additions & 15 deletions src/pdm_build_locked/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
import os
import subprocess
from contextlib import suppress
from importlib import import_module
from typing import Dict, List, Optional, Tuple, Union

from pdm.cli import actions
from pdm.cli.commands.build import Command as BaseCommand
from pdm.exceptions import PdmException
from pdm.project.core import Project
from pdm.resolver import resolve
from resolvelib import BaseReporter, Resolver

from ._utils import get_locked_group_name

Expand Down Expand Up @@ -141,21 +140,21 @@ def _get_locked_packages(project: Project, group: str) -> list[str]:
from pdm.cli.actions import resolve_candidates_from_lockfile

supported_params = inspect.signature(resolve_candidates_from_lockfile).parameters
requirements = list(project.get_dependencies(group).values())
if "cross_platform" in supported_params:
if "env_spec" in supported_params:
# pdm 2.17.0+
requirements = list(project.get_dependencies(group))
markers = import_module("pdm.models.markers")
# use lowest supported specifier to include all deps - we don't know the target Python at build time
env_spec = markers.EnvSpec.from_spec(">=3.8")
candidates = resolve_candidates_from_lockfile(
project, requirements, cross_platform=True, groups=[group], env_spec=env_spec
)
elif "cross_platform" in supported_params:
# pdm 2.11.0+
requirements = list(project.get_dependencies(group).values()) # type: ignore[attr-defined]
candidates = resolve_candidates_from_lockfile(project, requirements, cross_platform=True, groups=[group])
else: # pragma: no cover
# for older PDM versions, adjust resolve_candidates_from_lockfile with cross_platform=True
provider = project.get_provider(for_install=True)
provider.repository.ignore_compatibility = True
resolver: Resolver = project.core.resolver_class(provider, BaseReporter())
candidates, *_ = resolve(
resolver,
requirements,
project.environment.python_requires,
max_rounds=int(project.config["strategy.resolve_max_rounds"]),
)
else:
raise PdmException("Unsupported pdm version. pdm>=2.11 is required")

return [str(c.req.as_pinned_version(c.version)) for c in candidates.values()]

Expand Down
Loading

0 comments on commit 4334c8a

Please sign in to comment.