Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework class / namespace discovery #456

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,21 @@
("any", "capellambse.aird.GLOBAL_FILTERS"),
# Private type hinting helpers
("py:class", "_MapFunction"),
("py:class", "_NotSpecifiedType"),
("py:class", "capellambse.model._descriptors._Specification"),
# Sphinx currently doesn't handle TypeAliases well
("py:class", "_obj.ClassName"),
("py:class", "_obj.ElementList[T_co]"),
("py:class", "_obj.UnresolvedClassName"),
# TODO figure out why this broke again
# (and where, because Sphinx doesn't seem to know either)
("py:class", "cabc.Iterable"),
("py:class", "etree.QName"),
("py:class", "etree._Element"),
("py:class", "t.Any"),
]
nitpick_ignore_regex = [
("py:.*", r"^yaml\..*"),
("py:.*", r"^(?:awesomeversion|yaml)\..*"),
("py:.*", r"^(?:.*\.)?_[A-Z]$"), # Single-letter TypeVars (e.g. _T)
# Super/subclass and "see also" references sometimes break
("py:(meth|obj)", r"(?:.*\.)?write_transaction"),
Expand Down
4 changes: 2 additions & 2 deletions docs/source/examples/01 Introduction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
"<tr><th style=\"text-align: right;\">realization_view</th><td style=\"text-align: left;\"><b>Realization view of Prof. S. Snape</b> (uuid: 6f463eed-c77b-4568-8078-beec0536f243_realization_view)</td></tr>\n",
"<tr><th style=\"text-align: right;\">realized_components</th><td style=\"text-align: left;\"><p><em>(Empty list)</em></p></td></tr>\n",
"<tr><th style=\"text-align: right;\">realized_system_components</th><td style=\"text-align: left;\"><p><em>(Empty list)</em></p></td></tr>\n",
"<tr><th style=\"text-align: right;\">realizing_components</th><td style=\"text-align: left;\"><em>Backreference to - omitted: can be slow to compute. Display this property directly to show.</em></td></tr>\n",
"<tr><th style=\"text-align: right;\">realizing_components</th><td style=\"text-align: left;\"><em>Backreference to ModelElement - omitted: can be slow to compute. Display this property directly to show.</em></td></tr>\n",
"<tr><th style=\"text-align: right;\">realizing_physical_components</th><td style=\"text-align: left;\"><em>Backreference to PhysicalComponent - omitted: can be slow to compute. Display this property directly to show.</em></td></tr>\n",
"<tr><th style=\"text-align: right;\">related_exchanges</th><td style=\"text-align: left;\"><em>Backreference to ComponentExchange - omitted: can be slow to compute. Display this property directly to show.</em></td></tr>\n",
"<tr><th style=\"text-align: right;\">requirements</th><td style=\"text-align: left;\"><p><em>(Empty list)</em></p></td></tr>\n",
Expand Down Expand Up @@ -202,7 +202,7 @@
".realization_view = <Diagram 'Realization view of Prof. S. Snape'>\n",
".realized_components = []\n",
".realized_system_components = []\n",
".realizing_components = ... # backreference to - omitted: can be slow to compute\n",
".realizing_components = ... # backreference to ModelElement - omitted: can be slow to compute\n",
".realizing_physical_components = ... # backreference to PhysicalComponent - omitted: can be slow to compute\n",
".related_exchanges = ... # backreference to ComponentExchange - omitted: can be slow to compute\n",
".requirements = []\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
}
],
"source": [
"components_on_diagram = diagram.nodes.by_type(\"Part\").map(\"type\")\n",
"components_on_diagram = diagram.nodes.by_class(\"Part\").map(\"type\")\n",
"components_on_diagram"
]
},
Expand Down Expand Up @@ -207,7 +207,7 @@
"<tr><th style=\"text-align: right;\">realization_view</th><td style=\"text-align: left;\"><b>Realization view of Cooling Fan</b> (uuid: 65e82f3f-c5b7-44c1-bfea-8e20bb0230be_realization_view)</td></tr>\n",
"<tr><th style=\"text-align: right;\">realized_components</th><td style=\"text-align: left;\"><p><em>(Empty list)</em></p></td></tr>\n",
"<tr><th style=\"text-align: right;\">realized_logical_components</th><td style=\"text-align: left;\"><p><em>(Empty list)</em></p></td></tr>\n",
"<tr><th style=\"text-align: right;\">realizing_components</th><td style=\"text-align: left;\"><em>Backreference to - omitted: can be slow to compute. Display this property directly to show.</em></td></tr>\n",
"<tr><th style=\"text-align: right;\">realizing_components</th><td style=\"text-align: left;\"><em>Backreference to ModelElement - omitted: can be slow to compute. Display this property directly to show.</em></td></tr>\n",
"<tr><th style=\"text-align: right;\">related_exchanges</th><td style=\"text-align: left;\"><em>Backreference to ComponentExchange - omitted: can be slow to compute. Display this property directly to show.</em></td></tr>\n",
"<tr><th style=\"text-align: right;\">requirements</th><td style=\"text-align: left;\"><p><em>(Empty list)</em></p></td></tr>\n",
"<tr><th style=\"text-align: right;\">sid</th><td style=\"text-align: left;\"></td></tr>\n",
Expand Down Expand Up @@ -261,7 +261,7 @@
".realization_view = <Diagram 'Realization view of Cooling Fan'>\n",
".realized_components = []\n",
".realized_logical_components = []\n",
".realizing_components = ... # backreference to - omitted: can be slow to compute\n",
".realizing_components = ... # backreference to ModelElement - omitted: can be slow to compute\n",
".related_exchanges = ... # backreference to ComponentExchange - omitted: can be slow to compute\n",
".requirements = []\n",
".sid = ''\n",
Expand Down
17 changes: 17 additions & 0 deletions docs/source/examples/08 Property Values.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,13 @@
"<tr><th style=\"text-align: right;\">domains</th><td style=\"text-align: left;\"><ol start=\"0\" style=\"text-align: left;\">\n",
"<li><strong>ManagedDomain</strong> <a href=\"hlink://3763dd54-a878-446a-9330-b5d9c7121865\">&quot;DarkMagic&quot;</a> (3763dd54-a878-446a-9330-b5d9c7121865)</li>\n",
"</ol></td></tr>\n",
"<tr><th style=\"text-align: right;\">enumeration_property_types</th><td style=\"text-align: left;\"><p><em>(Empty list)</em></p></td></tr>\n",
"<tr><th style=\"text-align: right;\">filtering_criteria</th><td style=\"text-align: left;\"><p><em>(Empty list)</em></p></td></tr>\n",
"<tr><th style=\"text-align: right;\">groups</th><td style=\"text-align: left;\"><p><em>(Empty list)</em></p></td></tr>\n",
"<tr><th style=\"text-align: right;\">name</th><td style=\"text-align: left;\">EXTENSIONS</td></tr>\n",
"<tr><th style=\"text-align: right;\">packages</th><td style=\"text-align: left;\"><ol start=\"0\" style=\"text-align: left;\">\n",
"<li><strong>PropertyValuePkg</strong> <a href=\"hlink://3763dd54-a878-446a-9330-b5d9c7121865\">&quot;DarkMagic&quot;</a> (3763dd54-a878-446a-9330-b5d9c7121865)</li>\n",
"</ol></td></tr>\n",
"<tr><th style=\"text-align: right;\">parent</th><td style=\"text-align: left;\"><strong>Project</strong> <a href=\"hlink://af2196ac-49d3-4063-885c-9fa29adc39a8\">&quot;Melody Model Test&quot;</a> (af2196ac-49d3-4063-885c-9fa29adc39a8)</td></tr>\n",
"<tr><th style=\"text-align: right;\">progress_status</th><td style=\"text-align: left;\">NOT_SET</td></tr>\n",
"<tr><th style=\"text-align: right;\">property_value_groups</th><td style=\"text-align: left;\"><p><em>(Empty list)</em></p></td></tr>\n",
Expand All @@ -414,6 +419,7 @@
"<tr><th style=\"text-align: right;\">traces</th><td style=\"text-align: left;\"><p><em>(Empty list)</em></p></td></tr>\n",
"<tr><th style=\"text-align: right;\">uuid</th><td style=\"text-align: left;\">fdbeb3b8-e1e2-4c6d-aff4-bccb1b9f437f</td></tr>\n",
"<tr><th style=\"text-align: right;\">validation</th><td style=\"text-align: left;\"><em>&lt;capellambse.extensions.validation._validate.ElementValidation object at 0x762147ff7cb0&gt;</em></td></tr>\n",
"<tr><th style=\"text-align: right;\">values</th><td style=\"text-align: left;\"><p><em>(Empty list)</em></p></td></tr>\n",
"<tr><th style=\"text-align: right;\">visible_on_diagrams</th><td style=\"text-align: left;\"><p><em>(Empty list)</em></p></td></tr>\n",
"<tr><th style=\"text-align: right;\">xtype</th><td style=\"text-align: left;\">org.polarsys.capella.core.data.capellacore:PropertyValuePkg</td></tr>\n",
"</table>"
Expand All @@ -426,8 +432,11 @@
".description = Markup('')\n",
".diagrams = []\n",
".domains = [0] <ManagedDomain 'DarkMagic' (3763dd54-a878-446a-9330-b5d9c7121865)>\n",
".enumeration_property_types = []\n",
".filtering_criteria = []\n",
".groups = []\n",
".name = 'EXTENSIONS'\n",
".packages = [0] <PropertyValuePkg 'DarkMagic' (3763dd54-a878-446a-9330-b5d9c7121865)>\n",
".parent = <Project 'Melody Model Test' (af2196ac-49d3-4063-885c-9fa29adc39a8)>\n",
".progress_status = 'NOT_SET'\n",
".property_value_groups = []\n",
Expand All @@ -440,6 +449,7 @@
".traces = []\n",
".uuid = 'fdbeb3b8-e1e2-4c6d-aff4-bccb1b9f437f'\n",
".validation = <capellambse.extensions.validation._validate.ElementValidation object at 0x76215173d460>\n",
".values = []\n",
".visible_on_diagrams = []\n",
".xtype = 'org.polarsys.capella.core.data.capellacore:PropertyValuePkg'"
]
Expand Down Expand Up @@ -540,6 +550,8 @@
"<tr><th style=\"text-align: right;\">applied_property_value_groups</th><td style=\"text-align: left;\"><p><em>(Empty list)</em></p></td></tr>\n",
"<tr><th style=\"text-align: right;\">applied_property_values</th><td style=\"text-align: left;\"><p><em>(Empty list)</em></p></td></tr>\n",
"<tr><th style=\"text-align: right;\">constraints</th><td style=\"text-align: left;\"><p><em>(Empty list)</em></p></td></tr>\n",
"<tr><th style=\"text-align: right;\">description</th><td style=\"text-align: left;\">[PROPERTY]DarkMagic.Power.Max<10000.0[/PROPERTY]\n",
"[ARCHITECTURE]LOGICAL[/ARCHITECTURE]</td></tr>\n",
"<tr><th style=\"text-align: right;\">diagrams</th><td style=\"text-align: left;\"><p><em>(Empty list)</em></p></td></tr>\n",
"<tr><th style=\"text-align: right;\">filtering_criteria</th><td style=\"text-align: left;\"><p><em>(Empty list)</em></p></td></tr>\n",
"<tr><th style=\"text-align: right;\">fullname</th><td style=\"text-align: left;\">DarkMagic.Power Level</td></tr>\n",
Expand All @@ -559,6 +571,9 @@
"<tr><th style=\"text-align: right;\">traces</th><td style=\"text-align: left;\"><p><em>(Empty list)</em></p></td></tr>\n",
"<tr><th style=\"text-align: right;\">uuid</th><td style=\"text-align: left;\">a0cb5a23-955e-43d6-a633-2c4e66991364</td></tr>\n",
"<tr><th style=\"text-align: right;\">validation</th><td style=\"text-align: left;\"><em>&lt;capellambse.extensions.validation._validate.ElementValidation object at 0x762150164380&gt;</em></td></tr>\n",
"<tr><th style=\"text-align: right;\">values</th><td style=\"text-align: left;\"><ol start=\"0\" style=\"text-align: left;\">\n",
"<li><strong>EnumerationPropertyValue</strong> <a href=\"hlink://7367c731-aabb-4807-9d74-7ef2c6482ec9\">&quot;Skill&quot;</a>: <strong>EnumerationPropertyLiteral</strong> <a href=\"hlink://4da42696-28e2-4f90-bfb6-90ba1fc52d01\">&quot;TheOneWhoShallNotBeNamed&quot;</a> (4da42696-28e2-4f90-bfb6-90ba1fc52d01) (7367c731-aabb-4807-9d74-7ef2c6482ec9)</li>\n",
"</ol></td></tr>\n",
"<tr><th style=\"text-align: right;\">visible_on_diagrams</th><td style=\"text-align: left;\"><p><em>(Empty list)</em></p></td></tr>\n",
"<tr><th style=\"text-align: right;\">xtype</th><td style=\"text-align: left;\">org.polarsys.capella.core.data.capellacore:PropertyValueGroup</td></tr>\n",
"</table>"
Expand All @@ -568,6 +583,7 @@
".applied_property_value_groups = []\n",
".applied_property_values = []\n",
".constraints = []\n",
".description = Markup('[PROPERTY]DarkMagic.Power.Max<10000.0[/PROPERTY]\\n[ARCHITECTURE]LOGICAL[/ARCHITECTURE]')\n",
".diagrams = []\n",
".filtering_criteria = []\n",
".fullname = 'DarkMagic.Power Level'\n",
Expand All @@ -585,6 +601,7 @@
".traces = []\n",
".uuid = 'a0cb5a23-955e-43d6-a633-2c4e66991364'\n",
".validation = <capellambse.extensions.validation._validate.ElementValidation object at 0x762147ff7cb0>\n",
".values = [0] <EnumerationPropertyValue 'Skill' (7367c731-aabb-4807-9d74-7ef2c6482ec9)>\n",
".visible_on_diagrams = []\n",
".xtype = 'org.polarsys.capella.core.data.capellacore:PropertyValueGroup'"
]
Expand Down
28 changes: 28 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,34 @@ pvmt = "capellambse.extensions.pvmt:init"
reqif = "capellambse.extensions.reqif:init"
validation = "capellambse.extensions.validation:init"

