Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use ruff and ruff format #2

Merged
merged 2 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@ on:
push:
branches:
- main
pull_request:

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8, 3.9, '3.10', '3.11', '3.12']
steps:
- uses: actions/checkout@master
- name: Setup Python
uses: actions/setup-python@v3
with:
python-version: '3.10'
- uses: pdm-project/setup-pdm@v3
name: Install PDM
with:
python-version: '3.10'
python-version: ${{ matrix.python-version }}
cache: 'true'
- name: Generate coverage report
run: |
pdm install
Expand Down
18 changes: 18 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
ci:
autoupdate_schedule: monthly
repos:

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 'v0.1.6'
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
hooks:
- id: mypy
exclude: ^doc/src/.*\.py$
additional_dependencies:
- pytest
14 changes: 7 additions & 7 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ pdm-build-locked: Publish locked dependencies
:alt: PyPI Downloads
:target: https://pypi.org/project/pdm-build-locked/

.. image:: https://img.shields.io/codecov/c/github/sigma67/pdm-build-locked?style=flat-square
.. image:: https://img.shields.io/codecov/c/github/pdm-project/pdm-build-locked?style=flat-square
:alt: Code coverage
:target: https://codecov.io/gh/sigma67/pdm-build-locked
:target: https://codecov.io/gh/pdm-project/pdm-build-locked

.. image:: https://img.shields.io/github/v/release/sigma67/pdm-build-locked?style=flat-square
.. image:: https://img.shields.io/github/v/release/pdm-project/pdm-build-locked?style=flat-square
:alt: Latest release
:target: https://github.com/sigma67/pdm-build-locked/releases/latest
:target: https://github.com/pdm-project/pdm-build-locked/releases/latest

.. image:: https://img.shields.io/github/commits-since/sigma67/pdm-build-locked/latest?style=flat-square
.. image:: https://img.shields.io/github/commits-since/pdm-project/pdm-build-locked/latest?style=flat-square
:alt: Commits since latest release
:target: https://github.com/sigma67/pdm-build-locked/commits
:target: https://github.com/pdm-project/pdm-build-locked/commits


pdm-build-locked is a pdm plugin to add locked packages as additional
optional dependency groups to the distribution metadata.

Documentation: https://pdm-build-locked.readthedocs.io
Documentation: https://pdm-build-locked.readthedocs.io
22 changes: 11 additions & 11 deletions doc/src/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
#
import os

on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
on_rtd = os.environ.get("READTHEDOCS", None) == "True"

# -- Project information -----------------------------------------------------

project = 'pdm-build-locked'
copyright = '2023, sigma67'
author = 'sigma67'
project = "pdm-build-locked"
copyright = "2023, sigma67"
author = "sigma67"

# -- General configuration ---------------------------------------------------

Expand All @@ -28,13 +28,13 @@
extensions = ["sphinx.ext.autodoc"]

# The suffix of source filenames.
source_suffix = '.rst'
source_suffix = ".rst"

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
Expand All @@ -51,11 +51,11 @@
# Default to the default alabaster theme if not.
try:
import sphinx_rtd_theme
html_theme = 'sphinx_rtd_theme'

html_theme = "sphinx_rtd_theme"
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
except ImportError:
html_theme = 'alabaster'
html_theme = "alabaster"
else:
# Set theme to 'default' for ReadTheDocs.
html_theme = 'default'

html_theme = "default"
1,188 changes: 536 additions & 652 deletions pdm.lock

Large diffs are not rendered by default.

60 changes: 19 additions & 41 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ classifiers = [
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11"
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]
authors = [
{name = "sigma67", email = "sigma67.github@gmail.com"},
{name = "Frost Ming", email = "me@frostming.com"},
]
dependencies = []
requires-python = ">=3.8"
Expand All @@ -45,52 +47,30 @@ package-dir = "src"
[tool.pdm.dev-dependencies]
dev = [
"pdm>=2.8.0",
"black>=23.7.0",
"isort>=5.12.0",
"pylint>=2.17.4",
"mypy>=1.4.1",
"pytest>=7.4.0",
"pkginfo>=1.9.6",
"pytest-cov>=4.1.0",
"click>=8.1.6",
"pre-commit>=3.5.0",
]

[tool.black]
## black code formatter settings
[tool.ruff]
line-length = 120


[tool.isort]
profile = "black"
src_paths = ["src", "tests"]


[tool.pylint]
## pylint linter settings
## see `pylint --generate-toml-config`
## justify single line via: # pylint: disable=<rule>

