Skip to content

Commit ae66ab6

Browse files
authored
fix infinite loop in pyi generator (#5354)
1 parent 89b47e0 commit ae66ab6

File tree

1 file changed

+32
-27
lines changed

1 file changed

+32
-27
lines changed

reflex/utils/pyi_generator.py

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030

3131
PWD = Path.cwd()
3232

33+
PYI_HASHES = "pyi_hashes.json"
34+
3335
EXCLUDED_FILES = [
3436
"app.py",
3537
"component.py",
@@ -1264,45 +1266,48 @@ def scan_all(
12641266
file_parent = file_path.parent
12651267
while len(file_parent.parts) > len(top_dir.parts):
12661268
file_parent = file_parent.parent
1269+
while len(top_dir.parts) > len(file_parent.parts):
1270+
top_dir = top_dir.parent
12671271
while not file_parent.samefile(top_dir):
12681272
file_parent = file_parent.parent
12691273
top_dir = top_dir.parent
12701274

1271-
pyi_hashes_file = top_dir / "pyi_hashes.json"
1272-
if not pyi_hashes_file.exists():
1273-
while top_dir.parent and not (top_dir / "pyi_hashes.json").exists():
1274-
top_dir = top_dir.parent
1275-
another_pyi_hashes_file = top_dir / "pyi_hashes.json"
1276-
if another_pyi_hashes_file.exists():
1277-
pyi_hashes_file = another_pyi_hashes_file
1278-
1279-
pyi_hashes_file.write_text(
1280-
json.dumps(
1281-
dict(
1282-
zip(
1283-
[
1284-
f.relative_to(pyi_hashes_file.parent).as_posix()
1285-
for f in file_paths
1286-
],
1287-
hashes,
1288-
strict=True,
1289-
)
1290-
),
1291-
indent=2,
1292-
sort_keys=True,
1275+
while (
1276+
not top_dir.samefile(top_dir.parent)
1277+
and not (top_dir / PYI_HASHES).exists()
1278+
):
1279+
top_dir = top_dir.parent
1280+
1281+
pyi_hashes_file = top_dir / PYI_HASHES
1282+
1283+
if pyi_hashes_file.exists():
1284+
pyi_hashes_file.write_text(
1285+
json.dumps(
1286+
dict(
1287+
zip(
1288+
[
1289+
f.relative_to(pyi_hashes_file.parent).as_posix()
1290+
for f in file_paths
1291+
],
1292+
hashes,
1293+
strict=True,
1294+
)
1295+
),
1296+
indent=2,
1297+
sort_keys=True,
1298+
)
1299+
+ "\n",
12931300
)
1294-
+ "\n",
1295-
)
12961301
elif file_paths:
12971302
file_paths = list(map(Path, file_paths))
12981303
pyi_hashes_parent = file_paths[0].parent
12991304
while (
1300-
pyi_hashes_parent.parent
1301-
and not (pyi_hashes_parent / "pyi_hashes.json").exists()
1305+
not pyi_hashes_parent.samefile(pyi_hashes_parent.parent)
1306+
and not (pyi_hashes_parent / PYI_HASHES).exists()
13021307
):
13031308
pyi_hashes_parent = pyi_hashes_parent.parent
13041309

1305-
pyi_hashes_file = pyi_hashes_parent / "pyi_hashes.json"
1310+
pyi_hashes_file = pyi_hashes_parent / PYI_HASHES
13061311
if pyi_hashes_file.exists():
13071312
pyi_hashes = json.loads(pyi_hashes_file.read_text())
13081313
for file_path, hashed_content in zip(

0 commit comments

Comments
 (0)