[project.entry-points."capellambse.namespaces"]
viewpoint = "capellambse.model.diagram:VIEWPOINT_NS"

activity = "capellambse.metamodel.namespaces:ACTIVITY"
behavior = "capellambse.metamodel.namespaces:BEHAVIOR"
capellacommon = "capellambse.metamodel.namespaces:CAPELLACOMMON"
capellacore = "capellambse.metamodel.namespaces:CAPELLACORE"
capellamodeller = "capellambse.metamodel.namespaces:CAPELLAMODELLER"
cs = "capellambse.metamodel.namespaces:CS"
epbs = "capellambse.metamodel.namespaces:EPBS"
fa = "capellambse.metamodel.namespaces:FA"
information = "capellambse.metamodel.namespaces:INFORMATION"
information_communication = "capellambse.metamodel.namespaces:INFORMATION_COMMUNICATION"
information_datatype = "capellambse.metamodel.namespaces:INFORMATION_DATATYPE"
information_datavalue = "capellambse.metamodel.namespaces:INFORMATION_DATAVALUE"
interaction = "capellambse.metamodel.namespaces:INTERACTION"
la = "capellambse.metamodel.namespaces:LA"
libraries = "capellambse.metamodel.namespaces:LIBRARIES"
metadata = "capellambse.metamodel.namespaces:METADATA"
modellingcore = "capellambse.metamodel.namespaces:MODELLINGCORE"
oa = "capellambse.metamodel.namespaces:OA"
pa = "capellambse.metamodel.namespaces:PA"
pa_deployment = "capellambse.metamodel.namespaces:PA_DEPLOYMENT"
sa = "capellambse.metamodel.namespaces:SA"

