diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6a9ff02..a25b7d2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,7 +5,7 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/python-jsonschema/check-jsonschema - rev: 0.28.2 + rev: 0.28.3 hooks: - id: check-github-workflows args: [ "--verbose" ] @@ -20,12 +20,11 @@ repos: - id: tox-ini-fmt args: ["-p", "fix"] - repo: https://github.com/tox-dev/pyproject-fmt - rev: "1.8.0" + rev: "2.0.1" hooks: - id: pyproject-fmt - additional_dependencies: ["tox>=4.12.1"] - repo: https://github.com/astral-sh/ruff-pre-commit - rev: "v0.4.2" + rev: "v0.4.4" hooks: - id: ruff-format - id: ruff diff --git a/pyproject.toml b/pyproject.toml index bd1f8dd..6084859 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,7 +14,9 @@ keywords = [ "pyproject", ] license.file = "LICENSE.txt" -authors = [{ name = "Bernat Gabor", email = "gaborjbernat@gmail.com" }] +authors = [ + { name = "Bernat Gabor", email = "gaborjbernat@gmail.com" }, +] requires-python = ">=3.8" classifiers = [ "License :: OSI Approved :: MIT License", @@ -31,7 +33,7 @@ dynamic = [ "version", ] dependencies = [ - "pyproject-fmt-rust==1", + "pyproject-fmt-rust==1.0.1", ] optional-dependencies.docs = [ "furo>=2024.5.6", @@ -53,22 +55,34 @@ urls."Source Code" = "https://github.com/tox-dev/pyproject-fmt" scripts.pyproject-fmt = "pyproject_fmt.__main__:run" [tool.hatch] -build.dev-mode-dirs = ["src"] +build.dev-mode-dirs = [ + "src", +] build.hooks.vcs.version-file = "src/pyproject_fmt/_version.py" -build.targets.sdist.include = ["/src", "/tests","tox.ini"] +build.targets.sdist.include = [ + "/src", + "/tests", + "tox.ini", +] version.source = "vcs" [tool.ruff] line-length = 120 target-version = "py38" -lint.isort = { known-first-party = ["pyproject_fmt"], required-imports = ["from __future__ import annotations"] } -lint.select = ["ALL"] +lint.isort = { known-first-party = [ + "pyproject_fmt", +], required-imports = [ + "from __future__ import annotations", +] } +lint.select = [ + "ALL", +] lint.ignore = [ - "ANN101", # no type annotation for self - "ANN401", # allow Any as type annotation - "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 + "ANN101", # no type annotation for self + "ANN401", # allow Any as type annotation + "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 "COM812", # Conflict with formatter "ISC001", # Conflict with formatter "CPY", # No copyright statements @@ -79,12 +93,12 @@ format.docstring-code-format = true format.docstring-code-line-length = 100 [tool.ruff.lint.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 + "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 "PLR0913", # any number of arguments in tests "PLR0917", # any number of arguments in tests "PLC2701", # private import @@ -95,7 +109,9 @@ builtin = "clear,usage,en-GB_to_en-US" count = true [tool.pytest] -ini_options.testpaths = ["tests"] +ini_options.testpaths = [ + "tests", +] [tool.coverage] html.show_contexts = true @@ -111,7 +127,9 @@ paths.source = [ ] report.fail_under = 100 run.parallel = true -run.plugins = ["covdefaults"] +run.plugins = [ + "covdefaults", +] [tool.mypy] show_error_codes = true diff --git a/src/pyproject_fmt/__main__.py b/src/pyproject_fmt/__main__.py index 5ee9403..a7baa6b 100644 --- a/src/pyproject_fmt/__main__.py +++ b/src/pyproject_fmt/__main__.py @@ -35,14 +35,7 @@ def color_diff(diff: Iterable[str]) -> Iterable[str]: def _handle_one(config: Config) -> bool: - formatted = format_toml( - config.toml, - column_width=config.column_width, - indent=config.indent, - keep_full_version=config.keep_full_version, - max_supported_python=config.max_supported_python, - min_supported_python=config.min_supported_python, - ) + formatted = format_toml(config.toml, config.settings) before = config.toml changed = before != formatted if config.stdout: # stdout just prints new format to stdout diff --git a/src/pyproject_fmt/cli.py b/src/pyproject_fmt/cli.py index 812fddd..aaa686b 100644 --- a/src/pyproject_fmt/cli.py +++ b/src/pyproject_fmt/cli.py @@ -15,6 +15,8 @@ from pathlib import Path from typing import Sequence +from pyproject_fmt_rust import Settings + if sys.version_info >= (3, 11): # pragma: >=3.11 cover import tomllib else: # pragma: <3.11 cover @@ -42,12 +44,7 @@ class Config: pyproject_toml: Path stdout: bool # push to standard out check: bool # check only - - column_width: int #: maximum column width - indent: int #: indentation to apply - keep_full_version: bool #: whether to keep full dependency versions - max_supported_python: tuple[int, int] #: the maximum supported Python version - min_supported_python: tuple[int, int] #: the minimum supported Python version + settings: Settings @property def toml(self) -> str: @@ -176,11 +173,13 @@ def cli_args(args: Sequence[str]) -> list[Config]: pyproject_toml=pyproject_toml, stdout=opt.stdout, check=opt.check, - column_width=column_width, - indent=indent, - keep_full_version=keep_full_version, - max_supported_python=max_supported_python, - min_supported_python=min_supported_python, + settings=Settings( + column_width=column_width, + indent=indent, + keep_full_version=keep_full_version, + max_supported_python=max_supported_python, + min_supported_python=min_supported_python, + ), ) )