Skip to content

Commit

Permalink
Check for valid package names in pypi-lock.mjs
Browse files Browse the repository at this point in the history
  • Loading branch information
juntyr committed Feb 16, 2025
1 parent 5f340b3 commit 975101d
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions tools/pypi-lock.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ from pathlib import Path
import micropip
def get_imports_for_package(p: str) -> list[str]:
def valid_package_name(n: str) -> bool:
return all(invalid_chr not in n for invalid_chr in ".- ")
imports = set()
tree = dict()
Expand All @@ -28,7 +31,11 @@ def get_imports_for_package(p: str) -> list[str]:
continue
# include top-level single-file packages
if len(f.parts) == 1 and f.suffix in [".py", ".so"]:
if (
len(f.parts) == 1 and
f.suffix in [".py", ".so"] and
valid_package_name(f.stem)
):
imports.add(f.stem)
continue
Expand All @@ -41,7 +48,10 @@ def get_imports_for_package(p: str) -> list[str]:
# extract folders that only have folders but no files as children,
# these are package candidates
queue = [([k], t) for k, t in tree.items() if len(t) > 0]
queue = [
([k], t) for k, t in tree.items()
if len(t) > 0 and valid_package_name(k)
]
while len(queue) > 0:
ps, tree = queue.pop()
imports.add('.'.join(ps))
Expand All @@ -51,7 +61,8 @@ def get_imports_for_package(p: str) -> list[str]:
add_to_queue = []
for k, t in tree.items():
if len(t) > 0:
add_to_queue.append((ps + [k], t))
if valid_package_name(k):
add_to_queue.append((ps + [k], t))
else:
is_package = False
Expand Down

0 comments on commit 975101d

Please sign in to comment.