checks.imports.ImportsCheck
checks.imports.ImportsCheck()Check that all imports in the package can be resolved.
Scans all Python files in the package and attempts to resolve each import statement. Reports any imports that cannot be found, which may indicate missing dependencies.
Attributes
name :-
The check identifier (“imports”).
description :-
Human-readable description of this check.
Note
This check excludes standard library modules and local package imports from validation. It only flags third-party imports that cannot be resolved in the current environment.
Examples
Run the imports check:
>>> from pathlib import Path
>>> check = ImportsCheck()
>>> result = check.run(Path("."), {"enabled": True})
>>> result.name
'imports'The check reports unresolvable imports:
>>> # If a file imports 'nonexistent_package'
>>> # result.status == CheckStatus.WARNING
>>> # "Cannot import 'nonexistent_package'" in result.detailsMethods
| Name | Description |
|---|---|
| run | Check imports in all Python files. |
run
checks.imports.ImportsCheck.run(package_path, config)Check imports in all Python files.
Parses each Python file to extract import statements, then attempts to import each module to verify it exists.
Parameters
Returns
: CheckResult-
A CheckResult with:
: CheckResult-
- OK status if all imports can be resolved
: CheckResult-
- NOTE status if no Python files found
: CheckResult-
- WARNING status if some imports cannot be resolved
: CheckResult-
- ERROR status if Python files have syntax errors