99from pathlib import Path
1010
1111
12- RUNTIME_PACKAGES = ("prism" , "prismatoid" )
12+ RUNTIME_MODULE_TOKENS = ("prism" , "prismatoid" )
1313
1414
1515def _normalize (path : str ) -> str :
1616 return path .replace ("\\ " , "/" ).lstrip ("./" )
1717
1818
19- def _package_matches (entries : list [str ]) -> list [str ]:
19+ def _contains_runtime_tokens (entries : list [str ]) -> list [str ]:
2020 matches : list [str ] = []
2121 for name in entries :
22- if any (name .startswith (f"{ pkg } /" ) for pkg in RUNTIME_PACKAGES ):
22+ low = name .lower ()
23+ if any (token in low for token in RUNTIME_MODULE_TOKENS ):
2324 matches .append (name )
2425 return matches
2526
@@ -30,26 +31,28 @@ def verify_runtime_dir(runtime_dir: Path, require_no_data: bool) -> tuple[bool,
3031 if not runtime_dir .exists ():
3132 return False , [f"missing runtime dir: { runtime_dir } " ]
3233
33- for pkg in RUNTIME_PACKAGES :
34- pkg_dir = runtime_dir / pkg
35- if not pkg_dir .exists () or not pkg_dir .is_dir ():
36- errors .append (f"missing runtime package directory: { pkg } /" )
37- continue
38-
39- if not any (path .is_file () for path in pkg_dir .rglob ("*" )):
40- errors .append (f"runtime package has no files: { pkg } /" )
41-
4234 if require_no_data and (runtime_dir / "data" ).exists ():
4335 errors .append ("runtime dir must not contain data/ (portable-only)" )
4436
4537 if errors :
4638 return False , errors
4739
4840 print (f"Validated runtime dir: { runtime_dir } " )
49- for pkg in RUNTIME_PACKAGES :
50- count = sum (1 for p in (runtime_dir / pkg ).rglob ("*" ) if p .is_file ())
51- print (f"Found { pkg } / files: { count } " )
41+ return True , []
42+
43+
44+ def verify_pyz_contains_runtime_modules (pyz_path : Path ) -> tuple [bool , list [str ]]:
45+ if not pyz_path .exists ():
46+ return False , [f"missing pyz archive: { pyz_path } " ]
47+
48+ data = pyz_path .read_bytes ().lower ()
49+ found = [token for token in RUNTIME_MODULE_TOKENS if token .encode ("utf-8" ) in data ]
5250
51+ if not found :
52+ return False , [f"missing prism/prismatoid markers in PYZ archive ({ pyz_path } )" ]
53+
54+ print (f"Validated runtime modules in PYZ: { pyz_path } " )
55+ print (f"Found runtime token markers: { ', ' .join (found )} " )
5356 return True , []
5457
5558
@@ -65,26 +68,18 @@ def verify_portable_zip(zip_path: Path) -> tuple[bool, list[str]]:
6568 if not any (name == "data/" or name .startswith ("data/" ) for name in entries ):
6669 errors .append ("missing required data/ directory contents" )
6770
68- runtime_entries = _package_matches (entries )
69- if not runtime_entries :
70- errors .append ("missing prism/prismatoid runtime files in portable zip" )
71-
7271 if errors :
7372 return False , errors
7473
7574 print (f"Validated portable zip: { zip_path } " )
76- print ("Found prism/prismatoid entries:" )
77- for name in runtime_entries [:20 ]:
78- print (f" { name } " )
79- if len (runtime_entries ) > 20 :
80- print (f" ... and { len (runtime_entries ) - 20 } more" )
81-
75+ print ("Found data/ directory contents for portable mode" )
8276 return True , []
8377
8478
8579def main () -> int :
8680 parser = argparse .ArgumentParser (description = __doc__ )
8781 parser .add_argument ("--runtime-dir" , type = Path , help = "Path to unpacked runtime directory" )
82+ parser .add_argument ("--pyz-path" , type = Path , help = "Path to PyInstaller PYZ archive" )
8883 parser .add_argument ("--portable-zip" , type = Path , help = "Path to portable zip" )
8984 parser .add_argument (
9085 "--require-runtime-no-data" ,
@@ -93,8 +88,8 @@ def main() -> int:
9388 )
9489 args = parser .parse_args ()
9590
96- if not args .runtime_dir and not args .portable_zip :
97- parser .error ("Provide at least one of --runtime-dir or --portable-zip" )
91+ if not args .runtime_dir and not args .pyz_path and not args . portable_zip :
92+ parser .error ("Provide at least one of --runtime-dir, --pyz-path, or --portable-zip" )
9893
9994 all_errors : list [str ] = []
10095
@@ -103,6 +98,11 @@ def main() -> int:
10398 if not ok :
10499 all_errors .extend (errors )
105100
101+ if args .pyz_path :
102+ ok , errors = verify_pyz_contains_runtime_modules (args .pyz_path )
103+ if not ok :
104+ all_errors .extend (errors )
105+
106106 if args .portable_zip :
107107 ok , errors = verify_portable_zip (args .portable_zip )
108108 if not ok :
0 commit comments