Skip to content

Commit

Permalink
fix issue #13 (#14)
Browse files Browse the repository at this point in the history
* fix issue #13

* add linters

* fix for buggy pdm remove empty tables

* test omit

* ignore coverage strangeness

* use mypy 3.10

* update mypy action
  • Loading branch information
sigma67 authored Jun 14, 2024
1 parent dda9492 commit d025c55
Show file tree
Hide file tree
Showing 11 changed files with 743 additions and 518 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
run: |
pdm install
pdm run pytest
pdm run coverage xml
pdm run coverage xml -i
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
Expand Down
33 changes: 33 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: lint

on:
pull_request:
branches:
- main
paths:
- src/**
- tests/**

jobs:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: chartboost/ruff-action@v1
with:
version: 0.4.8
- uses: chartboost/ruff-action@v1
with:
version: 0.4.8
args: format --check
mypy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.10"
- uses: pdm-project/setup-pdm@v3
name: Install PDM
- run: pdm install
- run: pdm run mypy --install-types --non-interactive
14 changes: 14 additions & 0 deletions .github/workflows/pdm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Update dependencies

on:
schedule:
- cron: "5 3 * * 1"

jobs:
update-dependencies:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Update dependencies
uses: pdm-project/update-deps-action@main
1 change: 1 addition & 0 deletions doc/src/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#
import os
from datetime import date

import tomli

on_rtd = os.environ.get("READTHEDOCS", None) == "True"
Expand Down
1,166 changes: 663 additions & 503 deletions pdm.lock

Large diffs are not rendered by default.

17 changes: 11 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ dev = [
"pdm-backend>=2.1.7",
"hatchling>=1.20.0",
"build>=1.0.3",
"ruff>=0.4.8",
"mypy>=1.10.0"
]
doc = [
"sphinx>=7.1.2",
Expand All @@ -71,6 +73,10 @@ doc = [

[tool.ruff]
line-length = 120
src = ["src"]
target-version = "py38"

[tool.ruff.lint]
extend-select = [
"I", # isort
"B", # flake8-bugbear
Expand All @@ -81,11 +87,7 @@ extend-select = [
"YTT", # flake8-2020
]
extend-ignore = ["B018", "B019"]
src = ["src"]
target-version = "py38"

[tool.ruff.mccabe]
max-complexity = 10
mccabe.max-complexity = 10

[tool.mypy]
## mypy static typechecker settings
Expand All @@ -99,6 +101,9 @@ files = [
]
mypy_path = "src"
show_error_codes = true
exclude = [
"tests/data"
]

[tool.pytest.ini_options]
testpaths = ["tests"]
Expand All @@ -107,7 +112,7 @@ addopts = "--verbose --cov --cov-report=term --cov-report=html --cov-report=xml
[tool.coverage.run]
branch = true
source = ["src"]
omit = ["backend.py", "hatchling.py"]
omit = ["backend.py", "hatchling.py", "/tmp"]

[tool.coverage.report]
show_missing = true
3 changes: 2 additions & 1 deletion src/pdm_build_locked/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import sys
import warnings
from collections.abc import MutableMapping
from pathlib import Path
from typing import Any

Expand Down Expand Up @@ -66,7 +67,7 @@ def get_locked_group_name(group: str) -> str:
return group_name


def update_metadata_with_locked(metadata: dict[str, Any], root: Path) -> None: # pragma: no cover
def update_metadata_with_locked(metadata: MutableMapping[str, Any], root: Path) -> None: # pragma: no cover
"""Inplace update the metadata(pyproject.toml) with the locked dependencies.
Args:
Expand Down
18 changes: 13 additions & 5 deletions src/pdm_build_locked/command.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""pdm build --locked command"""

from __future__ import annotations

import argparse
Expand All @@ -13,7 +14,7 @@
from pdm.exceptions import PdmException
from pdm.project.core import Project
from pdm.resolver import resolve
from resolvelib import BaseReporter
from resolvelib import BaseReporter, Resolver

from ._utils import get_locked_group_name

Expand Down Expand Up @@ -76,12 +77,14 @@ def handle(self, project: Project, options: argparse.Namespace) -> None:

# write to pyproject
# get reference to optional-dependencies in project.pyproject, or create it if it doesn't exist
optional = project.pyproject.metadata.get(
"optional-dependencies", None
) or project.pyproject.metadata.setdefault("optional-dependencies", {})
optional_key = "optional-dependencies"
optional = project.pyproject.metadata.get(optional_key, None) or project.pyproject.metadata.setdefault(
optional_key, {}
)

# update target
optional.update(optional_dependencies)
project.pyproject.metadata[optional_key] = optional
project.pyproject.write(show_message=False)

# to prevent unclean scm status, we need to ignore pyproject.toml during build
Expand All @@ -95,6 +98,11 @@ def handle(self, project: Project, options: argparse.Namespace) -> None:
for group in locked_groups:
with suppress(KeyError):
project.pyproject.metadata.get("optional-dependencies", {}).pop(group)
if not project.pyproject.settings:
del project.pyproject._data["tool"]["pdm"] # type: ignore[union-attr]
if not project.pyproject._data["tool"]:
del project.pyproject._data["tool"]

project.pyproject.write(show_message=False)
self._git_ignore_pyproject(project, False)

Expand Down Expand Up @@ -137,7 +145,7 @@ def _get_locked_packages(project: Project, group: str) -> list[str]:
# 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 = project.core.resolver_class(provider, BaseReporter())
resolver: Resolver = project.core.resolver_class(provider, BaseReporter())
candidates, *_ = resolve(
resolver,
requirements,
Expand Down
5 changes: 3 additions & 2 deletions src/pdm_build_locked/plugin.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""
pdm-build-locked
pdm-build-locked
A PDM plugin that adds locked dependencies to optional-dependencies on build
A PDM plugin that adds locked dependencies to optional-dependencies on build
"""

from pdm.core import Core

from .command import BuildCommand
Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""conftest"""

import shutil
from pathlib import Path
from typing import Generator
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_build_command.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""test pdm build --locked"""

from __future__ import annotations

from pathlib import Path
Expand Down

0 comments on commit d025c55

Please sign in to comment.