Skip to content

Commit 5e98da0

Browse files
authored
Use patch to precommit (#5279)
* use patch to precommit to use pyproject * IT IS POSSIBLE * no need for that one * do old and new * only do things on current working directory * compile the pyproject into the yaml config * dang it darglint
1 parent b3e551c commit 5e98da0

File tree

5 files changed

+84
-52
lines changed

5 files changed

+84
-52
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ reflex.db
2020
.env.*
2121
node_modules
2222
package-lock.json
23-
*.pyi
23+
*.pyi
24+
.pre-commit-config.yaml

.pre-commit-config.yaml

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

pyproject.toml

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ artifacts = ["*.pyi"]
7373

7474
[tool.hatch.build.hooks.custom]
7575
path = "scripts/hatch_build.py"
76-
dependencies = ["plotly", "ruff"]
76+
dependencies = ["plotly", "ruff", "pre_commit", "toml"]
7777
require-runtime-dependencies = true
7878

7979
[tool.pyright]
@@ -149,7 +149,7 @@ dev = [
149149
"pillow >=11",
150150
"playwright >=1.51",
151151
"plotly >=6.0",
152-
"pre-commit >=4.2",
152+
"pre-commit ==4.2.0",
153153
"psycopg[binary] >=3.2",
154154
"pyright >=1.1.400",
155155
"pytest >=8.3",
@@ -165,6 +165,7 @@ dev = [
165165
"ruff >=0.11",
166166
"selenium >=4.31",
167167
"starlette-admin >=0.14",
168+
"toml >=0.10.2",
168169
"uvicorn >=0.34.0",
169170
]
170171

@@ -206,3 +207,53 @@ exclude_also = [
206207

207208
[tool.coverage.html]
208209
directory = "coverage_html_report"
210+
211+
[tool.pre-commit]
212+
fail_fast = true
213+
214+
[[tool.pre-commit.repos]]
215+
repo = "https://github.com/astral-sh/ruff-pre-commit"
216+
rev = "v0.11.8"
217+
hooks = [
218+
{ id = "ruff-format", args = [
219+
"reflex",
220+
"tests",
221+
] },
222+
{ id = "ruff", args = [
223+
"--fix",
224+
"--exit-non-zero-on-fix",
225+
], exclude = "^integration/benchmarks/" },
226+
]
227+
228+
[[tool.pre-commit.repos]]
229+
repo = "https://github.com/codespell-project/codespell"
230+
rev = "v2.4.1"
231+
hooks = [
232+
{ id = "codespell", args = [
233+
"reflex",
234+
], additional_dependencies = [
235+
"tomli",
236+
] },
237+
]
238+
239+
# Run pyi check before pyright because pyright can fail if pyi files are wrong.
240+
[[tool.pre-commit.repos]]
241+
repo = "local"
242+
hooks = [
243+
{ id = "update-pyi-files", name = "update-pyi-files", always_run = true, language = "system", require_serial = true, description = "Update pyi files as needed", entry = "python3 scripts/make_pyi.py" },
244+
]
245+
246+
[[tool.pre-commit.repos]]
247+
repo = "https://github.com/RobertCraigie/pyright-python"
248+
rev = "v1.1.400"
249+
hooks = [{ id = "pyright", args = ["reflex", "tests"], language = "system" }]
250+
251+
[[tool.pre-commit.repos]]
252+
repo = "https://github.com/terrencepreilly/darglint"
253+
rev = "v1.8.1"
254+
hooks = [{ id = "darglint", exclude = "^reflex/reflex.py" }]
255+
256+
[[tool.pre-commit.repos]]
257+
repo = "https://github.com/pre-commit/mirrors-prettier"
258+
rev = "f62a70a3a7114896b062de517d72829ea1c884b6"
259+
hooks = [{ id = "prettier", require_serial = true }]

scripts/hatch_build.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Custom build hook for Hatch."""
22

3+
import importlib.util
34
import pathlib
45
import subprocess
56
import sys
@@ -37,6 +38,22 @@ def finalize(
3738
if self.marker().exists():
3839
return
3940

41+
if importlib.util.find_spec("pre_commit") and importlib.util.find_spec("toml"):
42+
import json
43+
44+
import toml
45+
import yaml
46+
47+
reflex_dir = pathlib.Path(__file__).parent.parent
48+
pre_commit_config = json.loads(
49+
json.dumps(
50+
toml.load(reflex_dir / "pyproject.toml")["tool"]["pre-commit"]
51+
)
52+
)
53+
(reflex_dir / ".pre-commit-config.yaml").write_text(
54+
yaml.dump(pre_commit_config), encoding="utf-8"
55+
)
56+
4057
if not (pathlib.Path(self.root) / "scripts").exists():
4158
return
4259

uv.lock

Lines changed: 12 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)