Skip to content

Commit 4b35890

Browse files
authored
support selecting ty as the type checker (#70)
1 parent acefc8e commit 4b35890

File tree

8 files changed

+33
-9
lines changed

8 files changed

+33
-9
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ This is a modern Cookiecutter template that can be used to initiate a Python pro
1515
- Supports both [src and flat layout](https://packaging.python.org/en/latest/discussions/src-layout-vs-flat-layout/).
1616
- CI/CD with [GitHub Actions](https://github.com/features/actions)
1717
- Pre-commit hooks with [pre-commit](https://pre-commit.com/)
18-
- Code quality with [ruff](https://github.com/charliermarsh/ruff), [mypy](https://mypy.readthedocs.io/en/stable/) and [deptry](https://github.com/fpgmaas/deptry/).
18+
- Code quality with [ruff](https://github.com/charliermarsh/ruff), [mypy](https://mypy.readthedocs.io/en/stable/)/[ty](https://docs.astral.sh/ty/) and [deptry](https://github.com/fpgmaas/deptry/).
1919
- Publishing to [PyPI](https://pypi.org) by creating a new release on GitHub
2020
- Testing and coverage with [pytest](https://docs.pytest.org/en/7.1.x/) and [codecov](https://about.codecov.io/)
2121
- Documentation with [MkDocs](https://www.mkdocs.org/)

cookiecutter.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
"y",
3838
"n"
3939
],
40+
"type_checker": [
41+
"mypy",
42+
"ty"
43+
],
4044
"open_source_license": [
4145
"MIT license",
4246
"BSD license",

docs/features/linting.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ preview = true
6767

6868
# mypy
6969

70-
[mypy](https://mypy.readthedocs.io/en/stable/) is used for static type checking, and it's configuration and can be edited in `pyproject.toml`.
70+
[mypy](https://mypy.readthedocs.io/en/stable/) is used for static type checking, and it's configuration can be edited in `pyproject.toml`.
7171

7272
```toml
7373
[tool.mypy]
@@ -85,6 +85,16 @@ exclude = [
8585
]
8686
```
8787

88+
# ty
89+
90+
[ty](https://docs.astral.sh/ty/) is an extremely fast type checker (and language server) that can be used instead of mypy, and it's configuration can be edited in `pyproject.toml`.
91+
92+
```toml
93+
[tool.ty.environment]
94+
python = "./.venv"
95+
python-version = "3.9"
96+
```
97+
8898
# deptry
8999

90100
[deptry](https://github.com/fpgmaas/deptry) is used to check the code for dependency issues, and it can be configured by adding a `[tool.deptry]` section in `pyproject.toml`. For more information, see [this section](https://deptry.com/usage/#configuration) documentation of deptry.

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ This is a modern Cookiecutter template that can be used to initiate a Python pro
1616
- Supports both [src and flat layout](https://packaging.python.org/en/latest/discussions/src-layout-vs-flat-layout/).
1717
- CI/CD with [GitHub Actions](https://github.com/features/actions)
1818
- Pre-commit hooks with [pre-commit](https://pre-commit.com/)
19-
- Code quality with [ruff](https://github.com/charliermarsh/ruff), [mypy](https://mypy.readthedocs.io/en/stable/) and [deptry](https://github.com/fpgmaas/deptry/).
19+
- Code quality with [ruff](https://github.com/charliermarsh/ruff), [mypy](https://mypy.readthedocs.io/en/stable/)/[ty](https://docs.astral.sh/ty/) and [deptry](https://github.com/fpgmaas/deptry/).
2020
- Publishing to [PyPI](https://pypi.org) by creating a new release on GitHub
2121
- Testing and coverage with [pytest](https://docs.pytest.org/en/7.1.x/) and [codecov](https://about.codecov.io/)
2222
- Documentation with [MkDocs](https://www.mkdocs.org/)

{{cookiecutter.project_name}}/.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
run: uv run python -m pytest tests {% if cookiecutter.codecov == "y" %}--cov --cov-config=pyproject.toml --cov-report=xml{%- endif %}
4848

4949
- name: Check typing
50-
run: uv run mypy
50+
run: uv run {% if cookiecutter.type_checker == "mypy" %}mypy{% else %}ty check{% endif %}
5151

5252
{% if cookiecutter.codecov == "y" %}
5353
- name: Upload coverage reports to Codecov with GitHub Action on Python 3.11

{{cookiecutter.project_name}}/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ check: ## Run code quality tools.
1010
@uv lock --locked
1111
@echo "🚀 Linting code: Running pre-commit"
1212
@uv run pre-commit run -a
13-
@echo "🚀 Static type checking: Running mypy"
14-
@uv run mypy
13+
@echo "🚀 Static type checking: Running {{ cookiecutter.type_checker }}"
14+
@uv run {% if cookiecutter.type_checker == "mypy" %}mypy{% else %}ty check{% endif %}
1515
{%- if cookiecutter.deptry == 'y' %}
1616
@echo "🚀 Checking for obsolete dependencies: Running deptry"
1717
@uv run deptry {% if cookiecutter.layout == "src" %}src{% else %}.{% endif %}

{{cookiecutter.project_name}}/pyproject.toml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ dev = [
2929
"pre-commit>=2.20.0",
3030
"tox-uv>=1.11.3",
3131
{% if cookiecutter.deptry == 'y' %}"deptry>=0.23.0",{% endif %}
32-
"mypy>=0.991",
32+
{% if cookiecutter.type_checker == "mypy" -%}
33+
"mypy>=0.991",
34+
{%- elif cookiecutter.type_checker == "ty" -%}
35+
"ty>=0.0.1a16",
36+
{%- endif %}
3337
{% if cookiecutter.codecov == 'y' %}"pytest-cov>=4.0.0",{% endif %}
3438
"ruff>=0.11.5",
3539
{% if cookiecutter.mkdocs == 'y' %}"mkdocs>=1.4.2",
@@ -49,6 +53,7 @@ packages = ["src/{{cookiecutter.project_slug}}"]
4953
packages = ["{{cookiecutter.project_slug}}"]
5054
{%- endif %}
5155

56+
{% if cookiecutter.type_checker == "mypy" -%}
5257
[tool.mypy]
5358
files = [
5459
{%- if cookiecutter.layout == "src" -%}
@@ -64,6 +69,11 @@ check_untyped_defs = true
6469
warn_return_any = true
6570
warn_unused_ignores = true
6671
show_error_codes = true
72+
{%- else -%}
73+
[tool.ty.environment]
74+
python = "./.venv"
75+
python-version = "3.9"
76+
{%- endif %}
6777

6878
[tool.pytest.ini_options]
6979
testpaths = ["tests"]
@@ -119,7 +129,7 @@ ignore = [
119129
[tool.ruff.format]
120130
preview = true
121131

122-
{% if cookiecutter.codecov == "y"-%}
132+
{% if cookiecutter.codecov == "y" -%}
123133
[tool.coverage.report]
124134
skip_empty = true
125135

{{cookiecutter.project_name}}/tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ allowlist_externals = uv
1616
commands =
1717
uv sync --python {envpython}
1818
uv run python -m pytest --doctest-modules tests --cov --cov-config=pyproject.toml --cov-report=xml
19-
mypy
19+
{% if cookiecutter.type_checker == "mypy" %}mypy{% else %}ty check{% endif %}

0 commit comments

Comments
 (0)