Skip to content

Commit be45b2e

Browse files
authored
refactor: replace toml-sort with pyproject-fmt (#635)
1 parent a7d0326 commit be45b2e

File tree

9 files changed

+246
-279
lines changed

9 files changed

+246
-279
lines changed

.pre-commit-config.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,11 @@ repos:
7373
- python
7474
- pyi
7575
require_serial: true
76-
- id: toml-sort
77-
name: toml-sort
78-
entry: pdm run toml-sort
79-
language: system
76+
- id: pyproject-fmt
77+
name: pyproject-fmt
78+
entry: pyproject-fmt
79+
language: python
80+
files: '(^|/)pyproject\.toml$'
8081
types:
8182
- toml
8283
- id: forbidden-files

Makefile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: clean deepclean install dev prerequisites mypy ruff ruff-format toml-sort lint pre-commit test-run test build publish doc-autobuild doc-gen doc-mypy doc-coverage doc consistency
1+
.PHONY: clean deepclean install dev prerequisites mypy ruff ruff-format pyproject-fmt lint pre-commit test-run test build publish doc-autobuild doc-gen doc-mypy doc-coverage doc consistency
22

33
########################################################################################
44
# Variables
@@ -53,6 +53,7 @@ dev:
5353

5454
# Install standalone tools
5555
prerequisites:
56+
pipx install --force pyproject-fmt==2.1.4
5657
pipx install --force ruff==0.5.0
5758

5859
########################################################################################
@@ -71,12 +72,12 @@ ruff:
7172
ruff-format:
7273
ruff format --check .
7374

74-
# Check lint with toml-sort.
75-
toml-sort:
76-
pdm run toml-sort --check pyproject.toml
75+
# Check lint with pyproject-fmt.
76+
pyproject-fmt:
77+
pyproject-fmt pyproject.toml
7778

7879
# Check lint with all linters.
79-
lint: mypy ruff ruff-format toml-sort
80+
lint: mypy ruff ruff-format pyproject-fmt
8081

8182
# Run pre-commit with autofix against all files.
8283
pre-commit:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ If you find this helpful, please consider [sponsorship](https://github.com/spons
3939
- Project setup and template update with [copier](https://copier.readthedocs.io/).
4040
- Manage dependencies and virtual environments with [pdm](https://pdm-project.org/).
4141
- Build with [setuptools](https://github.com/pypa/setuptools) and versioned with [setuptools-scm](https://github.com/pypa/setuptools_scm/).
42-
- Lint with [pre-commit](https://pre-commit.com), [mypy](http://www.mypy-lang.org/), [ruff](https://github.com/charliermarsh/ruff), [toml-sort](https://github.com/pappasam/toml-sort) and [commitlint](https://commitlint.js.org/).
42+
- Lint with [pre-commit](https://pre-commit.com), [mypy](http://www.mypy-lang.org/), [ruff](https://github.com/charliermarsh/ruff), [pyproject-fmt](https://github.com/tox-dev/pyproject-fmt) and [commitlint](https://commitlint.js.org/).
4343
- Test with [pytest](https://docs.pytest.org/) and [coverage](https://coverage.readthedocs.io) for threshold and reports.
4444
- Documentation with [sphinx](https://www.sphinx-doc.org/), the [furo](https://pradyunsg.me/furo) theme and [MyST parser](https://myst-parser.readthedocs.io/) for markdown.
4545
- Develop Command Line Interfaces with [typer](https://typer.tiangolo.com/).

includes/sample.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ If you find this helpful, please consider [sponsorship](https://github.com/spons
1515
- Project setup and template update with [copier](https://copier.readthedocs.io/).
1616
- Manage dependencies and virtual environments with [pdm](https://pdm-project.org/).
1717
- Build with [setuptools](https://github.com/pypa/setuptools) and versioned with [setuptools-scm](https://github.com/pypa/setuptools_scm/).
18-
- Lint with [pre-commit](https://pre-commit.com), [mypy](http://www.mypy-lang.org/), [ruff](https://github.com/charliermarsh/ruff), [toml-sort](https://github.com/pappasam/toml-sort) and [commitlint](https://commitlint.js.org/).
18+
- Lint with [pre-commit](https://pre-commit.com), [mypy](http://www.mypy-lang.org/), [ruff](https://github.com/charliermarsh/ruff), [pyproject-fmt](https://github.com/tox-dev/pyproject-fmt) and [commitlint](https://commitlint.js.org/).
1919
- Test with [pytest](https://docs.pytest.org/) and [coverage](https://coverage.readthedocs.io) for threshold and reports.
2020
- Documentation with [sphinx](https://www.sphinx-doc.org/), the [furo](https://pradyunsg.me/furo) theme and [MyST parser](https://myst-parser.readthedocs.io/) for markdown.
2121
- Develop Command Line Interfaces with [typer](https://typer.tiangolo.com/).

pdm.lock

Lines changed: 1 addition & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 97 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,105 @@
11
[build-system]
22
build-backend = "setuptools.build_meta"
33
requires = [
4-
"setuptools-scm==8.1.0",
5-
"setuptools==70.1.1",
4+
"setuptools==70.1.1",
5+
"setuptools-scm==8.1.0",
66
]
77

88
[project]
9-
authors = [
10-
{email = "[email protected]", name = "huxuan"},
11-
]
12-
classifiers = [
13-
"Development Status :: 3 - Alpha",
14-
"License :: OSI Approved :: MIT License",
15-
"Operating System :: OS Independent",
16-
"Programming Language :: Python :: 3.10",
17-
"Programming Language :: Python :: 3.11",
18-
"Programming Language :: Python :: 3.12",
19-
"Programming Language :: Python :: 3.8",
20-
"Programming Language :: Python :: 3.9",
21-
]
22-
dependencies = [
23-
"pydantic-settings",
24-
"typer[all]",
25-
]
9+
name = "ss-python"
2610
description = "An evolving Python project template that covers the full development lifecycle."
27-
dynamic = [
28-
"version",
29-
]
11+
readme = "README.md"
3012
keywords = [
31-
"copier-template",
32-
"full-development-lifecycle",
33-
"project-template",
34-
"serious-scaffold",
13+
"copier-template",
14+
"full-development-lifecycle",
15+
"project-template",
16+
"serious-scaffold",
17+
]
18+
license = { text = "MIT" }
19+
authors = [
20+
{ email = "[email protected]", name = "huxuan" },
3521
]
36-
license = {text = "MIT"}
37-
name = "ss-python"
38-
readme = "README.md"
3922
requires-python = ">=3.8"
40-
41-
[project.scripts]
42-
ss-python-cli = "ss_python.cli:app"
43-
44-
[project.urls]
45-
documentation = "https://serious-scaffold.github.io/ss-python"
46-
issue = "https://github.com/serious-scaffold/ss-python/issues"
47-
repository = "https://github.com/serious-scaffold/ss-python"
48-
49-
[tool.coverage.report]
50-
fail_under = 100
51-
52-
[tool.coverage.run]
53-
source = [
54-
"ss_python",
23+
classifiers = [
24+
"Development Status :: 3 - Alpha",
25+
"License :: OSI Approved :: MIT License",
26+
"Operating System :: OS Independent",
27+
"Programming Language :: Python :: 3 :: Only",
28+
"Programming Language :: Python :: 3.8",
29+
"Programming Language :: Python :: 3.9",
30+
"Programming Language :: Python :: 3.10",
31+
"Programming Language :: Python :: 3.11",
32+
"Programming Language :: Python :: 3.12",
5533
]
56-
57-
[tool.mypy]
58-
check_untyped_defs = true
59-
disallow_any_unimported = true
60-
disallow_untyped_defs = true
61-
enable_error_code = [
62-
"ignore-without-code",
34+
dynamic = [
35+
"version",
6336
]
64-
exclude = [
65-
"build",
66-
"template",
37+
dependencies = [
38+
"pydantic-settings",
39+
"typer[all]",
6740
]
68-
no_implicit_optional = true
69-
show_error_codes = true
70-
warn_return_any = true
71-
warn_unused_ignores = true
41+
urls.documentation = "https://serious-scaffold.github.io/ss-python"
42+
urls.issue = "https://github.com/serious-scaffold/ss-python/issues"
43+
urls.repository = "https://github.com/serious-scaffold/ss-python"
44+
scripts.ss-python-cli = "ss_python.cli:app"
7245

7346
[tool.pdm]
7447
distribution = true
7548

7649
[tool.pdm.dev-dependencies]
7750
doc = [
78-
"Sphinx",
79-
"autodoc-pydantic",
80-
"coverage",
81-
"furo",
82-
"mypy[reports]",
83-
"myst-parser",
84-
"pytest",
85-
"sphinx-autobuild",
86-
"sphinx-click",
87-
"sphinx-design",
51+
"Sphinx",
52+
"autodoc-pydantic",
53+
"coverage",
54+
"furo",
55+
"mypy[reports]",
56+
"myst-parser",
57+
"pytest",
58+
"sphinx-autobuild",
59+
"sphinx-click",
60+
"sphinx-design",
8861
]
8962
lint = [
90-
"mypy",
91-
"toml-sort",
63+
"mypy",
9264
]
9365
test = [
94-
"coverage",
95-
"pytest",
66+
"coverage",
67+
"pytest",
9668
]
9769

70+
[tool.setuptools_scm]
71+
fallback_version = "0.0.0"
72+
73+
[tool.ruff]
74+
src = [
75+
"src",
76+
]
77+
extend-exclude = [
78+
"template",
79+
]
80+
fix = true
81+
lint.select = [
82+
"B", # flake8-bugbear
83+
"D", # pydocstyle
84+
"E", # pycodestyle error
85+
"F", # Pyflakes
86+
"I", # isort
87+
"RUF100", # Unused noqa directive
88+
"S", # flake8-bandit
89+
"SIM", # flake8-simplify
90+
"UP", # pyupgrade
91+
"W", # pycodestyle warning
92+
]
93+
lint.per-file-ignores."tests/*" = [
94+
"S101",
95+
]
96+
lint.pydocstyle.convention = "google"
97+
98+
[tool.pyproject-fmt]
99+
indent = 4
100+
keep_full_version = true
101+
max_supported_python = "3.12"
102+
98103
[tool.pytest.ini_options]
99104
addopts = "-l -s --durations=0"
100105
log_cli = true
@@ -103,37 +108,26 @@ log_date_format = "%Y-%m-%d %H:%M:%S"
103108
log_format = "%(asctime)s %(levelname)s %(message)s"
104109
minversion = "6.0"
105110

106-
[tool.ruff]
107-
extend-exclude = [
108-
"template",
109-
]
110-
fix = true
111-
src = ["src"]
111+
[tool.coverage.report]
112+
fail_under = 100
112113

113-
[tool.ruff.lint]
114-
select = [
115-
"B", # flake8-bugbear
116-
"D", # pydocstyle
117-
"E", # pycodestyle error
118-
"F", # Pyflakes
119-
"I", # isort
120-
"RUF100", # Unused noqa directive
121-
"S", # flake8-bandit
122-
"SIM", # flake8-simplify
123-
"UP", # pyupgrade
124-
"W", # pycodestyle warning
114+
[tool.coverage.run]
115+
source = [
116+
"ss_python",
125117
]
126118

127-
[tool.ruff.lint.per-file-ignores]
128-
"tests/*" = ["S101"]
129-
130-
[tool.ruff.lint.pydocstyle]
131-
convention = "google"
132-
133-
[tool.setuptools_scm]
134-
fallback_version = "0.0.0"
135-
136-
[tool.tomlsort]
137-
all = true
138-
in_place = true
139-
trailing_comma_inline_array = true
119+
[tool.mypy]
120+
check_untyped_defs = true
121+
disallow_any_unimported = true
122+
disallow_untyped_defs = true
123+
enable_error_code = [
124+
"ignore-without-code",
125+
]
126+
exclude = [
127+
"build",
128+
"template",
129+
]
130+
no_implicit_optional = true
131+
show_error_codes = true
132+
warn_return_any = true
133+
warn_unused_ignores = true

template/.pre-commit-config.yaml.jinja

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,11 @@ repos:
7676
- python
7777
- pyi
7878
require_serial: true
79-
- id: toml-sort
80-
name: toml-sort
81-
entry: pdm run toml-sort
82-
language: system
79+
- id: pyproject-fmt
80+
name: pyproject-fmt
81+
entry: pyproject-fmt
82+
language: python
83+
files: '(^|/)pyproject\.toml$'
8384
types:
8485
- toml
8586
- id: forbidden-files

template/Makefile.jinja

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[% from pathjoin("includes", "variable.jinja") import page_url with context -%]
2-
.PHONY: clean deepclean install dev prerequisites mypy ruff ruff-format toml-sort lint pre-commit test-run test build publish doc-autobuild doc-gen doc-mypy doc-coverage doc
2+
.PHONY: clean deepclean install dev prerequisites mypy ruff ruff-format pyproject-fmt lint pre-commit test-run test build publish doc-autobuild doc-gen doc-mypy doc-coverage doc
33
[%- if project_name == "Serious Scaffold Python" %] consistency[% endif %]
44

55
########################################################################################
@@ -55,6 +55,7 @@ dev:
5555

5656
# Install standalone tools
5757
prerequisites:
58+
pipx install --force pyproject-fmt==2.1.4
5859
pipx install --force ruff==0.5.0
5960

6061
########################################################################################
@@ -73,12 +74,12 @@ ruff:
7374
ruff-format:
7475
ruff format --check .
7576

76-
# Check lint with toml-sort.
77-
toml-sort:
78-
pdm run toml-sort --check pyproject.toml
77+
# Check lint with pyproject-fmt.
78+
pyproject-fmt:
79+
pyproject-fmt pyproject.toml
7980

8081
# Check lint with all linters.
81-
lint: mypy ruff ruff-format toml-sort
82+
lint: mypy ruff ruff-format pyproject-fmt
8283

8384
# Run pre-commit with autofix against all files.
8485
pre-commit:

0 commit comments

Comments
 (0)