helpers
_helpers
Shared AST helpers for rule implementations.
ASTCache
Thread-safe AST parse cache.
Parses each file at most once per audit session. Uses double-checked locking so multiple threads hitting the same file don't duplicate work.
Source code in packages/axm-audit/src/axm_audit/core/rules/_helpers.py
get_or_parse(path)
Return cached AST or parse path and cache the result.
Source code in packages/axm-audit/src/axm_audit/core/rules/_helpers.py
get_ast_cache()
get_python_files(directory)
Get all Python files in a directory recursively.
iter_src_dirs(project_path)
Discover src/ directories under project_path.
Layout detection (in order):
- Single-package —
<project_path>/src/exists → returns[<project_path>/src]. This branch wins even if a siblingpackages/directory also exists (defensive precedence). - Multi-package workspace —
<project_path>/packages/<pkg>/src/matches one or more<pkg>→ returns the matched src dirs sorted lexicographically by<pkg>. - Otherwise — returns
[].
Note: this is unrelated to the older
axm_audit.core.rules.quality._get_audit_targets which returns
(list[str], str) of ruff/mypy CLI args.
Source code in packages/axm-audit/src/axm_audit/core/rules/_helpers.py
iter_workspace_packages(project_path)
Return the package roots of a multi-package workspace.
Returns [] for single-package or no-layout projects.
Each returned path is the package directory (parent of src/),
sorted lexicographically.
Source code in packages/axm-audit/src/axm_audit/core/rules/_helpers.py
parse_file_safe(path)
Parse a Python file, returning None on error.
Source code in packages/axm-audit/src/axm_audit/core/rules/_helpers.py
reset_ast_cache(token)
Reset the active cache using a token from :func:set_ast_cache.
set_ast_cache(cache)
Bind cache to the current context and return the reset token.