Skip to content

Commit b25b308

Browse files
committed
change: convert to Hatch, Pytest and Ruff
1 parent aa710ef commit b25b308

28 files changed

+577
-675
lines changed

.bumpversion.cfg

-17
This file was deleted.

.gitignore

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
*.pyc
1+
build/
2+
.copier/
3+
.coverage*
4+
dist/
25
*.egg-info/
6+
*.pyc
7+
.pytest_cache/
38
.tox/
4-
.coverage
5-
dist/
6-
build/
79
.venv/
810
.vscode/

.pre-commit-config.yaml

+71-27
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,96 @@
11
---
2-
# INSTALL .: `pre-commit install --overwrite --install-hooks`
2+
# INSTALL .: `pre-commit install`
33
# UPDATE ..: `pre-commit autoupdate`
4-
exclude: '^(CHANGELOG\.md)$'
4+
exclude: |
5+
(?x)^(
6+
CHANGELOG\..*|
7+
\.copier-answers\..*|
8+
\.copier/answers\..*|
9+
.*/vendor/.*|
10+
.+\.min\.(css|js)|
11+
.+\.svg
12+
)$
513
default_language_version:
6-
python: python3.9
14+
python: python3.12
15+
default_install_hook_types:
16+
- commit-msg
17+
- pre-commit
718
repos:
19+
# General
20+
# https://github.com/pre-commit/pre-commit-hooks
821
- repo: https://github.com/pre-commit/pre-commit-hooks
922
rev: v5.0.0
1023
hooks:
11-
# Generall Stuff
24+
# Whitespace
1225
- id: trailing-whitespace
1326
- id: end-of-file-fixer
1427
- id: mixed-line-ending
1528
args:
1629
- "--fix=lf"
1730
# VCS
1831
- id: check-merge-conflict
32+
args:
33+
- "--assume-in-merge"
34+
# Binaries
35+
- id: check-shebang-scripts-are-executable
1936
# Config / Data Files (syntax check only)
37+
- id: check-json
2038
- id: check-yaml
2139
- id: check-toml
40+
- id: check-xml
2241
# Python
2342
- id: debug-statements
24-
- id: requirements-txt-fixer
25-
# Prettier (HTML, JS, CSS, Markdown, YAML…)
26-
- repo: https://github.com/pre-commit/mirrors-prettier
27-
rev: v4.0.0-alpha.8
43+
# Sensible Data
44+
- id: detect-private-key
45+
# Markdown
46+
# https://github.com/executablebooks/mdformat
47+
- repo: https://github.com/executablebooks/mdformat
48+
rev: 0.7.22
2849
hooks:
29-
- id: prettier
30-
# Python: check syntax
31-
- repo: https://github.com/pycqa/flake8
32-
rev: 7.1.1
50+
- id: mdformat
51+
additional_dependencies:
52+
- mdformat-config
53+
- mdformat-frontmatter
54+
- mdformat-mkdocs
55+
- mdformat-tables
56+
# skip linting Hugo content b/c of this bug:
57+
# https://github.com/executablebooks/mdformat/issues/402
58+
exclude: ^site/content/.*
59+
# Conventional Commits <https://www.conventionalcommits.org/>
60+
# https://github.com/compilerla/conventional-pre-commit
61+
- repo: https://github.com/compilerla/conventional-pre-commit
62+
rev: v4.0.0
3363
hooks:
34-
- id: flake8
64+
- id: conventional-pre-commit
65+
stages:
66+
- commit-msg
3567
args:
36-
- "--select=F"
37-
# Python: reorder imports
38-
- repo: https://github.com/asottile/reorder-python-imports
39-
rev: v3.14.0
68+
- change
69+
- chore
70+
- feat
71+
- fix
72+
# Python: lint and format code
73+
# https://github.com/astral-sh/ruff-pre-commit
74+
- repo: https://github.com/astral-sh/ruff-pre-commit
75+
rev: v0.9.4
4076
hooks:
41-
- id: reorder-python-imports
77+
- id: ruff
4278
args:
43-
- "--application-directories=.:src:tests"
44-
- "--py37-plus"
45-
# Python: lint with black
46-
- repo: https://github.com/psf/black
47-
rev: 24.10.0
48-
hooks:
49-
- id: black
79+
- "--fix"
80+
- "--exit-non-zero-on-fix"
81+
- "--target-version=py312"
82+
# https://docs.astral.sh/ruff/rules/
83+
- "--select=F,E4,E7,E9,I,UP,B,N"
84+
- "--config"
85+
- "lint.isort.force-single-line=true"
86+
- "--config"
87+
- "format.docstring-code-format=true"
88+
- id: ruff-format
5089
args:
51-
- "--line-length=88"
52-
- "--target-version=py37"
90+
- "--target-version=py312"
91+
# Python: check project (i.e. `pyproject.toml`)
92+
# https://github.com/abravalheri/validate-pyproject
93+
- repo: https://github.com/abravalheri/validate-pyproject
94+
rev: v0.23
95+
hooks:
96+
- id: validate-pyproject

.pyup.yml

-6
This file was deleted.

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ You can find the **issue tracker** at:
1010
[keep a changelog]: https://keepachangelog.com/
1111
[semantic versioning]: https://semver.org/
1212

13-
<!-- TOWNCRIER -->
13+
<!-- towncrier release notes start -->
1414

1515
## 0.6.1 (2022-01-03)
1616

Makefile

