Skip to content

Commit

Permalink
Pass configuration via separate class
Browse files Browse the repository at this point in the history
Signed-off-by: Bernát Gábor <[email protected]>
  • Loading branch information
gaborbernat committed May 11, 2024
1 parent cb3ddb2 commit 15a7b3f
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 42 deletions.
7 changes: 3 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
Expand All @@ -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
Expand Down
56 changes: 37 additions & 19 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ keywords = [
"pyproject",
]
license.file = "LICENSE.txt"
authors = [{ name = "Bernat Gabor", email = "[email protected]" }]
authors = [
{ name = "Bernat Gabor", email = "[email protected]" },
]
requires-python = ">=3.8"
classifiers = [
"License :: OSI Approved :: MIT License",
Expand All @@ -31,7 +33,7 @@ dynamic = [
"version",
]
dependencies = [
"pyproject-fmt-rust==1",
"pyproject-fmt-rust==1.0.1",
]
optional-dependencies.docs = [
"furo>=2024.5.6",
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
9 changes: 1 addition & 8 deletions src/pyproject_fmt/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 10 additions & 11 deletions src/pyproject_fmt/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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,
),
)
)

Expand Down

0 comments on commit 15a7b3f

Please sign in to comment.