Component graph
Authored component dependencies, reverse references, source locations, and partial-analysis problems.
ComponentGraph class
Hold a versioned snapshot of authored dependencies between registered components.
Build a graph with Citry.inspect_component_graph(). Query direct dependencies or reverse references by primary name, alias, or a node returned from the same graph.
Example
graph = app.inspect_component_graph() for dependency in graph.dependencies("page"): print(dependency.name) for dependent in graph.dependents("button"): print(dependent.name)
Attributes
schema_versionint- Graph JSON schema version.citry_versionstr- Installed Citry package version used to build the graph.engine_idstr- Runtime identity of the inspected Citry instance.nodestuple[ComponentGraphNode, ...]- Registered component definitions in canonical order.referencestuple[ComponentGraphReference, ...]- Resolved authored occurrences in canonical source order.unresolvedtuple[UnresolvedComponentReference, ...]- Unknown and dynamic authored occurrences.problemstuple[ComponentGraphProblem, ...]- Sources that could not be inspected completely.
coverage_complete attribute
coverage_complete: boolWhether every selected primary template was available and parseable.
fully_resolved attribute
fully_resolved: boolWhether source coverage is complete and every reference has a static target.
component function
component(selector: str | ComponentGraphNode) -> ComponentGraphNodeReturn one graph node selected by registered name, alias, or retained node.
Parameters
selectorstr | ComponentGraphNode- Case-insensitive registered name or a node from this graph.
Returns
ComponentGraphNode: The canonical node stored in this graph.
Raises
TypeError- Ifselectoris not a string or graph node.NotRegistered- If the selector does not identify this graph's exact component generation.
dependencies function
dependencies(component: str | ComponentGraphNode) -> tuple[ComponentGraphNode, ...]Return unique registered components directly referenced by component.
dependents function
dependents(component: str | ComponentGraphNode) -> tuple[ComponentGraphNode, ...]Return unique registered components that directly reference component.
references_from function
references_from(component: str | ComponentGraphNode) -> tuple[ComponentGraphReference, ...]Return every resolved authored reference owned by component.
references_to function
references_to(component: str | ComponentGraphNode) -> tuple[ComponentGraphReference, ...]Return every resolved authored reference targeting component.
unresolved_from function
unresolved_from(component: str | ComponentGraphNode | None = None) -> tuple[UnresolvedComponentReference, ...]Return unresolved references from one component, or all of them when omitted.
to_json function
Serialize this graph to deterministic UTF-8 JSON text.
Parameters
indentint | None- Optional non-negative indentation width.Noneemits compact JSON.
Returns
str: Deterministic JSON with recursively sorted object keys.
Raises
TypeError- Ifindentis not an integer orNone.ValueError- Ifindentis negative.
ComponentGraphNode class
Identify one registered component definition in an authored dependency graph.
Use name in templates and graph queries. aliases contains the other registered spellings that resolve to the same component.
Example
graph = app.inspect_component_graph() card = graph.component("card") print(card.name)
Attributes
class_idstr- Stable identity for the component's Python route.engine_idstr- Runtime identity of the Citry instance that built the graph.definition_idstr- Runtime identity of this exact class generation.namestr- Canonical registered component name.aliasestuple[str, ...]- Other registered names for the same component.builtinbool- Whether Citry created this framework component.
ComponentGraphReference class
Describe one authored component reference that resolves to a registered target.
Repeated invocations remain separate records. Use ComponentGraph.dependencies when you need unique target components.
Attributes
source_definition_idstr- Exact component definition that owns the source.target_definition_idstr- Exact registered target definition.registered_namestr- Normalized registry name that matched the reference.authored_namestr- Target name exactly as written by the author.syntaxLiteral['tag', 'static-selector']- Whether the target came from a tag or static selector.locationComponentGraphLocation- Authored source occurrence.
UnresolvedComponentReference class
Describe an authored component reference whose target is not statically known.
unknown-component retains the written name. dynamic-target uses authored_name=None because the runtime expression or spread chooses it.
Attributes
source_definition_idstr- Exact component definition that owns the source.authored_namestr | None- Written target name, orNonefor a dynamic target.reasonLiteral['unknown-component', 'dynamic-target']- Whether the name is unknown or the target is dynamic.syntaxLiteral['tag', 'static-selector', 'dynamic-selector']- Authored tag or selector form.locationComponentGraphLocation- Authored source occurrence.
ComponentGraphLocation class
Point to one component reference in an authored primary template.
start_index and end_index are half-open UTF-8 byte offsets in the normalized root template. source_range carries the same span as zero-based UTF-16 positions for editors.
Attributes
originstr- Human-readable template origin.source_kindLiteral['inline', 'file']- Whether the template is inline or file-backed.declared_onstr | None- Import path of the class that declared the template.declaration_filePath | None- Python file containing that declaration, when known.template_filePath | None- Resolved file-backed template path, when applicable.start_indexint- Inclusive UTF-8 byte offset in the root template.end_indexint- Exclusive UTF-8 byte offset in the root template.source_rangeLspRange- Equivalent zero-based UTF-16 editor range.
ComponentGraphProblem class
Report why Citry could not inspect part of an authored template source.
Graph construction continues after a problem, so callers can use references from unaffected components. component_definition_ids identifies every selected component that consumes the affected physical source.
Attributes
component_definition_idstuple[str, ...]- Sorted exact definitions affected.codestr- Stable graph-local problem category.messagestr- Human-readable explanation.originstr- Source or declaration that failed.locationComponentGraphLocation | None- Authored range when the failure supplied one.