(path, text, scan_root, auto_install, report)
| 939 | |
| 940 | |
| 941 | def 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 | |
| 967 | def find_project_file(start, names, stop): |
no test coverage detected