Skip to content

Commit 8d1511e

Browse files
authored
dev: pre-commit hook to standardize toml format (#2186)
1 parent 8dbe44a commit 8d1511e

4 files changed

Lines changed: 81 additions & 35 deletions

File tree

.pre-commit-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,8 @@ repos:
5050
hooks:
5151
- id: yamlfmt
5252
args: [-formatter, retain_line_breaks=true]
53+
54+
- repo: https://github.com/tombi-toml/tombi-pre-commit
55+
rev: v0.10.6
56+
hooks:
57+
- id: tombi-format

pyproject.toml

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ classifiers = [
1111
"Intended Audience :: Education",
1212
"Intended Audience :: Science/Research",
1313
"License :: OSI Approved :: Apache Software License",
14-
"Operating System :: POSIX :: Linux",
1514
"Operating System :: MacOS :: MacOS X",
15+
"Operating System :: POSIX :: Linux",
1616
"Programming Language :: Python :: 3.11",
1717
"Programming Language :: Python :: 3.12",
1818
"Programming Language :: Python :: 3.13",
1919
"Programming Language :: Python :: 3.14",
2020
]
21-
keywords = ["probabilistic", "machine learning", "bayesian", "statistics"]
21+
keywords = ["bayesian", "machine learning", "probabilistic", "statistics"]
2222
dependencies = [
2323
"jax>=0.7.0",
2424
"jaxlib>=0.7.0",
@@ -47,11 +47,6 @@ requires = ["setuptools>=61", "wheel"]
4747
build-backend = "setuptools.build_meta"
4848

4949
[dependency-groups]
50-
ci = [
51-
"coverage>=7.13.5",
52-
"coveralls>=4.1.0",
53-
"funsor",
54-
]
5550
dev = [
5651
"equinox",
5752
"flax",
@@ -61,19 +56,24 @@ dev = [
6156
"jaxns>=2.6.3,<=2.6.9",
6257
"matplotlib",
6358
"optax>=0.0.6",
64-
"pylab-sdk", # jaxns dependency
59+
"pylab-sdk", # jaxns dependency
6560
"pytest-cov",
66-
"pyyaml", # flax dependency
67-
"requests", # pylab dependency
61+
"pyyaml", # flax dependency
62+
"requests", # pylab dependency
6863
"tfp-nightly",
6964
]
65+
ci = [
66+
"coverage>=7.13.5",
67+
"coveralls>=4.1.0",
68+
"funsor",
69+
]
7070
docs = [
71-
"ipython", # sphinx needs this to render codes
71+
"ipython", # sphinx needs this to render codes
7272
"nbsphinx>=0.8.9",
7373
"readthedocs-sphinx-search>=0.3.2",
74-
"sphinx-rtd-theme",
75-
"sphinx-gallery",
7674
"sphinx>=5",
75+
"sphinx-gallery",
76+
"sphinx-rtd-theme",
7777
]
7878
examples = [
7979
"arviz",
@@ -142,10 +142,10 @@ extend-include = ["*.ipynb"]
142142
[tool.ruff.lint]
143143
select = ["ANN", "E", "F", "I", "W"]
144144
ignore = [
145-
"ANN002", # missing args type annotation
146-
"ANN003", # missing kwargs type annotation
147-
"ANN204", # missing type annotation for __call__
148-
"ANN401", # function arguments are annotated with a more specific type than Any.
145+
"ANN002", # missing args type annotation
146+
"ANN003", # missing kwargs type annotation
147+
"ANN204", # missing type annotation for __call__
148+
"ANN401", # function arguments are annotated with a more specific type than Any.
149149
"E203",
150150
]
151151

@@ -175,7 +175,7 @@ line-ending = "auto"
175175
[tool.ruff.lint.per-file-ignores]
176176
"!numpyro/{diagnostics.py,handlers.py,optim.py,patch.py,primitives.py,infer/elbo.py,distributions/distribution.py}" = [
177177
"ANN",
178-
] # require type annotations in typed modules
178+
] # require type annotations in typed modules
179179

180180
[tool.ruff.lint.extend-per-file-ignores]
181181
"numpyro/contrib/tfp/distributions.py" = ["F811"]
@@ -198,7 +198,6 @@ section-order = [
198198
[tool.ruff.lint.isort.sections]
199199
known-jax = ["flax", "jax", "optax", "tensorflow_probability"]
200200

201-
202201
[tool.pytest.ini_options]
203202
addopts = ["-v", "--color=yes"]
204203
filterwarnings = [
@@ -225,8 +224,8 @@ ignore_missing_imports = true
225224
[[tool.mypy.overrides]]
226225
module = [
227226
"examples.datasets",
228-
"numpyro.contrib.control_flow.*", # types missing
229-
"numpyro.contrib.funsor.*", # types missing
227+
"numpyro.contrib.control_flow.*", # types missing
228+
"numpyro.contrib.funsor.*", # types missing
230229
"numpyro.contrib.hsgp.*",
231230
"numpyro.contrib.stochastic_support.*",
232231
"numpyro.diagnostics.*",

tombi.toml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
toml-version = "v1.0.0"
2+
3+
[files]
4+
include = ["**/*.toml"]
5+
exclude = [".cache/**/*.toml"]
6+
7+
[format]
8+
[format.rules]
9+
array-bracket-space-width = 0
10+
array-comma-space-width = 1
11+
date-time-delimiter = "T"
12+
indent-style = "space"
13+
indent-sub-tables = false
14+
indent-table-key-value-pairs = false
15+
indent-width = 4
16+
inline-table-brace-space-width = 1
17+
inline-table-comma-space-width = 1
18+
key-value-equals-sign-alignment = false
19+
key-value-equals-sign-space-width = 1
20+
line-ending = "lf"
21+
line-width = 80
22+
string-quote-style = "double"
23+
trailing-comment-alignment = true
24+
trailing-comment-space-width = 2
25+
26+
[lint]
27+
[lint.rules]
28+
dotted-keys-out-of-order = "warn"
29+
key-empty = "warn"
30+
tables-out-of-order = "off"
31+
32+
[lsp]
33+
code-action.enabled = true
34+
completion.enabled = true
35+
diagnostic.enabled = true
36+
document-link.enabled = true
37+
formatting.enabled = true
38+
goto-declaration.enabled = true
39+
goto-definition.enabled = true
40+
goto-type-definition.enabled = true
41+
hover.enabled = true
42+
workspace-diagnostic.enabled = true

ty.toml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@ python-version = "3.13"
66
# To match mypy's "passing" behavior, we disable ty's stricter rules that mypy doesn't catch.
77
[rules]
88
unresolved-import = "ignore"
9-
unused-ignore-comment = "ignore" # Needed for mypy compatibility
9+
unused-ignore-comment = "ignore" # Needed for mypy compatibility
1010
# Rules that ty catches but mypy doesn't (needed to match mypy's passing behavior)
11-
invalid-type-form = "ignore" # ParamSpec usage patterns
12-
not-subscriptable = "ignore" # ModelT[P] subscripting
13-
invalid-assignment = "ignore" # Implicit shadowing
14-
possibly-missing-attribute = "warn" # Nullable attribute access
15-
not-iterable = "ignore" # Iterator type inference
16-
invalid-argument-type = "ignore" # Stricter arg type checking
17-
no-matching-overload = "ignore" # Overload resolution
18-
invalid-return-type = "ignore" # Return type mismatches
19-
unresolved-attribute = "ignore" # Attribute resolution
20-
invalid-method-override = "ignore" # Liskov substitution violations
21-
call-non-callable = "ignore" # Callable type inference
22-
unsupported-operator = "ignore" # Operator type checking
11+
invalid-type-form = "ignore" # ParamSpec usage patterns
12+
not-subscriptable = "ignore" # ModelT[P] subscripting
13+
invalid-assignment = "ignore" # Implicit shadowing
14+
possibly-missing-attribute = "warn" # Nullable attribute access
15+
not-iterable = "ignore" # Iterator type inference
16+
invalid-argument-type = "ignore" # Stricter arg type checking
17+
no-matching-overload = "ignore" # Overload resolution
18+
invalid-return-type = "ignore" # Return type mismatches
19+
unresolved-attribute = "ignore" # Attribute resolution
20+
invalid-method-override = "ignore" # Liskov substitution violations
21+
call-non-callable = "ignore" # Callable type inference
22+
unsupported-operator = "ignore" # Operator type checking
2323
too-many-positional-arguments = "ignore" # Argument count checking
2424

2525
# Check the same modules mypy checks (ignore_errors = false in pyproject.toml)
@@ -39,4 +39,4 @@ include = [
3939
"numpyro/util.py",
4040
"numpyro/distributions/transforms.py",
4141
]
42-
respect-ignore-files = true
42+
respect-ignore-files = true

0 commit comments

Comments
 (0)