diff --git a/.gitignore b/.gitignore index 92854384ce0..508d57ca9d6 100644 --- a/.gitignore +++ b/.gitignore @@ -20,4 +20,5 @@ reflex.db .env.* node_modules package-lock.json -*.pyi \ No newline at end of file +*.pyi +.pre-commit-config.yaml \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml deleted file mode 100644 index 801438f22ee..00000000000 --- a/.pre-commit-config.yaml +++ /dev/null @@ -1,48 +0,0 @@ -fail_fast: true - -repos: - - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.11.8 - hooks: - - id: ruff-format - args: [reflex, tests] - - id: ruff - args: ["--fix", "--exit-non-zero-on-fix"] - exclude: "^integration/benchmarks/" - - - repo: https://github.com/codespell-project/codespell - rev: v2.4.1 - hooks: - - id: codespell - args: ["reflex"] - additional_dependencies: - - tomli - - # Run pyi check before pyright because pyright can fail if pyi files are wrong. - - repo: local - hooks: - - 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 - - - repo: https://github.com/RobertCraigie/pyright-python - rev: v1.1.400 - hooks: - - id: pyright - args: [reflex, tests] - language: system - - - repo: https://github.com/terrencepreilly/darglint - rev: v1.8.1 - hooks: - - id: darglint - exclude: "^reflex/reflex.py" - - repo: https://github.com/pre-commit/mirrors-prettier - rev: f62a70a3a7114896b062de517d72829ea1c884b6 - hooks: - - id: prettier - require_serial: true diff --git a/pyproject.toml b/pyproject.toml index e2b6a9793c0..496210cfb49 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -73,7 +73,7 @@ artifacts = ["*.pyi"] [tool.hatch.build.hooks.custom] path = "scripts/hatch_build.py" -dependencies = ["plotly", "ruff"] +dependencies = ["plotly", "ruff", "pre_commit", "toml"] require-runtime-dependencies = true [tool.pyright] @@ -149,7 +149,7 @@ dev = [ "pillow >=11", "playwright >=1.51", "plotly >=6.0", - "pre-commit >=4.2", + "pre-commit ==4.2.0", "psycopg[binary] >=3.2", "pyright >=1.1.400", "pytest >=8.3", @@ -165,6 +165,7 @@ dev = [ "ruff >=0.11", "selenium >=4.31", "starlette-admin >=0.14", + "toml >=0.10.2", "uvicorn >=0.34.0", ] @@ -206,3 +207,53 @@ exclude_also = [ [tool.coverage.html] directory = "coverage_html_report" + +[tool.pre-commit] +fail_fast = true + +[[tool.pre-commit.repos]] +repo = "https://github.com/astral-sh/ruff-pre-commit" +rev = "v0.11.8" +hooks = [ + { id = "ruff-format", args = [ + "reflex", + "tests", + ] }, + { id = "ruff", args = [ + "--fix", + "--exit-non-zero-on-fix", + ], exclude = "^integration/benchmarks/" }, +] + +[[tool.pre-commit.repos]] +repo = "https://github.com/codespell-project/codespell" +rev = "v2.4.1" +hooks = [ + { id = "codespell", args = [ + "reflex", + ], additional_dependencies = [ + "tomli", + ] }, +] + +# Run pyi check before pyright because pyright can fail if pyi files are wrong. +[[tool.pre-commit.repos]] +repo = "local" +hooks = [ + { 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" }, +] + +[[tool.pre-commit.repos]] +repo = "https://github.com/RobertCraigie/pyright-python" +rev = "v1.1.400" +hooks = [{ id = "pyright", args = ["reflex", "tests"], language = "system" }] + +[[tool.pre-commit.repos]] +repo = "https://github.com/terrencepreilly/darglint" +rev = "v1.8.1" +hooks = [{ id = "darglint", exclude = "^reflex/reflex.py" }] + +[[tool.pre-commit.repos]] +repo = "https://github.com/pre-commit/mirrors-prettier" +rev = "f62a70a3a7114896b062de517d72829ea1c884b6" +hooks = [{ id = "prettier", require_serial = true }] diff --git a/scripts/hatch_build.py b/scripts/hatch_build.py index 028e0a8054a..b4b67e0cfe6 100644 --- a/scripts/hatch_build.py +++ b/scripts/hatch_build.py @@ -1,5 +1,6 @@ """Custom build hook for Hatch.""" +import importlib.util import pathlib import subprocess import sys @@ -37,6 +38,22 @@ def finalize( if self.marker().exists(): return + if importlib.util.find_spec("pre_commit") and importlib.util.find_spec("toml"): + import json + + import toml + import yaml + + reflex_dir = pathlib.Path(__file__).parent.parent + pre_commit_config = json.loads( + json.dumps( + toml.load(reflex_dir / "pyproject.toml")["tool"]["pre-commit"] + ) + ) + (reflex_dir / ".pre-commit-config.yaml").write_text( + yaml.dump(pre_commit_config), encoding="utf-8" + ) + if not (pathlib.Path(self.root) / "scripts").exists(): return diff --git a/uv.lock b/uv.lock index d121693bfcc..69390a1bd62 100644 --- a/uv.lock +++ b/uv.lock @@ -1572,6 +1572,7 @@ dev = [ { name = "ruff" }, { name = "selenium" }, { name = "starlette-admin" }, + { name = "toml" }, { name = "uvicorn" }, ] @@ -1609,7 +1610,7 @@ dev = [ { name = "pillow", specifier = ">=11" }, { name = "playwright", specifier = ">=1.51" }, { name = "plotly", specifier = ">=6.0" }, - { name = "pre-commit", specifier = ">=4.2" }, + { name = "pre-commit", specifier = "==4.2.0" }, { name = "psycopg", extras = ["binary"], specifier = ">=3.2" }, { name = "pyright", specifier = ">=1.1.400" }, { name = "pytest", specifier = ">=8.3" }, @@ -1625,6 +1626,7 @@ dev = [ { name = "ruff", specifier = ">=0.11" }, { name = "selenium", specifier = ">=4.31" }, { name = "starlette-admin", specifier = ">=0.14" }, + { name = "toml", specifier = ">=0.10.2" }, { name = "uvicorn", specifier = ">=0.34.0" }, ] @@ -1858,6 +1860,15 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/a6/a5/c0b6468d3824fe3fde30dbb5e1f687b291608f9473681bbf7dabbf5a87d7/text_unidecode-1.3-py2.py3-none-any.whl", hash = "sha256:1311f10e8b895935241623731c2ba64f4c455287888b18189350b67134a822e8", size = 78154, upload-time = "2019-08-30T21:37:03.543Z" }, ] +[[package]] +name = "toml" +version = "0.10.2" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/be/ba/1f744cdc819428fc6b5084ec34d9b30660f6f9daaf70eead706e3203ec3c/toml-0.10.2.tar.gz", hash = "sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f", size = 22253, upload-time = "2020-11-01T01:40:22.204Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/44/6f/7120676b6d73228c96e17f1f794d8ab046fc910d781c8d151120c3f1569e/toml-0.10.2-py2.py3-none-any.whl", hash = "sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b", size = 16588, upload-time = "2020-11-01T01:40:20.672Z" }, +] + [[package]] name = "tomli" version = "2.2.1"