rlsbl v0.60.1 /rlsbl.import_scanners
On this page

Python and Dart import scanners for dependency-import validation, filtering workspace-relevant imports and distinguishing lib vs test contexts.

#rlsbl.import_scanners

#rlsbl.import_scanners

Python, Dart, and npm import scanners for dependency-import validation.

Filters raw import data to workspace-relevant imports, handles language-specific edge cases, and distinguishes lib/ vs test/ contexts.

#ImportInfo

A single workspace-relevant import detected in a source file.

#_is_test_context

python
def _is_test_context(filepath: str, project_path: str) -> bool

Determine whether a file is in a non-production context.

Checks directory names (test, tests, __tests__, examples, example) and file name patterns (test_.py, _test.go, *.spec.ts, etc.).

#PythonImportScanner

Scan Python source files for workspace-relevant imports.

Uses the AST-based scanner from the lint system, then post-processes to filter out stdlib, relative imports, and non-workspace packages.

#scan

python
def scan(self, project_path: str, workspace_names: set[str], exclude_dirs: list[str] | None=None) -> list[ImportInfo]

Scan project_path for Python imports matching workspace members.

Args:

  • project_path: absolute path to the project root.
  • workspace_names: set of workspace member package names

(as they appear in pyproject.toml, e.g. "my-lib").

  • exclude_dirs: directory paths to skip during the walk

(relative to project_path or absolute).

Returns:

  • list of ImportInfo for imports that match workspace members.

#DartImportScanner

Scan Dart source files for workspace-relevant package imports.

Uses regex to extract package names from import/export statements. Checks for missing generated (.g.dart) files when build_runner is configured.

#scan

python
def scan(self, project_path: str, workspace_names: set[str], exclude_dirs: list[str] | None=None) -> list[ImportInfo]

Scan project_path for Dart imports matching workspace members.

Args:

  • project_path: absolute path to the project root.
  • workspace_names: set of workspace member package names

(as they appear in pubspec.yaml).

  • exclude_dirs: directory paths to skip during the walk

(relative to project_path or absolute).

Returns:

  • list of ImportInfo for imports that match workspace members.

Raises:

  • RuntimeError: if build.yaml exists but no .g.dart files

are found in the project (missing code generation).

#_check_generated_files

python
def _check_generated_files(self, project_path: str) -> None

Raise RuntimeError if build_runner is configured but no .g.dart files exist.

#_extract_npm_bare_name

python
def _extract_npm_bare_name(specifier: str) -> str | None

Extract bare package name from an npm import specifier.

Returns None for relative imports, Node.js builtins, and node:-prefixed builtins. For scoped packages (@scope/pkg/foo), returns @scope/pkg. For unscoped (pkg/foo), returns pkg.

#NpmImportScanner

Scan JS/TS source files for workspace-relevant imports.

Uses the AST-based scanner from the npm lint system, then post-processes to filter out relative imports, Node.js builtins, and non-workspace packages.

#scan

python
def scan(self, project_path: str, workspace_names: set[str], exclude_dirs: list[str] | None=None) -> list[ImportInfo]

Scan project_path for JS/TS imports matching workspace members.

Args:

  • project_path: absolute path to the project root.
  • workspace_names: set of workspace member package names

(as they appear in package.json, e.g. "@scope/my-lib").

  • exclude_dirs: directory paths to skip during the walk

(relative to project_path or absolute).

Returns:

  • list of ImportInfo for imports that match workspace members.

#GoImportScanner

Scan Go source files for workspace-relevant imports.

Uses the tree-sitter-based scanner from the Go lint system, then post-processes to filter to imports matching other workspace projects' Go module paths.

#scan

python
def scan(self, project_path: str, workspace_names: set[str], exclude_dirs: list[str] | None=None, *, module_path_map: dict[str, str] | None=None) -> list[ImportInfo]

Scan project_path for Go imports matching workspace members.

Args:

  • project_path: absolute path to the project root.
  • workspace_names: set of workspace member package names.
  • exclude_dirs: directory paths to skip during the walk

(relative to project_path or absolute).

  • module_path_map: mapping of workspace project name to its

Go module path (from go.mod). Only Go projects appear in this map. Required for Go import detection.

Returns:

  • list of ImportInfo for imports that match workspace members.

#_read_module_path

python
def _read_module_path(project_path: str) -> str | None

Read the module path from go.mod.

#_match_workspace_import

python
def _match_workspace_import(import_path: str, module_to_name: dict[str, str]) -> str | None

Check if an import path belongs to a workspace sibling.

An import matches a workspace module if the import path equals the module path or starts with it followed by '/'.