Skip to content

Commit

Permalink
feat: Add entrypoint to modelinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
ewuerger committed Mar 10, 2023
1 parent cc30c49 commit 0ebc532
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 14 deletions.
17 changes: 13 additions & 4 deletions capellambse/decl.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,13 @@ def _metadata_matches_modelinfo(
received = av.AwesomeVersion(version)
try:
if current < received:
raise ValueError(
msg = (
"Unsupported YAML: The version of the installed"
f" capellambse({current}) is lower than the version with which"
f" the YAMLwas written with ({received})."
)
logger.warning(msg)
raise ValueError(msg)
except av.AwesomeVersionCompareException:
raise ValueError(
"Unsupported YAML: Can't find capellambse in metadata"
Expand All @@ -239,20 +241,27 @@ def _metadata_matches_modelinfo(
if (referencing := metadata.get("referencing")) != "explicit":
raise ValueError(
"Unsupported YAML: Only explicit YAMLs are supported."
f" Got 'referencing: {referencing}'."
f" Got 'referencing: {referencing}'"
)

model_metadata = metadata.get("model", {})
if (hash := model_metadata.get("version")) != model.info.rev_hash:
raise ValueError(
"Unsupported YAML: Model revision hash isn't matching. Got"
f" {hash!r} but current is {model.info.rev_hash!r}."
f" {hash!r} but current is {model.info.rev_hash!r}"
)

if (url := model_metadata.get("url")) != model.info.url:
raise ValueError(
"Unsupported YAML: Model URL isn't matching. Got"
f" {url!r} but current is {model.info.url!r}."
f" {url!r} but current is {model.info.url!r}"
)

entrypoint = model_metadata.get("entrypoint")
if entrypoint != model.info.entrypoint:
raise ValueError(
"Unsupported YAML: Model entrypoint isn't matching. Got"
f" {entrypoint!r} but current is {model.info.entrypoint!r}"
)


Expand Down
1 change: 1 addition & 0 deletions capellambse/loader/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1279,6 +1279,7 @@ def get_model_info(self) -> ModelInfo:
info.capella_version = info.viewpoints.get(
"org.polarsys.capella.core.viewpoint", "UNKNOWN"
)
info.entrypoint = str(self.entrypoint)
return info

@contextlib.contextmanager
Expand Down
1 change: 1 addition & 0 deletions capellambse/loader/modelinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ class ModelInfo:
url: str | None = None
revision: str | None = None
rev_hash: str | None = None
entrypoint: str | None = None
capella_version: str | None = None
viewpoints: dict[str, str] = dataclasses.field(default_factory=dict)
1 change: 1 addition & 0 deletions docs/source/examples/10 Declarative Modeling.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@
"model:\n",
" version: 1234abcd\n",
" url: https://example.com/model.git\n",
" entrypoint: path/to/model.aird\n",
"referencing: explicit\n",
"---\n",
"{model_update}\n",
Expand Down
16 changes: 9 additions & 7 deletions docs/source/start/declarative.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,24 @@ Metadata
.. versionadded:: 0.5.16
Added metadata document to the declarative modelling YAML.

The metadata has the following format:
The metadata section is optional and has the following format:

.. code-block:: yaml
capellambse: 1.0.0
model:
version: 2fd4e1c67a2d28fced849ee1bb76e7391b93eb12
url: https://example.com/model.git
generator: Declarative Modelling Generator 1.0.0
entrypoint: path/to/model.aird
written_by:
capellambse_version: 1.0.0
generator: Declarative Modelling Generator 1.0.0
It gives information about which model the declarative modelling YAML file
wants to change, with which capellambse version and generator it was written
with and the referencing-type. A versioned model (e.g. using a git URL) can be
uniquely identified by its revision and the repository ``url``. These values
are checked against the ``model.info`` during ``decl.apply`` when the
``strict`` parameter is ``True`` (``False`` per default).
with. A versioned model (e.g. using a git URL) can be uniquely identified by
its revision and the repository ``url``. These values are checked against the
``model.info`` during ``decl.apply`` when the ``strict`` parameter is ``True``
(``False`` per default).

Instructions in the declarative modelling YAML may need additional instructions
for references such that the changes are correctly displayed in Capella. E.g.
Expand Down
1 change: 1 addition & 0 deletions tests/data/decl/coffee-machine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
model:
version: 1234abcd
url: https://example.com/model.git
entrypoint: path/to/model.aird
written_by:
capellambse_version: 1.0.0
referencing: explicit
Expand Down
37 changes: 34 additions & 3 deletions tests/test_decl.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@
"capellambse_version": "1.0.0",
"generator": "Example 1.0.0",
},
"model": {"url": "https://example.invalid", "version": "12345678"},
"model": {
"url": "https://example.invalid",
"version": "12345678",
"entrypoint": "path/to/model.aird",
},
"referencing": "explicit",
}

Expand Down Expand Up @@ -100,6 +104,7 @@ def test_loading_with_metadata():
model:
version: "12345678"
url: https://example.invalid
entrypoint: path/to/model.aird
referencing: explicit
---
- parent: !uuid {uuid!r}
Expand Down Expand Up @@ -617,6 +622,24 @@ def test_metadata_checks(
"https://example.com/models/456",
id="Model URL not matching",
),
pytest.param(
{
"model": {
"url": None,
"version": None,
"entrypoint": "other/path/to/model.aird",
},
"written_by": {
"capellambse_version": imm.version("capellambse")
},
"referencing": "explicit",
},
lambda: modelinfo.ModelInfo(
rev_hash=None, url=None, entrypoint="path/to/model.aird"
),
"other/path/to/model.aird",
id="Model entrypoint not matching",
),
],
)
def test_meta_with_ModelInfo_patching(
Expand All @@ -641,13 +664,20 @@ def test_model_generator_not_in_metadata_logs_info(
):
url = "https://example.com/models/123"
rev_hash = "abc123"
entrypoint = "path/to/model.aird"
monkeypatch.setattr(
model._loader,
"get_model_info",
lambda: modelinfo.ModelInfo(url=url, rev_hash=rev_hash),
lambda: modelinfo.ModelInfo(
url=url, rev_hash=rev_hash, entrypoint=entrypoint
),
)
metadata = {
"model": {"url": url, "version": rev_hash},
"model": {
"url": url,
"version": rev_hash,
"entrypoint": entrypoint,
},
"written_by": {"capellambse_version": imm.version("capellambse")},
"referencing": "explicit",
}
Expand Down Expand Up @@ -735,6 +765,7 @@ def patch_metadata(
}
metadata["model"]["version"] = model.info.rev_hash
metadata["model"]["url"] = model.info.url
metadata["model"]["entrypoint"] = model.info.entrypoint
yml = decl.dump(instructions, metadata=metadata)
new_path = tmp_path / decl_path.name
new_path.write_text(yml, encoding="utf8")
Expand Down

0 comments on commit 0ebc532

Please sign in to comment.