+53-76
Original file line numberDiff line numberDiff line change
@@ -1,117 +1,94 @@
11
.PHONY: \
2-
setup setup-venv setup-requirements setup-pre-commit \
3-
clean full-clean upgrade \
4-
lint audit \
5-
all-tests unittests doctests coverage \
2+
clean full-clean \
3+
lint check fmt \
4+
tests doctests coverage \
5+
build publish \
66
change clog \
7-
release build publish
8-
9-
10-
PYTHON_VERSION := $(shell cat runtime.txt)
11-
12-
RELEASE_LEVELS := patch minor major
13-
14-
15-
# SETUP
16-
17-
setup: setup-venv setup-requirements setup-pre-commit
18-
19-
setup-venv: version ?= $(cat runtime.txt)
20-
setup-venv:
21-
python$(PYTHON_VERSION) -m venv --clear --upgrade-deps .venv
22-
23-
export PATH := $(shell pwd)/.venv/bin:$(PATH)
24-
25-
setup-requirements: req ?= requirements.txt
26-
setup-requirements:
27-
pip install --isolated --no-input --quiet -r '$(req)'
28-
29-
setup-pre-commit:
30-
pre-commit install --install-hooks
7+
release
318

329
clean:
3310
rm -rf MANIFEST build dist
3411

3512
full-clean: clean
36-
rm -rf .venv .tox .nox .pytest_cache .mypy_cache .coverage*
37-
38-
upgrade:
39-
pip-compile \
40-
--upgrade \
41-
--no-header \
42-
--strip-extras \
43-
--annotation-style line \
44-
--output-file requirements/constraints.txt \
45-
setup.cfg \
46-
requirements/*.in
47-
13+
rm -rf .venv .tox .nox .pytest_cache .mypy_cache .ruff_cache .coverage*
4814

4915
# LINTING
5016

5117
lint:
52-
pre-commit run --all-files
18+
hatch run lint:pc
5319

54-
audit:
55-
safety check --file requirements/constraints.txt
20+
check:
21+
hatch run lint:check
5622

23+
fix:
24+
hatch run lint:fix
25+
hatch run lint:upgrade
5726

5827
# TESTS
5928

60-
all-tests:
61-
tox $(args)
29+
test:
30+
hatch test
31+
32+
coverage:
33+
hatch test --cover
6234

63-
doctests:
64-
xdoctest --quiet wtforms_html5
35+
version-test:
36+
hatch test --all --cover
6537

66-
unittests:
67-
python -m unittest discover
38+
doctest:
39+
hatch test -- --xdoctest src/
6840

69-
coverage:
70-
coverage erase
71-
coverage run -m unittest discover $(args)
72-
coverage report
41+
# PACKAGING
42+
43+
build: clean
44+
hatch build --clean --target wheel
7345

46+
publish: build
47+
hatch publish
7448

7549
# CHANGELOG
7650

51+
CHANGE_TYPES := rm fix feat change
52+
7753
change: issue ?= _$(shell < /dev/urandom tr -dc A-Za-z0-9 | head -c9)
78-
change: type ?= feature
7954
change: change_file := changes/$(issue).$(type).md
8055
change:
56+
ifneq ($(filter $(type),$(CHANGE_TYPES)),)
8157
touch '$(change_file)'
8258
$(EDITOR) '$(change_file)'
59+
else
60+
@echo "Given change type '$(type)' is not a suported value: $(CHANGE_TYPES)"
61+
endif
8362

8463
clog:
85-
towncrier --draft --version=Unreleased
64+
hatch run project:towncrier build --draft --version Unreleased
8665

8766

88-
# PACKAGING
67+
# RELEASE
68+
69+
RELEASE_LEVELS := patch minor major
8970

9071
release:
9172
ifneq ($(filter $(part),$(RELEASE_LEVELS)),)
92-
$(eval version = $(shell \
93-
.venv/bin/bumpversion --dry-run --allow-dirty --list $(part) \
94-
| grep '^current_version=' \
95-
| cut -d= -f2 \
96-
))
97-
$(eval new = $(shell \
98-
.venv/bin/bumpversion --dry-run --allow-dirty --list $(part) \
99-
| grep '^new_version=' \
100-
| cut -d= -f2 \
73+
# check git status
74+
@if ! git diff-index --quiet HEAD; then \
75+
echo "ERROR: git unclean!"; \
76+
exit 1; \
77+
fi
78+
# get next version (for changelog)
79+
$(eval new_version := $(shell \
80+
hatch run project:bumpver update --dry --$(part) 2>&1 \
81+
| grep 'New Version:' \
82+
| awk '{print $$NF}' \
10183
))
102-
@echo "bump $(part) -> $(version) => $(new)"
103-
towncrier --yes --version '$(new)'
84+
@echo "bump -> '$(new_version)'"
85+
# write changelog
86+
hatch run project:towncrier build --yes --version '$(new_version)'
10487
if ! git diff --staged --exit-code; then \
105-
git commit -m ':memo: add CHANGELOG for $(new)' --no-verify; \
88+
git commit -m 'chore: add CHANGELOG for `$(new_version)`' --no-verify; \
10689
fi
107-
bumpversion '$(part)' --commit-args='--no-verify'
90+
# bump version
91+
hatch run project:bumpver update '--$(part)'
10892
else
10993
@echo "Given part '$(part)' is not a suported value: $(RELEASE_LEVELS)"
11094
endif
111-
112-
build: clean
113-
python -m build
114-
115-
publish: build
116-
python -m twine check dist/*
117-
python -m twine upload dist/*

0 commit comments

Comments
 (0)