Skip to content

Commit f220e5b

Browse files
committed
feat: VCS versioning and mypy
1 parent bad9c6d commit f220e5b

File tree

12 files changed

+56
-31
lines changed

12 files changed

+56
-31
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,6 @@ cython_debug/
126126

127127
# Code editor files and folders
128128
.vscode/
129+
130+
# hatch-vcs
131+
src/pybamm_cookiecutter/_version.py

.pre-commit-config.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ repos:
3737
rev: v0.0.281
3838
hooks:
3939
- id: ruff
40+
files: "^(src/pybamm_cookiecutter|tests$)"
4041
args: ["--fix", "--show-fixes"]
4142

4243
# Documentation files
@@ -61,3 +62,11 @@ repos:
6162
hooks:
6263
- id: nbqa-ruff
6364
additional_dependencies: [ruff==0.0.281]
65+
66+
# mypy
67+
68+
- repo: https://github.com/pre-commit/mirrors-mypy
69+
rev: v1.4.1
70+
hooks:
71+
- id: mypy
72+
files: "^(src/pybamm_cookiecutter|tests$)"

noxfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
nox.options.reuse_existing_virtualenvs = True
55

66
@nox.session(name="docs")
7-
def build_docs(session):
7+
def build_docs(session: nox.Session) -> None:
88
"""Build the documentation and load it in a browser tab, rebuilding on changes."""
99
envbindir = session.bin
1010
session.install("-e", ".[docs]")

pyproject.toml

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[build-system]
2-
requires = ["hatchling"]
2+
requires = ["hatchling", "hatch-vcs"]
33
build-backend = "hatchling.build"
44

55
[project]
@@ -60,11 +60,29 @@ Discussions = "https://github.com/pybamm-team/pybamm-cookiecutter/discussions"
6060
Changelog = "https://github.com/pybamm-team/pybamm-cookiecutter/releases"
6161

6262
[tool.hatch]
63-
version.path = "src/pybamm_cookiecutter/__init__.py"
63+
version.source = "vcs"
64+
build.hooks.vcs.version-file = "src/pybamm_cookiecutter/_version.py"
6465
envs.default.dependencies = [
6566
"pybamm",
6667
]
6768

69+
[tool.mypy]
70+
packages = [
71+
"src/pybamm_cookiecutter",
72+
"tests"
73+
]
74+
python_version = "3.8"
75+
strict = true
76+
warn_return_any = false
77+
show_error_codes = true
78+
enable_error_code = [
79+
"ignore-without-code",
80+
"truthy-bool",
81+
"redundant-expr",
82+
]
83+
disallow_untyped_defs = false
84+
disallow_untyped_calls = false
85+
6886
[tool.coverage]
6987
run.source = ["pybamm_cookiecutter"]
7088
port.exclude_lines = [
@@ -97,18 +115,7 @@ select = [
97115
"NPY", # NumPy specific rules
98116
"PD", # pandas-vet
99117
]
100-
extend-ignore = [
101-
"PLR", # Design related pylint codes
102-
"E501", # Line too long
103-
]
104118
src = ["src"]
105-
unfixable = [
106-
"T20", # Removes print statements
107-
"F841", # Removes unused variables
108-
]
109119
exclude = []
120+
isort.required-imports = ["from __future__ import annotations"]
110121
flake8-unused-arguments.ignore-variadic-names = true
111-
112-
[tool.ruff.per-file-ignores]
113-
"tests/**" = ["T20"]
114-
"noxfile.py" = ["T20"]

src/pybamm_cookiecutter/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
44
pybamm-cookiecutter: A template for creating battery modeling projects based on PyBaMM
55
"""
6+
from __future__ import annotations
67

8+
from ._version import version as __version__
79

8-
__version__ = "0.0.1"
9-
10-
__all__ = ("__version__",)
10+
__all__ : tuple[str] = ("__version__",)

src/pybamm_cookiecutter/py.typed

Whitespace-only changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from __future__ import annotations
2+
3+
version: str
4+
version_tuple: tuple[int, int, int] | tuple[int, int, int, str, str]

tests/test_package.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import pybamm_cookiecutter as m
22

33

4-
def test_version():
4+
def test_version() -> None:
55
assert m.__version__

{{cookiecutter.project_name}}/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,6 @@ Thumbs.db
119119
# Common editor files
120120
*~
121121
*.swp
122+
123+
# hatch-vcs
124+
src/pybamm_cookiecutter/_version.py

{{cookiecutter.project_name}}/pyproject.toml

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
[build-system]
22
{%- if cookiecutter.backend == "hatch" %}
3-
requires = ["hatchling"]
3+
requires = [
4+
"hatchling",
5+
"hatch-vcs"
6+
]
47
build-backend = "hatchling.build"
58
{%- endif %}
69

@@ -73,7 +76,8 @@ Changelog = "{{ cookiecutter.url }}/releases"
7376

7477
{%- if cookiecutter.backend == "hatch" %}
7578
[tool.hatch]
76-
version.path = "src/{{ cookiecutter.__project_slug }}/__init__.py"
79+
version.source = "vcs"
80+
build.hooks.vcs.version-file = "src/{{ cookiecutter.__project_slug }}/_version.py"
7781
envs.default.dependencies = [
7882
"pybamm",
7983
]
@@ -111,18 +115,10 @@ select = [
111115
"NPY", # NumPy specific rules
112116
"PD", # pandas-vet
113117
]
114-
extend-ignore = [
115-
"PLR", # Design related pylint codes
116-
"E501", # Line too long
117-
]
118118
src = ["src"]
119119
unfixable = [
120120
"T20", # Removes print statements
121121
"F841", # Removes unused variables
122122
]
123123
exclude = []
124124
flake8-unused-arguments.ignore-variadic-names = true
125-
126-
[tool.ruff.per-file-ignores]
127-
"tests/**" = ["T20"]
128-
"noxfile.py" = ["T20"]

0 commit comments

Comments
 (0)