Quellcode durchsuchen

use patch to precommit to use pyproject

Khaleel Al-Adhami vor 1 Woche
Ursprung
Commit
faf594f389
3 geänderte Dateien mit 56 neuen und 1 gelöschten Zeilen
  1. 3 1
      pyproject.toml
  2. 31 0
      scripts/hatch_build.py
  3. 22 0
      uv.lock

+ 3 - 1
pyproject.toml

@@ -73,7 +73,7 @@ artifacts = ["*.pyi"]
 
 
 [tool.hatch.build.hooks.custom]
 [tool.hatch.build.hooks.custom]
 path = "scripts/hatch_build.py"
 path = "scripts/hatch_build.py"
-dependencies = ["plotly", "ruff"]
+dependencies = ["plotly", "ruff", "pre_commit", "diff_match_patch"]
 require-runtime-dependencies = true
 require-runtime-dependencies = true
 
 
 [tool.pyright]
 [tool.pyright]
@@ -142,6 +142,7 @@ dev = [
   "asynctest >=0.13",
   "asynctest >=0.13",
   "darglint >=1.8",
   "darglint >=1.8",
   "dill >=0.3",
   "dill >=0.3",
+  "diff-match-patch >=20241021",
   "hatchling >=1.27",
   "hatchling >=1.27",
   "libsass >=0.23",
   "libsass >=0.23",
   "numpy >=2.2",
   "numpy >=2.2",
@@ -165,6 +166,7 @@ dev = [
   "ruff >=0.11",
   "ruff >=0.11",
   "selenium >=4.31",
   "selenium >=4.31",
   "starlette-admin >=0.14",
   "starlette-admin >=0.14",
+  "toml >=0.10.2",
   "uvicorn >=0.34.0",
   "uvicorn >=0.34.0",
 ]
 ]
 
 

+ 31 - 0
scripts/hatch_build.py

@@ -1,5 +1,6 @@
 """Custom build hook for Hatch."""
 """Custom build hook for Hatch."""
 
 
+import importlib.util
 import pathlib
 import pathlib
 import subprocess
 import subprocess
 import sys
 import sys
@@ -37,6 +38,36 @@ class CustomBuilder(BuildHookInterface):
         if self.marker().exists():
         if self.marker().exists():
             return
             return
 
 
+        if importlib.util.find_spec("pre_commit"):
+            import pre_commit.yaml
+            from diff_match_patch import diff_match_patch
+
+            patch = """@@ -82,16 +82,28 @@
+ ort yaml
++%0Aimport toml
+ %0A%0ALoader
+@@ -209,24 +209,28 @@
+ der=Loader)%0A
++def 
+ yaml_load = 
+@@ -226,37 +226,145 @@
+ aml_load
+- = functools.partial(
++(stream):%0A    try:%0A        return toml.loads(stream).get(%22tool%22, %7B%7D).get(%22pre-commit%22, %7B%7D)%0A    except ValueError:%0A        return 
+ yaml.loa
+@@ -364,16 +364,23 @@
+ aml.load
++(stream
+ , Loader
+"""  # noqa: W291
+
+            dmp = diff_match_patch()
+            patches = dmp.patch_fromText(patch)
+            new_text, _ = dmp.patch_apply(
+                patches, pathlib.Path(pre_commit.yaml.__file__).read_text()
+            )
+            pathlib.Path(pre_commit.yaml.__file__).write_text(new_text)
+
         if not (pathlib.Path(self.root) / "scripts").exists():
         if not (pathlib.Path(self.root) / "scripts").exists():
             return
             return
 
 

+ 22 - 0
uv.lock

