Skip to content

Index

core

Core audit functionality.

audit_project(project_path, category=None, quick=False)

Audit a project against Python 2026 standards.

Rules execute in parallel via ThreadPoolExecutor for speed. Each rule is isolated — one failure does not prevent others. An ASTCache is shared across rules to avoid redundant parsing.

Parameters:

Name Type Description Default
project_path Path

Root directory of the project to audit.

required
category str | None

Optional category filter.

None
quick bool

If True, run only lint + type checks.

False

Returns:

Type Description
AuditResult

AuditResult containing all check results.

Raises:

Type Description
FileNotFoundError

If project_path does not exist.

Source code in packages/axm-audit/src/axm_audit/core/auditor.py
def audit_project(
    project_path: Path,
    category: str | None = None,
    quick: bool = False,
) -> AuditResult:
    """Audit a project against Python 2026 standards.

    Rules execute in parallel via ThreadPoolExecutor for speed.
    Each rule is isolated — one failure does not prevent others.
    An ``ASTCache`` is shared across rules to avoid redundant parsing.

    Args:
        project_path: Root directory of the project to audit.
        category: Optional category filter.
        quick: If True, run only lint + type checks.

    Returns:
        AuditResult containing all check results.

    Raises:
        FileNotFoundError: If project_path does not exist.
    """
    if not project_path.exists():
        raise FileNotFoundError(f"Project path does not exist: {project_path}")

    rules = get_rules_for_category(category, quick)

    cache = ASTCache()
    set_ast_cache(cache)
    try:
        with concurrent.futures.ThreadPoolExecutor() as pool:
            checks = list(pool.map(lambda r: _safe_check(r, project_path), rules))
    finally:
        set_ast_cache(None)

    return AuditResult(project_path=str(project_path), checks=checks)

get_rules_for_category(category, quick=False)

Get rules for a specific category or all rules.

Parameters:

Name Type Description Default
category str | None

Filter to specific category, or None for all.

required
quick bool

If True, only lint + type checks.

False

Returns:

Type Description
list[ProjectRule]

List of rule instances to run.

Raises:

Type Description
ValueError

If category is not valid.

Source code in packages/axm-audit/src/axm_audit/core/auditor.py
def get_rules_for_category(
    category: str | None, quick: bool = False
) -> list[ProjectRule]:
    """Get rules for a specific category or all rules.

    Args:
        category: Filter to specific category, or None for all.
        quick: If True, only lint + type checks.

    Returns:
        List of rule instances to run.

    Raises:
        ValueError: If category is not valid.
    """
    _ensure_registry_loaded()

    if quick:
        from axm_audit.core.rules.quality import LintingRule, TypeCheckRule

        return [LintingRule(), TypeCheckRule()]

    # Validate category
    if category is not None and category not in VALID_CATEGORIES:
        raise ValueError(
            f"Invalid category: {category}. "
            f"Valid categories: {', '.join(sorted(VALID_CATEGORIES))}"
        )

    if not category:
        return _build_all_rules()

    registry = get_registry()
    rule_classes = registry.get(category, [])
    rules: list[ProjectRule] = []
    for cls in rule_classes:
        rules.extend(cls.get_instances())
    return rules