capellarequirements = "capellambse.extensions.reqif:CapellaRequirementsNS"
requirements = "capellambse.extensions.reqif:RequirementsNS"

[dependency-groups]
dev = [
"cairosvg>=2.5.2",
Expand Down
38 changes: 17 additions & 21 deletions src/capellambse/extensions/filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,20 @@
import capellambse.model as m
from capellambse import _native, helpers

VIEWPOINT: t.Final = "org.polarsys.capella.filtering"
NAMESPACE: t.Final = "http://www.polarsys.org/capella/filtering/6.0.0"
SYMBOLIC_NAME: t.Final = "filtering"

_LOGGER = logging.getLogger(__name__)

m.XTYPE_ANCHORS[__name__] = SYMBOLIC_NAME
NS = m.Namespace(
"http://www.polarsys.org/capella/filtering/{VERSION}",
"filtering",
"org.polarsys.capella.filtering",
"7.0.0",
)

VIEWPOINT: t.Final = NS.viewpoint
NAMESPACE: t.Final = NS.uri.format(VERSION="6.0.0")
SYMBOLIC_NAME: t.Final = NS.alias


@m.xtype_handler(None)
class FilteringCriterion(m.ModelElement):
"""A single filtering criterion."""

Expand All @@ -40,17 +44,15 @@ class FilteringCriterion(m.ModelElement):
)