@@ -312,6 +312,15 @@ wheels = [
     { url = "https://files.pythonhosted.org/packages/69/28/85d1e0396d64422c5218d68e5cdcc53153aa8a2c83c7dbc3ee1502adf3a1/darglint-1.8.1-py3-none-any.whl", hash = "sha256:5ae11c259c17b0701618a20c3da343a3eb98b3bc4b5a83d31cdd94f5ebdced8d", size = 120767, upload-time = "2021-10-18T03:40:35.034Z" },
     { url = "https://files.pythonhosted.org/packages/69/28/85d1e0396d64422c5218d68e5cdcc53153aa8a2c83c7dbc3ee1502adf3a1/darglint-1.8.1-py3-none-any.whl", hash = "sha256:5ae11c259c17b0701618a20c3da343a3eb98b3bc4b5a83d31cdd94f5ebdced8d", size = 120767, upload-time = "2021-10-18T03:40:35.034Z" },
 ]
 ]
 
 
+[[package]]
+name = "diff-match-patch"
+version = "20241021"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/0e/ad/32e1777dd57d8e85fa31e3a243af66c538245b8d64b7265bec9a61f2ca33/diff_match_patch-20241021.tar.gz", hash = "sha256:beae57a99fa48084532935ee2968b8661db861862ec82c6f21f4acdd6d835073", size = 39962, upload-time = "2024-10-21T19:41:21.094Z" }
+wheels = [
+    { url = "https://files.pythonhosted.org/packages/f7/bb/2aa9b46a01197398b901e458974c20ed107935c26e44e37ad5b0e5511e44/diff_match_patch-20241021-py3-none-any.whl", hash = "sha256:93cea333fb8b2bc0d181b0de5e16df50dd344ce64828226bda07728818936782", size = 43252, upload-time = "2024-10-21T19:41:19.914Z" },
+]
+
 [[package]]
 [[package]]
 name = "dill"
 name = "dill"
 version = "0.4.0"
 version = "0.4.0"
@@ -1548,6 +1557,7 @@ dependencies = [
 dev = [
 dev = [
     { name = "asynctest" },
     { name = "asynctest" },
     { name = "darglint" },
     { name = "darglint" },
+    { name = "diff-match-patch" },
     { name = "dill" },
     { name = "dill" },
     { name = "hatchling" },
     { name = "hatchling" },
     { name = "libsass" },
     { name = "libsass" },
@@ -1572,6 +1582,7 @@ dev = [
     { name = "ruff" },
     { name = "ruff" },
     { name = "selenium" },
     { name = "selenium" },
     { name = "starlette-admin" },
     { name = "starlette-admin" },
+    { name = "toml" },
     { name = "uvicorn" },
     { name = "uvicorn" },
 ]
 ]
 
 
@@ -1601,6 +1612,7 @@ requires-dist = [
 dev = [
 dev = [
     { name = "asynctest", specifier = ">=0.13" },
     { name = "asynctest", specifier = ">=0.13" },
     { name = "darglint", specifier = ">=1.8" },
     { name = "darglint", specifier = ">=1.8" },
+    { name = "diff-match-patch", specifier = ">=20241021" },
     { name = "dill", specifier = ">=0.3" },
     { name = "dill", specifier = ">=0.3" },
     { name = "hatchling", specifier = ">=1.27" },
     { name = "hatchling", specifier = ">=1.27" },
     { name = "libsass", specifier = ">=0.23" },
     { name = "libsass", specifier = ">=0.23" },
@@ -1625,6 +1637,7 @@ dev = [
     { name = "ruff", specifier = ">=0.11" },
     { name = "ruff", specifier = ">=0.11" },
     { name = "selenium", specifier = ">=4.31" },
     { name = "selenium", specifier = ">=4.31" },
     { name = "starlette-admin", specifier = ">=0.14" },
     { name = "starlette-admin", specifier = ">=0.14" },
+    { name = "toml", specifier = ">=0.10.2" },
     { name = "uvicorn", specifier = ">=0.34.0" },
     { name = "uvicorn", specifier = ">=0.34.0" },
 ]
 ]
 
 
@@ -1858,6 +1871,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" },
     { 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]]
 [[package]]
 name = "tomli"
 name = "tomli"
 version = "2.2.1"
 version = "2.2.1"