-
Notifications
You must be signed in to change notification settings - Fork 17
feat: added support for the libraries linking and referencing from model #619
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
base: master
Are you sure you want to change the base?
Changes from 8 commits
0834f55
95876e0
642dc10
689caf9
afa4254
1c909f0
48f4663
e16380a
09d5b1b
29ca09b
a24c1b9
bf61bcc
c31203a
7a47cb1
0ffe456
51ff19d
35447dc
ba96398
cb6ed11
f7050f5
a6a3312
70b3180
6af3dc1
ee38b5c
9ac0245
6f0ae2c
af6deb0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -32,6 +32,7 @@ | |||||||||
|
|
||||||||||
| import capellambse._namespaces as _n | ||||||||||
| from capellambse import filehandler, helpers | ||||||||||
| from capellambse.aird._common import XP_SEMANTIC_RESOURCES | ||||||||||
|
wingedfox marked this conversation as resolved.
Outdated
|
||||||||||
| from capellambse.loader import exs | ||||||||||
| from capellambse.loader.modelinfo import ModelInfo | ||||||||||
|
|
||||||||||
|
|
@@ -590,6 +591,85 @@ def check_duplicate_uuids(self) -> None: | |||||||||
| " - check the 'resources' for duplicate models" | ||||||||||
| ) | ||||||||||
|
|
||||||||||
| def __get_metadata( | ||||||||||
| self, afm: ModelFile | ||||||||||
| ) -> etree._Element: | ||||||||||
| """Return metadata from given model. | ||||||||||
|
|
||||||||||
| Parameters | ||||||||||
| ---------- | ||||||||||
| afm | ||||||||||
| model metadata file | ||||||||||
| return | ||||||||||
| metadata element if found | ||||||||||
|
wingedfox marked this conversation as resolved.
Outdated
|
||||||||||
|
|
||||||||||
| Raises | ||||||||||
| ------ | ||||||||||
| RuntimeError | ||||||||||
| If metadata could not be found | ||||||||||
| """ | ||||||||||
| metadata = next(afm.root.iter(METADATA_TAG), None) | ||||||||||
| if metadata is None: | ||||||||||
| raise RuntimeError("Cannot find <Metadata> in primary .afm file") | ||||||||||
|
Comment on lines
+617
to
+618
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This exception message doesn't quite fit anymore, since this function is also used for auxiliary
Suggested change
|
||||||||||
| LOGGER.debug("Found <Metadata> with ID %s", metadata.get("id")) | ||||||||||
| return metadata | ||||||||||
|
|
||||||||||
| def _link_library( | ||||||||||
| self, lib: pathlib.PurePosixPath | ||||||||||
|
wingedfox marked this conversation as resolved.
Outdated
|
||||||||||
| ) -> None: | ||||||||||
|
wingedfox marked this conversation as resolved.
Outdated
|
||||||||||
| """Link library into the project tree, updates .aird, .capella, .afm to correcrly reflect library in target model. | ||||||||||
|
|
||||||||||
| Parameters | ||||||||||
| ---------- | ||||||||||
| lib | ||||||||||
| path to a library .aird file | ||||||||||
|
|
||||||||||
|
|
||||||||||
| Description | ||||||||||
| ----------- | ||||||||||
| When you need to refere to external library (or reuse one in a project) | ||||||||||
| ``` | ||||||||||
| p = "..." #path to library | ||||||||||
| model._loader._link_library(p) | ||||||||||
|
|
||||||||||
| lib = model.project.extensions[0].reference.library #no longer crashes, all fragments are in place | ||||||||||
|
wingedfox marked this conversation as resolved.
Outdated
|
||||||||||
|
|
||||||||||
| ``` | ||||||||||
| """ | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The docs build is failing because sphinx doesn't like this docstring in particular.
You can test the docs build locally as well (which should be much faster than waiting for CI) with a simple |
||||||||||
| handler = self.resources[str(lib)] | ||||||||||
| _h , filename = _derive_entrypoint(handler) | ||||||||||
| frag = ModelFile( | ||||||||||
| filename, handler, ignore_uuid_dups=self.__ignore_uuid_dups | ||||||||||
| ) | ||||||||||
|
Wuestengecko marked this conversation as resolved.
|
||||||||||
|
|
||||||||||
| p = lib.joinpath(filename) | ||||||||||
| self.trees[p] = frag | ||||||||||
| for ref in _find_refs(frag.root): | ||||||||||
| ref_name = helpers.normalize_pure_path( | ||||||||||
| _unquote_ref(ref), base=p.parent | ||||||||||
| ) | ||||||||||
| self.__load_referenced_files(ref_name) | ||||||||||
|
|
||||||||||
| if ref_name.suffix == ".afm": | ||||||||||
| meta_lib = self.__get_metadata(self.trees[ref_name]) | ||||||||||
| meta_self = self.__find_metadata() | ||||||||||
|
|
||||||||||
| if not next(filter(lambda el: re.search(str(ref_name), el.attrib["href"]), meta_self.iterchildren("additionalResources")), None): | ||||||||||
| ael = meta_self.makeelement("additionalMetadata", href=f"../{ref_name}#{meta_lib.attrib['id']}") | ||||||||||
| meta_self.append(ael) | ||||||||||
| elif ref_name.suffix == ".capella": | ||||||||||
| aird_self = self.trees[pathlib.PurePosixPath(f"\x00/{self.entrypoint}")] | ||||||||||
|
|
||||||||||
| last = next(filter(lambda el: re.search(str(ref_name), el.text), XP_SEMANTIC_RESOURCES(aird_self.root)), None) | ||||||||||
|
wingedfox marked this conversation as resolved.
Outdated
|
||||||||||
| if not last: | ||||||||||
| for r in XP_SEMANTIC_RESOURCES(aird_self.root): | ||||||||||
| last = r | ||||||||||
|
|
||||||||||
| if last is not None: | ||||||||||
| sr = last.makeelement("semanticResources") | ||||||||||
| sr.text = f"platform:/resource/{ref_name}" | ||||||||||
| last.addnext(sr) | ||||||||||
|
|
||||||||||
| def __load_referenced_files( | ||||||||||
| self, resource_path: pathlib.PurePosixPath | ||||||||||
| ) -> None: | ||||||||||
|
|
@@ -1345,11 +1425,7 @@ def __find_metadata(self) -> etree._Element: | |||||||||
| ) | ||||||||||
| if afm is None: | ||||||||||
| raise RuntimeError("Cannot find .afm file in primary resource") | ||||||||||
| metadata = next(afm.root.iter(METADATA_TAG), None) | ||||||||||
| if metadata is None: | ||||||||||
| raise RuntimeError("Cannot find <Metadata> in primary .afm file") | ||||||||||
| LOGGER.debug("Found <Metadata> with ID %s", metadata.get("id")) | ||||||||||
| return metadata | ||||||||||
| return self.__get_metadata(afm) | ||||||||||
|
|
||||||||||
| def referenced_viewpoints(self) -> cabc.Iterator[tuple[str, str]]: | ||||||||||
| metadata = self.__find_metadata() | ||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| from __future__ import annotations | ||
|
|
||
| import capellambse.model as m | ||
| from capellambse.metamodel import re | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know why Github isn't running CI for this PR. Could you please make sure you run all the pre-commit hooks locally with |
||
|
|
||
| from . import capellacore | ||
| from . import namespaces as ns | ||
|
|
@@ -57,6 +58,10 @@ class SystemEngineering(capellacore.AbstractModellingStructure, ModelRoot): | |
| [source:MIL-STD 499B standard] | ||
| """ | ||
|
|
||
| extensions = m._descriptors.Containment[re.ReElementContainer]( | ||
| "ownedExtensions", (ns.RE, "RecCatalog") | ||
| ) | ||
|
wingedfox marked this conversation as resolved.
Outdated
|
||
|
|
||
| @property | ||
| def oa(self) -> oa.OperationalAnalysis: | ||
| from . import oa # noqa: PLC0415 | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.