Skip to content

Commit 8a3fd91

Browse files
authored
switch to hatch for testing, builds, and publication (#385)
* [hatch] install and configure hatch * [test] fix pytest and ruff warnings * switch to hatch for tests, builds, and publishing fixes #384 * [config] add configuraton for coverage in pyproject.toml * [hatch] configure mypy * fix configuration for mypy * [project] fix license file name
1 parent 7fd7b86 commit 8a3fd91

File tree

8 files changed

+94
-72
lines changed

8 files changed

+94
-72
lines changed

MANIFEST.in

Lines changed: 0 additions & 38 deletions
This file was deleted.

Makefile

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
test: lint pytest documentation examples
1+
test: lint documentation examples pytest
22

33

44
pytest: clean
5-
pytest --cov
5+
pytest -v --cov
66

77

88
documentation: sphinx
@@ -32,7 +32,7 @@ ruff:
3232

3333
mypy:
3434
-@ pip install -q -U mypy
35-
mypy --ignore-missing-imports . --exclude dist
35+
mypy --install-types --exclude dist .
3636

3737

3838
clean:
@@ -47,20 +47,22 @@ clean:
4747
rm -rf .tox
4848

4949

50-
release_check: clean documentation
51-
tox
50+
checks: clean documentation
51+
-@ pip install -qU hatch
52+
hatch run --force-continue test:checks
5253
@echo version `python -m tatsu --version`
5354

5455

55-
build: clean
56-
pip install -U build
57-
python -m build
56+
build: cleanhatch
57+
-@ pip install -qU hatch
58+
hatch build
5859

5960

60-
test_upload: build
61-
pip install -U twine
62-
twine upload --repository test dist/*
61+
test_publish: build
62+
-@ pip install -qU hatch
63+
hatch publish --repo test
6364

6465

65-
upload: release_check build
66-
twine upload dist/*
66+
publish: checks build
67+
pip install -U hatch
68+
hatch publish

tox.ini renamed to deprecated/tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ whitelist_externals =
99

1010
commands =
1111
ruff check --preview tatsu test examples
12-
mypy --ignore-missing-imports --exclude "parsers|docs|tmp|build|dist" .
12+
mypy --ignore-missing-imports --exclude "parsers|docs|tmp|build|dist" .
1313
pytest
1414

1515
deps =

pyproject.toml

Lines changed: 73 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[build-system]
2-
requires = ["setuptools>=46.4", "wheel"]
3-
build-backend = "setuptools.build_meta"
2+
requires = ["hatchling"]
3+
build-backend = "hatchling.build"
44

55
[project]
66
name = "TatSu"
@@ -12,7 +12,7 @@ description = "TatSu takes a grammar in a variation of EBNF as input, and output
1212
readme = "README.rst"
1313
requires-python = ">=3.10"
1414
keywords = []
15-
license = {file = "LICENSE.TXT"}
15+
license = {file = "LICENSE.txt"}
1616
classifiers = [
1717
"Development Status :: 5 - Production/Stable",
1818
"License :: OSI Approved :: BSD License",
@@ -47,24 +47,84 @@ Repository = "https://github.com/neogeny/TatSu"
4747
Documentation = "https://tatsu.readthedocs.io/en/stable/"
4848
Questions = "https://stackoverflow.com/questions/tagged/tatsu"
4949

50-
[tool.setuptools]
51-
include-package-data = false
50+
[tool.hatch.version]
51+
path = "tatsu/_version.py"
5252

53-
[tool.setuptools.dynamic]
54-
version = {attr = "tatsu._version.__version__"}
53+
[tool.hatch.build.targets.wheel]
54+
packages = ["tatsu"]
5555

56-
[tool.setuptools.packages.find]
57-
include = ["tatsu*"]
56+
[tool.hatch.build.targets.sdist]
57+
include = [
58+
"/tatsu",
59+
"/test",
60+
"/grammar",
61+
"/examples",
62+
"*.yaml",
63+
]
64+
excludee = ["deprecated"]
65+
66+
[tool.hatch.envs.hatch-test]
67+
default-args = ["test"]
68+
dependencies = [
69+
"pytest",
70+
"pytest-cov",
71+
"pytest-xdist", # For parallel execution
72+
]
5873

74+
# Set default arguments for the pytest command
75+
extra-args = ["-v", "--cov"]
5976

60-
[tool.blue]
61-
target-version = ["py310"]
62-
line-length=79
63-
skip-magic-trailing-comma=true
77+
# Enable built-in features
78+
randomize = false # Randomize test order
79+
parallel = false # Run tests in parallel
80+
retries = 0
6481

82+
[tool.pytest.ini_options]
83+
# minversion = "6.0"
84+
#addopts = "-ra -q"
85+
addopts = "-q"
86+
testpaths = [
87+
"test",
88+
]
89+
[tool.mypy]
90+
python_version = 3.14
91+
#ignore_missing_imports = true
92+
exclude = "parsers|docs|dist|build|tmp"
93+
94+
[tool.ruff]
95+
line-length = 88
96+
97+
# The minimum Python version to support
98+
# target-version = "py311"
99+
100+
# Files or directories to exclude from linting/formatting
101+
exclude = [
102+
".git",
103+
"__pycache__",
104+
"dist",
105+
]
65106

66107
[tool.coverage.run]
67108
omit = [
68109
"test/*",
69110
"tatsu/diagrams.py",
70111
]
112+
data_file = ".cache/coverage/.coverage"
113+
parallel = false
114+
115+
[tool.hatch.envs.test]
116+
dependencies = ["pytest", "mypy", "ruff"]
117+
118+
[tool.hatch.envs.test.scripts]
119+
lint = "ruff check -q --preview tatsu test examples"
120+
types = "mypy --install-types --exclude 'parsers|docs|tmp|build|dist' ."
121+
tests = "pytest"
122+
123+
checks = [
124+
"lint",
125+
"types",
126+
"tests"
127+
]
128+
129+
[[tool.hatch.envs.test.matrix]]
130+
python = ["3.10", "3.11", "3.12", "3.13", "3.14"]

requirements-dev.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
-r requirements-test.txt
2+
auto-changelog
23
git-pylint-commit-hook
4+
hatch
35
ipython
46
pip
57
psutil
6-
twine
7-
auto-changelog

requirements-test.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ docutils
33
mypy
44
pytest
55
pytest-cov
6-
pytest-flake8
76
pytest-mypy
7+
pytest-xdist
88
rich
99
rst2html5
1010
ruff
1111
setuptools
1212
sphinx
1313
sphinx-rtd-theme
14-
tox

test/grammar/parameter_test.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,12 @@ def rule_all(self, ast, p1, k1):
178178
self.assertEqual(['a', 'b', 'c'], ast)
179179

180180
code = codegen(m)
181-
import codecs
182181
module_name = 'tc36unicharstest'
183182
temp_dir = pathlib.Path(tempfile.mkdtemp()) / module_name
184183
temp_dir.mkdir(exist_ok=True)
185184
py_file_path = temp_dir / f'{module_name}.py'
186185

187-
with codecs.open(py_file_path, 'w', 'utf-8') as f:
186+
with pathlib.Path(py_file_path).open('w') as f:
188187
f.write(code)
189188
try:
190189
sys.path.append(str(temp_dir))

test/grammar/syntax_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,5 +418,5 @@ def test_deprecated_comments_override_failures(comment, option):
418418
{comment}
419419
a
420420
"""
421-
with pytest.raises(AttributeError, match=""):
421+
with pytest.raises(AttributeError):
422422
tool.parse(grammar, text, **option)

0 commit comments

Comments
 (0)