Skip to content

Commit

Permalink
Add ruff (#81)
Browse files Browse the repository at this point in the history
Signed-off-by: Bernát Gábor <bgabor8@bloomberg.net>
  • Loading branch information
gaborbernat authored Jun 14, 2023
1 parent 54e96b0 commit d14728a
Show file tree
Hide file tree
Showing 21 changed files with 228 additions and 250 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ jobs:
- "3.8"
- "3.7"
os:
- ubuntu-22.04
- windows-2022
- macos-12
- ubuntu-latest
- windows-latest
- macos-latest
steps:
- name: Setup python for tox
uses: actions/setup-python@v4
Expand Down Expand Up @@ -71,10 +71,10 @@ jobs:
- docs
- pkg_meta
os:
- ubuntu-22.04
- windows-2022
- ubuntu-latest
- windows-latest
exclude:
- { os: windows-2022, tox_env: pkg_meta }
- { os: windows-latest, tox_env: pkg_meta }
steps:
- uses: actions/checkout@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:

jobs:
release:
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
environment:
name: release
url: https://pypi.org/p/pyproject-api
Expand Down
12 changes: 0 additions & 12 deletions .markdownlint.yaml

This file was deleted.

67 changes: 18 additions & 49 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,74 +2,43 @@ repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-ast
- id: check-builtin-literals
- id: check-docstring-first
- id: check-merge-conflict
- id: check-yaml
- id: check-toml
- id: debug-statements
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/asottile/pyupgrade
rev: v3.3.2
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.0.272"
hooks:
- id: pyupgrade
args: ["--py37-plus"]
exclude: "^(src/pyproject_api/_backend.py|tests/demo_pkg_inline/build.py)$"
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
- id: ruff
exclude: src/pyproject_api/_backend.py
args: [--fix, --exit-non-zero-on-fix]
- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black
args: [--safe]
- repo: https://github.com/asottile/blacken-docs
rev: 1.13.0
hooks:
- id: blacken-docs
additional_dependencies: [black==23.3]
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: rst-backticks
- repo: https://github.com/tox-dev/tox-ini-fmt
rev: "1.3.0"
hooks:
- id: tox-ini-fmt
args: ["-p", "fix"]
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
- repo: https://github.com/tox-dev/pyproject-fmt
rev: "0.11.2"
hooks:
- id: flake8
additional_dependencies:
- flake8-bugbear==23.3.23
- flake8-comprehensions==3.12
- flake8-pytest-style==1.7.2
- flake8-spellcheck==0.28
- flake8-unused-arguments==0.0.13
- flake8-noqa==1.3.1
- pep8-naming==0.13.3
- flake8-pyproject==1.2.3
- id: pyproject-fmt
additional_dependencies: ["tox>=4.6"]
- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v2.7.1"
rev: "v3.0.0-alpha.9-for-vscode"
hooks:
- id: prettier
additional_dependencies:
- prettier@2.7.1
- "@prettier/plugin-xml@2.2"
args: ["--print-width=120", "--prose-wrap=always"]
- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.33.0
- repo: https://github.com/asottile/blacken-docs
rev: 1.14.0
hooks:
- id: blacken-docs
additional_dependencies: [black==23.3]
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: markdownlint
- id: rst-backticks
- repo: meta
hooks:
- id: check-hooks-apply
- id: check-useless-excludes
- repo: https://github.com/tox-dev/pyproject-fmt
rev: "0.10.0"
hooks:
- id: pyproject-fmt
3 changes: 2 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# noqa: D100
from __future__ import annotations

from pyproject_api import __version__

project = name = "pyproject_api"
company = "tox-dev"
copyright = f"{company}"
copyright = f"{company}" # noqa: A001
version, release = __version__, __version__.split("+")[0]

extensions = [
Expand Down
54 changes: 35 additions & 19 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
build-backend = "hatchling.build"
requires = [
"hatch-vcs>=0.3",
"hatchling>=1.14.1",
"hatchling>=1.17.1",
]

[project]
Expand All @@ -28,6 +28,13 @@ classifiers = [
"Operating System :: MacOS :: MacOS X",
"Operating System :: Microsoft :: Windows",
"Operating System :: POSIX",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Software Development :: Libraries",
"Topic :: Software Development :: Testing",
"Topic :: Utilities",
Expand All @@ -40,17 +47,17 @@ dependencies = [
'tomli>=2.0.1; python_version < "3.11"',
]
optional-dependencies.docs = [
"furo>=2023.3.27",
"sphinx>=6.2.1",
"furo>=2023.5.20",
"sphinx>=7.0.1",
"sphinx-autodoc-typehints!=1.23.4,>=1.23",
]
optional-dependencies.testing = [
"covdefaults>=2.3",
'importlib-metadata>=6.6; python_version < "3.8"',
"pytest>=7.3.1",
"pytest-cov>=4",
"pytest-cov>=4.1",
"pytest-mock>=3.10",
"setuptools>=67.7.2",
"setuptools>=67.8",
"wheel>=0.40",
]
urls.Homepage = "http://pyproject_api.readthedocs.org"
Expand All @@ -64,18 +71,6 @@ version.source = "vcs"
[tool.black]
line-length = 120

[tool.isort]
known_first_party = ["pyproject_api"]
profile = "black"
line_length = 120

[tool.flake8]
max-complexity = 22
max-line-length = 120
unused-arguments-ignore-abstract-functions = true
noqa-require-code = true
dictionaries = ["en_US", "python", "technical", "django"]

[tool.coverage]
html.show_contexts = true
html.skip_covered = false
Expand All @@ -98,5 +93,26 @@ show_error_codes = true
strict = true
overrides = [{ module = ["virtualenv.*"], ignore_missing_imports = true }]

[tool.pep8]
max-line-length = "120"
[tool.ruff]
select = ["ALL"]
line-length = 120
target-version = "py37"
isort = {known-first-party = ["pyproject_api"], required-imports = ["from __future__ import annotations"]}
ignore = [
"INP001", # no implicit namespaces here
"ANN101", # Missing type annotation for `self` in method
"ANN102", # Missing type annotation for `cls` in classmethod"
"ANN401", # Dynamically typed expressions
"D203", # `one-blank-line-before-class` (D203) and `no-blank-line-before-class` (D211) are incompatible
"D212", # `multi-line-summary-first-line` (D212) and `multi-line-summary-second-line` (D213) are incompatible
"S104", # Possible binding to all interface
]
[tool.ruff.per-file-ignores]
"tests/**/*.py" = [
"S101", # asserts allowed in tests...
"FBT", # don"t care about booleans as positional arguments in tests
"INP001", # no implicit namespace
"D", # don"t care about documentation in tests
"S603", # `subprocess` call: check for execution of untrusted input
"PLR2004", # Magic value used in comparison, consider replacing with a constant variable
]
1 change: 1 addition & 0 deletions src/pyproject_api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""PyProject API interface."""
from __future__ import annotations

from ._frontend import (
Expand Down
29 changes: 16 additions & 13 deletions src/pyproject_api/__main__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
from __future__ import annotations
from __future__ import annotations # noqa: D100

import argparse
import os
import pathlib
import sys
from typing import TYPE_CHECKING

from ._frontend import EditableResult, SdistResult, WheelResult
from ._via_fresh_subprocess import SubprocessFrontend

if TYPE_CHECKING:
from ._frontend import EditableResult, SdistResult, WheelResult

def main_parser() -> argparse.ArgumentParser:

def main_parser() -> argparse.ArgumentParser: # noqa: D103
parser = argparse.ArgumentParser(
description=(
"A pyproject.toml-based build frontend. "
Expand Down Expand Up @@ -58,7 +61,7 @@ def main_parser() -> argparse.ArgumentParser:
return parser


def main(argv: list[str]) -> None:
def main(argv: list[str]) -> None: # noqa: D103
parser = main_parser()
args = parser.parse_args(argv)

Expand All @@ -70,22 +73,22 @@ def main(argv: list[str]) -> None:
res: SdistResult | WheelResult | EditableResult

if "sdist" in distributions:
print("Building sdist...")
print("Building sdist...") # noqa: T201
res = frontend.build_sdist(outdir)
print(res.out)
print(res.err, file=sys.stderr)
print(res.out) # noqa: T201
print(res.err, file=sys.stderr) # noqa: T201

if "wheel" in distributions:
print("Building wheel...")
print("Building wheel...") # noqa: T201
res = frontend.build_wheel(outdir)
print(res.out)
print(res.err, file=sys.stderr)
print(res.out) # noqa: T201
print(res.err, file=sys.stderr) # noqa: T201

if "editable" in distributions:
print("Building editable wheel...")
print("Building editable wheel...") # noqa: T201
res = frontend.build_editable(outdir)
print(res.out)
print(res.err, file=sys.stderr)
print(res.out) # noqa: T201
print(res.err, file=sys.stderr) # noqa: T201


if __name__ == "__main__":
Expand Down
10 changes: 4 additions & 6 deletions src/pyproject_api/_backend.pyi
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
"""Handles communication on the backend side between frontend and backend"""
from typing import Any, Optional, Sequence
from typing import Any, Sequence

class MissingCommand(TypeError): ...
class MissingCommand(TypeError): ... # noqa: N818

class BackendProxy:
backend_module: str
backend_object: Optional[str]
backend_object: str | None
backend: Any
def __init__(self, backend_module: str, backend_obj: Optional[str]) -> None: ...
def __init__(self, backend_module: str, backend_obj: str | None) -> None: ...
def __call__(self, name: str, *args: Any, **kwargs: Any) -> Any: ...
def __str__(self) -> str: ...
def _exit(self) -> None: ...
def _optional_commands(self) -> dict[str, bool]: ...

Expand Down
Loading

0 comments on commit d14728a

Please sign in to comment.