@m.xtype_handler(None)
class FilteringCriterionPkg(m.ModelElement):
"""A package containing multiple filtering criteria."""

_xmltag = "ownedFilteringCriterionPkgs"

criteria = m.DirectProxyAccessor(FilteringCriterion, aslist=m.ElementList)
packages: m.Accessor[FilteringCriterionPkg]
packages: m.Accessor[m.ElementList[FilteringCriterionPkg]]


@m.xtype_handler(None)
class FilteringModel(m.ModelElement):
"""A filtering model containing criteria to filter by."""

Expand Down Expand Up @@ -83,7 +85,7 @@ def __get__(

loader = obj._model._loader
try:
xt_critset = f"{SYMBOLIC_NAME}:AssociatedFilteringCriterionSet"
xt_critset = f"{NS.alias}:AssociatedFilteringCriterionSet"
critset = next(loader.iterchildren_xt(obj._element, xt_critset))
except StopIteration:
elems = []
Expand All @@ -94,32 +96,26 @@ def __get__(
return self._make_list(obj, elems)


@m.xtype_handler(None)
class FilteringResult(m.ModelElement):
"""A filtering result."""


@m.xtype_handler(None)
class ComposedFilteringResult(m.ModelElement):
"""A composed filtering result."""


def init() -> None:
m.set_accessor(
mm.capellamodeller.SystemEngineering,
"filtering_model",
m.DirectProxyAccessor(FilteringModel),
mm.capellamodeller.SystemEngineering.filtering_model = (
m.DirectProxyAccessor(FilteringModel)
)
m.MelodyModel.filtering_model = property( # type: ignore[attr-defined]
operator.attrgetter("project.model_root.filtering_model")
)
m.set_accessor(
m.ModelElement, "filtering_criteria", AssociatedCriteriaAccessor()
)
m.ModelElement.filtering_criteria = AssociatedCriteriaAccessor()


m.set_self_references(
(FilteringCriterionPkg, "packages"),
FilteringCriterionPkg.packages = m.DirectProxyAccessor(
FilteringCriterionPkg, aslist=m.ElementList
)

try:
Expand Down
2 changes: 1 addition & 1 deletion src/capellambse/extensions/pvmt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def _get_pvmt_configuration(model: m.MelodyModel) -> PVMTConfiguration:
def init() -> None:
"""Initialize the PVMT extension."""
m.MelodyModel.pvmt = property(_get_pvmt_configuration) # type: ignore[attr-defined]
m.set_accessor(m.ModelElement, "pvmt", m.AlternateAccessor(ObjectPVMT))
m.ModelElement.pvmt = m.AlternateAccessor(ObjectPVMT)


if not t.TYPE_CHECKING:
Expand Down
Loading
Loading