Skip to content

Commit

Permalink
refactor: replace toml-sort with pyproject-fmt (#635)
Browse files Browse the repository at this point in the history
  • Loading branch information
huxuan authored Jul 5, 2024
1 parent a7d0326 commit be45b2e
Show file tree
Hide file tree
Showing 9 changed files with 246 additions and 279 deletions.
9 changes: 5 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,11 @@ repos:
- python
- pyi
require_serial: true
- id: toml-sort
name: toml-sort
entry: pdm run toml-sort
language: system
- id: pyproject-fmt
name: pyproject-fmt
entry: pyproject-fmt
language: python
files: '(^|/)pyproject\.toml$'
types:
- toml
- id: forbidden-files
Expand Down
11 changes: 6 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.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
.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

########################################################################################
# Variables
Expand Down Expand Up @@ -53,6 +53,7 @@ dev:

# Install standalone tools
prerequisites:
pipx install --force pyproject-fmt==2.1.4
pipx install --force ruff==0.5.0

########################################################################################
Expand All @@ -71,12 +72,12 @@ ruff:
ruff-format:
ruff format --check .

# Check lint with toml-sort.
toml-sort:
pdm run toml-sort --check pyproject.toml
# Check lint with pyproject-fmt.
pyproject-fmt:
pyproject-fmt pyproject.toml

# Check lint with all linters.
lint: mypy ruff ruff-format toml-sort
lint: mypy ruff ruff-format pyproject-fmt

# Run pre-commit with autofix against all files.
pre-commit:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ If you find this helpful, please consider [sponsorship](https://github.com/spons
- Project setup and template update with [copier](https://copier.readthedocs.io/).
- Manage dependencies and virtual environments with [pdm](https://pdm-project.org/).
- Build with [setuptools](https://github.com/pypa/setuptools) and versioned with [setuptools-scm](https://github.com/pypa/setuptools_scm/).
- 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/).
- 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/).
- Test with [pytest](https://docs.pytest.org/) and [coverage](https://coverage.readthedocs.io) for threshold and reports.
- 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.
- Develop Command Line Interfaces with [typer](https://typer.tiangolo.com/).
Expand Down
2 changes: 1 addition & 1 deletion includes/sample.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ If you find this helpful, please consider [sponsorship](https://github.com/spons
- Project setup and template update with [copier](https://copier.readthedocs.io/).
- Manage dependencies and virtual environments with [pdm](https://pdm-project.org/).
- Build with [setuptools](https://github.com/pypa/setuptools) and versioned with [setuptools-scm](https://github.com/pypa/setuptools_scm/).
- 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/).
- 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/).
- Test with [pytest](https://docs.pytest.org/) and [coverage](https://coverage.readthedocs.io) for threshold and reports.
- 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.
- Develop Command Line Interfaces with [typer](https://typer.tiangolo.com/).
Expand Down
27 changes: 1 addition & 26 deletions pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

200 changes: 97 additions & 103 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,100 +1,105 @@
[build-system]
build-backend = "setuptools.build_meta"
requires = [
"setuptools-scm==8.1.0",
"setuptools==70.1.1",
"setuptools==70.1.1",
"setuptools-scm==8.1.0",
]

[project]
authors = [
{email = "i@huxuan.org", name = "huxuan"},
]
classifiers = [
"Development Status :: 3 - Alpha",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
]
dependencies = [
"pydantic-settings",
"typer[all]",
]
name = "ss-python"
description = "An evolving Python project template that covers the full development lifecycle."
dynamic = [
"version",
]
readme = "README.md"
keywords = [
"copier-template",
"full-development-lifecycle",
"project-template",
"serious-scaffold",
"copier-template",
"full-development-lifecycle",
"project-template",
"serious-scaffold",
]
license = { text = "MIT" }
authors = [
{ email = "i@huxuan.org", name = "huxuan" },
]
license = {text = "MIT"}
name = "ss-python"
readme = "README.md"
requires-python = ">=3.8"

[project.scripts]
ss-python-cli = "ss_python.cli:app"

[project.urls]
documentation = "https://serious-scaffold.github.io/ss-python"
issue = "https://github.com/serious-scaffold/ss-python/issues"
repository = "https://github.com/serious-scaffold/ss-python"

[tool.coverage.report]
fail_under = 100

[tool.coverage.run]
source = [
"ss_python",
classifiers = [
"Development Status :: 3 - Alpha",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3 :: Only",
"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",
]

[tool.mypy]
check_untyped_defs = true
disallow_any_unimported = true
disallow_untyped_defs = true
enable_error_code = [
"ignore-without-code",
dynamic = [
"version",
]
exclude = [
"build",
"template",
dependencies = [
"pydantic-settings",
"typer[all]",
]
no_implicit_optional = true
show_error_codes = true
warn_return_any = true
warn_unused_ignores = true
urls.documentation = "https://serious-scaffold.github.io/ss-python"
urls.issue = "https://github.com/serious-scaffold/ss-python/issues"
urls.repository = "https://github.com/serious-scaffold/ss-python"
scripts.ss-python-cli = "ss_python.cli:app"

[tool.pdm]
distribution = true

[tool.pdm.dev-dependencies]
doc = [
"Sphinx",
"autodoc-pydantic",
"coverage",
"furo",
"mypy[reports]",
"myst-parser",
"pytest",
"sphinx-autobuild",
"sphinx-click",
"sphinx-design",
"Sphinx",
"autodoc-pydantic",
"coverage",
"furo",
"mypy[reports]",
"myst-parser",
"pytest",
"sphinx-autobuild",
"sphinx-click",
"sphinx-design",
]
lint = [
"mypy",
"toml-sort",
"mypy",
]
test = [
"coverage",
"pytest",
"coverage",
"pytest",
]

[tool.setuptools_scm]
fallback_version = "0.0.0"

[tool.ruff]
src = [
"src",
]
extend-exclude = [
"template",
]
fix = true
lint.select = [
"B", # flake8-bugbear
"D", # pydocstyle
"E", # pycodestyle error
"F", # Pyflakes
"I", # isort
"RUF100", # Unused noqa directive
"S", # flake8-bandit
"SIM", # flake8-simplify
"UP", # pyupgrade
"W", # pycodestyle warning
]
lint.per-file-ignores."tests/*" = [
"S101",
]
lint.pydocstyle.convention = "google"

[tool.pyproject-fmt]
indent = 4
keep_full_version = true
max_supported_python = "3.12"

[tool.pytest.ini_options]
addopts = "-l -s --durations=0"
log_cli = true
Expand All @@ -103,37 +108,26 @@ log_date_format = "%Y-%m-%d %H:%M:%S"
log_format = "%(asctime)s %(levelname)s %(message)s"
minversion = "6.0"

[tool.ruff]
extend-exclude = [
"template",
]
fix = true
src = ["src"]
[tool.coverage.report]
fail_under = 100

[tool.ruff.lint]
select = [
"B", # flake8-bugbear
"D", # pydocstyle
"E", # pycodestyle error
"F", # Pyflakes
"I", # isort
"RUF100", # Unused noqa directive
"S", # flake8-bandit
"SIM", # flake8-simplify
"UP", # pyupgrade
"W", # pycodestyle warning
[tool.coverage.run]
source = [
"ss_python",
]

[tool.ruff.lint.per-file-ignores]
"tests/*" = ["S101"]

[tool.ruff.lint.pydocstyle]
convention = "google"

[tool.setuptools_scm]
fallback_version = "0.0.0"

[tool.tomlsort]
all = true
in_place = true
trailing_comma_inline_array = true
[tool.mypy]
check_untyped_defs = true
disallow_any_unimported = true
disallow_untyped_defs = true
enable_error_code = [
"ignore-without-code",
]
exclude = [
"build",
"template",
]
no_implicit_optional = true
show_error_codes = true
warn_return_any = true
warn_unused_ignores = true
9 changes: 5 additions & 4 deletions template/.pre-commit-config.yaml.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,11 @@ repos:
- python
- pyi
require_serial: true
- id: toml-sort
name: toml-sort
entry: pdm run toml-sort
language: system
- id: pyproject-fmt
name: pyproject-fmt
entry: pyproject-fmt
language: python
files: '(^|/)pyproject\.toml$'
types:
- toml
- id: forbidden-files
Expand Down
11 changes: 6 additions & 5 deletions template/Makefile.jinja
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[% from pathjoin("includes", "variable.jinja") import page_url with context -%]
.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
.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
[%- if project_name == "Serious Scaffold Python" %] consistency[% endif %]

########################################################################################
Expand Down Expand Up @@ -55,6 +55,7 @@ dev:

# Install standalone tools
prerequisites:
pipx install --force pyproject-fmt==2.1.4
pipx install --force ruff==0.5.0

########################################################################################
Expand All @@ -73,12 +74,12 @@ ruff:
ruff-format:
ruff format --check .

# Check lint with toml-sort.
toml-sort:
pdm run toml-sort --check pyproject.toml
# Check lint with pyproject-fmt.
pyproject-fmt:
pyproject-fmt pyproject.toml

# Check lint with all linters.
lint: mypy ruff ruff-format toml-sort
lint: mypy ruff ruff-format pyproject-fmt

# Run pre-commit with autofix against all files.
pre-commit:
Expand Down
Loading

0 comments on commit be45b2e

Please sign in to comment.