cursus.step_catalog.contract_discovery

Contract discovery for the unified step catalog system.

Interface-first: every contract is a view onto a validated StepInterface loaded from the step’s .step.yaml (iface.contract is a ContractSection, a drop-in for the legacy ScriptContract/StepContract). Discovery is driven by the registry’s canonical step names — no directory scan, no AST parse, no per-file import. The former steps/contracts/ folder scan is gone; the registry is the single source of “which steps exist” and load_interface is the single source of “what each step’s contract is”.

class ContractAutoDiscovery(package_root, workspace_dirs)[source]

Bases: object

Contract discovery sourced from step interfaces + the step registry.

discover_contract_classes(project_id=None)[source]

Discover all step contracts from the registry + interfaces.

Parameters:

project_id (str | None) – Optional project ID (accepted for signature stability; the registry + interface loader are the source of truth)

Returns:

Dictionary mapping PascalCase canonical step name to its ContractSection (a view onto the step’s validated StepInterface). Steps without an interface file are skipped.

Return type:

Dict[str, Any]

load_contract_class(step_name)[source]

Load the contract for a specific step.

Parameters:

step_name (str) – PascalCase canonical step name

Returns:

The step’s ContractSection (view onto its StepInterface), or None if the step has no interface file.

Return type:

Any | None

find_contracts_by_entry_point(entry_point)[source]

Find contracts that reference a specific script entry point.

Enables script-contract alignment validation by finding the contracts associated with a given script entry point.

Parameters:

entry_point (str) – Script entry point (e.g., “model_evaluation_xgb.py”). Matched with or without the .py extension.

Returns:

Dictionary mapping PascalCase canonical step name to its ContractSection.

Return type:

Dict[str, Any]

get_contract_entry_points()[source]

Get all contract entry points for validation.

Returns:

Dictionary mapping PascalCase canonical step name to its entry point. Steps whose contract declares no entry_point (script-less CreateModel/Transform steps) are omitted.

Return type:

Dict[str, str]

serialize_contract(contract_instance)[source]

Convert contract instance to dictionary format.

This method provides standardized serialization of ScriptContract objects for use in script-contract alignment validation, following the same pattern as SpecAutoDiscovery.serialize_spec().

Parameters:

contract_instance (Any) – Contract instance to serialize

Returns:

Dictionary representation of the contract

Return type:

Dict[str, Any]