MCPcopy Create free account
hub / github.com/dedsec1121fk/DedSec / check_python_script

Function check_python_script

Scripts/Other Tools/Termux Repair Wizard.py:941–964  ·  view source on GitHub ↗
(path, text, scan_root, auto_install, report)

Source from the content-addressed store, hash-verified

939
940
941def check_python_script(path, text, scan_root, auto_install, report):
942 python_cmd = shutil.which("python") or sys.executable
943 code, _, err = run(
944 [
945 python_cmd,
946 "-c",
947 "import sys,tokenize; f=tokenize.open(sys.argv[1]); compile(f.read(), sys.argv[1], 'exec')",
948 path,
949 ],
950 capture=True,
951 )
952 if code != 0:
953 report.line("syntax_failures", f"{path}: Python compile check failed: {err.strip()}")
954
955 stdlib = getattr(sys, "stdlib_module_names", set())
956 local_names = {item.stem for item in path.parent.glob("*.py")}
957 local_names.update(item.name for item in path.parent.iterdir() if item.is_dir() and (item / "__init__.py").exists())
958 for module in sorted(parse_python_imports(text)):
959 if module in stdlib or module in local_names or python_module_is_local(module, path, scan_root) or python_module_available(module):
960 continue
961 if auto_install:
962 install_python_module(module, report)
963 else:
964 report.line("warnings", f"{path}: missing Python import '{module}'")
965
966
967def find_project_file(start, names, stop):

Callers 1

script_keeperFunction · 0.70

Calls 6

runFunction · 0.70
parse_python_importsFunction · 0.70
python_module_is_localFunction · 0.70
python_module_availableFunction · 0.70
install_python_moduleFunction · 0.70
lineMethod · 0.45

Tested by

no test coverage detected