Parcourir la source

really really make sure that we don't make pyi hashes file if we don't need to (#5083)

* really really make sure that we don't make pyi hashes file if we don't need to

* what if i added something that would cause my local precommit to fail

* blz

* what

* potentially

* bruh

* potentially

* only some

* no clean

* no sparse checkout

* reset avatar

* verbose

* show diff on failure

* write only on diff

* woops

* avatar test

* YEA
Khaleel Al-Adhami il y a 1 mois
Parent
commit
be23309081
2 fichiers modifiés avec 17 ajouts et 8 suppressions
  1. 4 1
      .github/workflows/pre-commit.yml
  2. 13 7
      reflex/utils/pyi_generator.py

+ 4 - 1
.github/workflows/pre-commit.yml

@@ -23,4 +23,7 @@ jobs:
         with:
           python-version: 3.13.2
           run-uv-sync: true
-      - run: uv run pre-commit run --all-files
+      - uses: actions/checkout@v4
+        with:
+          clean: false
+      - run: uv run pre-commit run --all-files --show-diff-on-failure

+ 13 - 7
reflex/utils/pyi_generator.py

@@ -1250,12 +1250,20 @@ class PyiGenerator:
                         file_parent = file_parent.parent
                         top_dir = top_dir.parent
 
-                (top_dir.parent / "pyi_hashes.json").write_text(
+                pyi_hashes_file = top_dir / "pyi_hashes.json"
+                if not pyi_hashes_file.exists():
+                    while top_dir.parent and not (top_dir / "pyi_hashes.json").exists():
+                        top_dir = top_dir.parent
+                    another_pyi_hashes_file = top_dir / "pyi_hashes.json"
+                    if another_pyi_hashes_file.exists():
+                        pyi_hashes_file = another_pyi_hashes_file
+
+                pyi_hashes_file.write_text(
                     json.dumps(
                         dict(
                             zip(
                                 [
-                                    str(f.relative_to(top_dir.parent))
+                                    str(f.relative_to(pyi_hashes_file.parent))
                                     for f in file_paths
                                 ],
                                 hashes,
@@ -1271,11 +1279,8 @@ class PyiGenerator:
                 file_paths = list(map(Path, file_paths))
                 pyi_hashes_parent = file_paths[0].parent
                 while (
-                    not any(
-                        subfile.name == "pyi_hashes.json"
-                        for subfile in pyi_hashes_parent.iterdir()
-                    )
-                    and pyi_hashes_parent.parent
+                    pyi_hashes_parent.parent
+                    and not (pyi_hashes_parent / "pyi_hashes.json").exists()
                 ):
                     pyi_hashes_parent = pyi_hashes_parent.parent
 
@@ -1288,6 +1293,7 @@ class PyiGenerator:
                         pyi_hashes[str(file_path.relative_to(pyi_hashes_parent))] = (
                             hashed_content
                         )
+
                     pyi_hashes_file.write_text(
                         json.dumps(pyi_hashes, indent=2, sort_keys=True) + "\n"
                     )