[tool.pylint.main]
ignore-paths = [
".git",
"__pypackages__",
# "tests" # enable/disable linting within tests directory
extend-select = [
"I", # isort
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"PGH", # pygrep-hooks
"RUF", # ruff
"W", # pycodestyle
"YTT", # flake8-2020
]
load-plugins = [
"pylint.extensions.docparams"
]
accept-no-param-doc="no"
accept-no-raise-doc="no"
accept-no-yields-doc="no"
default-docstring-type="google"

[tool.pylint.format]
max-line-length = 120
extend-ignore = ["B018", "B019"]
src = ["src"]
target-version = "py38"

[tool.pylint."messages control"]
disable = [
"fixme"
]
[tool.ruff.mccabe]
max-complexity = 10

[tool.mypy]
## mypy static typechecker settings
Expand All @@ -106,15 +86,13 @@ mypy_path = "src"
show_error_codes = true
strict = true # https://mypy.readthedocs.io/en/stable/config_file.html#confval-strict


[tool.pytest.ini_options]
testpaths = ["tests"]
addopts = "--verbose --cov --cov-report=term --cov-report=html --cov-report=xml --cov-config=pyproject.toml"


[tool.coverage.run]
branch = true
source = ["src"]

[tool.coverage.report]
show_missing = true
show_missing = true
19 changes: 10 additions & 9 deletions src/pdm_build_locked/command.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
"""pdm build --locked command"""
from __future__ import annotations

import argparse
import subprocess
from contextlib import suppress
from typing import Dict, List, Tuple, Union
from typing import Dict, List, Optional, Tuple, Union

from pdm.cli import actions
from pdm.cli.commands.build import Command as BaseCommand
Expand All @@ -17,13 +19,12 @@
DependencyList = Dict[str, Union[List[str], Dict[str, List[str]]]]

# copied from pdm.models.repository due to TYPECHECKING guard
CandidateKey = Tuple[str, Union[str, None], Union[str, None], bool]
CandidateKey = Tuple[str, Optional[str], Optional[str], bool]


class BuildCommand(BaseCommand):
class BuildCommand(BaseCommand): # type: ignore[misc]
"""subclasses pdm's build command and calls it via super()"""

description = BaseCommand.__doc__
name = "build"

def add_arguments(self, parser: argparse.ArgumentParser) -> None:
Expand All @@ -43,7 +44,7 @@ def handle(self, project: Project, options: argparse.Namespace) -> None:
if dev_dependencies := project.pyproject.settings.get("dev-dependencies"):
pdm_dev_dependencies = dev_dependencies.keys()

groups = set(group for group in project.all_dependencies.keys() if group not in pdm_dev_dependencies)
groups = {group for group in project.all_dependencies if group not in pdm_dev_dependencies}

locked_groups = [self._get_locked_group_name(group) for group in groups]
if duplicate_groups := groups.intersection(locked_groups):
Expand All @@ -58,7 +59,7 @@ def handle(self, project: Project, options: argparse.Namespace) -> None:
self._update_lockfile(project)

# retrieve locked dependencies and write to pyproject
optional_dependencies: Dict[str, List[str]] = {}
optional_dependencies: dict[str, list[str]] = {}

###############################
# determine locked dependencies
Expand Down Expand Up @@ -136,7 +137,7 @@ def _get_locked_group_name(group: str) -> str:
return group_name

@staticmethod
def _get_locked_packages(project: Project, group: str) -> List[str]:
def _get_locked_packages(project: Project, group: str) -> list[str]:
"""
Determine locked dependency strings for direct and transitive dependencies

Expand All @@ -147,7 +148,7 @@ def _get_locked_packages(project: Project, group: str) -> List[str]:
Returns:
Set of locked packages
"""
requirements: Dict[str, Requirement] = project.get_dependencies(group)
requirements: dict[str, Requirement] = project.get_dependencies(group)

# get a ReusePinProvider - we don't want any calls to the remote repository,
# we just want to read from the lockfile
Expand All @@ -162,7 +163,7 @@ def _get_locked_packages(project: Project, group: str) -> List[str]:
project.allow_prereleases,
{normalize_name(k): v for k, v in project.pyproject.resolution_overrides.items()},
)
resolver = project.core.resolver_class(provider, BaseReporter()) # type: ignore
resolver = project.core.resolver_class(provider, BaseReporter())
reqs = list(requirements.values())
candidates, *_ = resolve(resolver, reqs, project.environment.python_requires)

Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ def invoke() -> Callable[..., Result]:
runner = CliRunner(mix_stderr=False)

def caller(args: Any) -> Result:
return runner.invoke(Core(), args, prog_name="pdm", catch_exceptions=False) # type: ignore[arg-type]
return runner.invoke(Core(), args, prog_name="pdm", catch_exceptions=False)

return caller