Source code for syside.query

  1"""
  2``syside.query`` -- read-only queries over a loaded model.
  3
  4Use this package to ask questions about a model that :func:`syside.load_model`
  5has produced: find elements by name or metadata, walk generalization and
  6containment hierarchies, and inspect features, connections, and variation
  7points. No function here modifies the model.
  8
  9Three kinds of names are exported:
 10
 11* Traversal primitives -- :func:`generalizations`, :func:`specializations`,
 12  and :func:`walk_containment` -- which walk the type and ownership
 13  hierarchies.
 14* Query functions built on those primitives, such as :func:`find_by_name` and
 15  :func:`find_elements_of_type`.
 16* Index types (:class:`NameIndex`, :class:`TypeIndex`, :class:`MetadataIndex`)
 17  with matching ``build_*_index`` builders. Without an index, each query scans
 18  the model; when you repeat lookups, build the index once and pass it via the
 19  ``index=`` parameter to make each later lookup a dictionary read. An index
 20  never changes a query's result, only its cost.
 21
 22Every function returns a plain, fully materialized value -- a ``list``,
 23``set``, ``bool``, scalar, or ``None`` -- never a lazy view of the model.
 24"""
 25
 26from __future__ import annotations
 27
 28from syside.query._functions import (
 29    MetadataIndex,
 30    MultiplicityBounds,
 31    NameIndex,
 32    TypeIndex,
 33    UNBOUNDED,
 34    Unbounded,
 35    actors,
 36    containers,
 37    annotated_elements,
 38    build_metadata_index,
 39    build_name_index,
 40    build_type_index,
 41    contains,
 42    contents,
 43    connection_ends,
 44    bindings_of,
 45    cross_subsets,
 46    all_contents,
 47    description,
 48    types_of,
 49    documentation,
 50    enumeration_values,
 51    exposed_elements,
 52    feature_chain,
 53    featured_in,
 54    features_of,
 55    find_by_name,
 56    find_by_name_and_type,
 57    find_by_path,
 58    find_by_qualified_name,
 59    find_elements_of_type,
 60    find_metadata_usages,
 61    find_relationships,
 62    has_metadata_prefix,
 63    incoming_connections,
 64    inherited_features,
 65    is_contained_in,
 66    metadata_prefixes,
 67    metadata_usages,
 68    multiplicity_bounds,
 69    outgoing_connections,
 70    generalization_names,
 71    redefined_by,
 72    redefines,
 73    referenced_feature,
 74    siblings,
 75    specializes,
 76    direct_supertypes,
 77    subjects,
 78    subsets,
 79    subtypes,
 80    supertypes,
 81    textual_representation,
 82    variants,
 83)
 84from syside.query._primitives import (
 85    specializations,
 86    generalizations,
 87    walk_containment,
 88)
 89
 90__all__ = [
 91    # primitives
 92    "generalizations",
 93    "specializations",
 94    "walk_containment",
 95    # index types + builders
 96    "NameIndex",
 97    "TypeIndex",
 98    "MetadataIndex",
 99    "build_name_index",
100    "build_type_index",
101    "build_metadata_index",
102    # dataclasses
103    "MultiplicityBounds",
104    "Unbounded",
105    "UNBOUNDED",
106    # lookup
107    "find_by_name",
108    "find_by_name_and_type",
109    "find_by_qualified_name",
110    "find_by_path",
111    "find_elements_of_type",
112    "find_relationships",
113    "find_metadata_usages",
114    # ownership tree
115    "contents",
116    "all_contents",
117    "containers",
118    "siblings",
119    "is_contained_in",
120    "contains",
121    # feature / type structure
122    "features_of",
123    "inherited_features",
124    "generalization_names",
125    "types_of",
126    "supertypes",
127    "subtypes",
128    "subsets",
129    "redefines",
130    "redefined_by",
131    "direct_supertypes",
132    "featured_in",
133    "cross_subsets",
134    "specializes",
135    # connections
136    "connection_ends",
137    "incoming_connections",
138    "outgoing_connections",
139    "bindings_of",
140    # expressions / chains
141    "referenced_feature",
142    "feature_chain",
143    # documentation
144    "documentation",
145    "description",
146    "textual_representation",
147    # metadata
148    "metadata_prefixes",
149    "metadata_usages",
150    "has_metadata_prefix",
151    "annotated_elements",
152    # enumerations / variants / cases
153    "enumeration_values",
154    "variants",
155    "actors",
156    "subjects",
157    # multiplicity
158    "multiplicity_bounds",
159    # views
160    "exposed_elements",
161]