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

Upgrade to capellambse v0.6.x #28

Merged
merged 2 commits into from
Sep 24, 2024
Merged
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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ repos:
hooks:
- id: mypy
additional_dependencies:
- capellambse==0.5.72
- capellambse==0.6.6
- types-pyyaml==6.0.11
- repo: https://github.com/pylint-dev/pylint
rev: v3.2.7
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ COPY frontend/fetch-version.py ./frontend/
RUN python frontend/fetch-version.py

# Pre-install npm dependencies for context diagrams
RUN python -c "from capellambse_context_diagrams import _elkjs; _elkjs._install_required_npm_pkg_versions()"
RUN python -c "from capellambse_context_diagrams import install_elk; install_elk()"

# Run as non-root user per default
RUN chmod -R 777 /home
Expand Down
24 changes: 8 additions & 16 deletions capella_model_explorer/backend/explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from pathlib import Path

import capellambse
import capellambse.model as m
import fastapi
import markupsafe
import prometheus_client
Expand Down Expand Up @@ -113,15 +114,9 @@ def __make_href_filter(self, obj: object) -> str | None:
if is_undefined(obj) or obj is None:
return "#"

if isinstance(obj, capellambse.model.ElementList):
if isinstance(obj, m.ElementList):
raise TypeError("Cannot make an href to a list of elements")
if not isinstance(
obj,
(
capellambse.model.GenericElement,
capellambse.model.diagram.AbstractDiagram,
),
):
if not isinstance(obj, (m.ModelElement, m.AbstractDiagram)):
raise TypeError(f"Expected a model object, got {obj!r}")

try:
Expand All @@ -132,11 +127,7 @@ def __make_href_filter(self, obj: object) -> str | None:
return self.__make_href(obj)

def __make_href(
self,
obj: (
capellambse.model.GenericElement
| capellambse.model.diagram.AbstractDiagram
),
self, obj: m.ModelElement | m.AbstractDiagram
) -> str | None:
if self.templates_index is None:
return None
Expand Down Expand Up @@ -265,12 +256,13 @@ def render_template(template_name: str, object_id: str):
@self.router.get("/api/model-info")
def model_info():
info = self.model.info
resinfo = info.resources["\x00"]
return {
"title": info.title,
"revision": info.revision,
"hash": info.rev_hash,
"revision": resinfo.revision,
"hash": resinfo.rev_hash,
"capella_version": info.capella_version,
"branch": info.branch,
"branch": resinfo.branch,
"badge": self.model.description_badge,
}

Expand Down
37 changes: 17 additions & 20 deletions capella_model_explorer/backend/model_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import capellambse
import capellambse.model as m
import capellambse.model.common as c
import diff_match_patch
import typing_extensions as te
from capellambse.filehandler import git, local
Expand Down Expand Up @@ -125,9 +124,9 @@ def populate_commits(model: capellambse.MelodyModel):


def _serialize_obj(obj: t.Any) -> t.Any:
if isinstance(obj, c.GenericElement):
if isinstance(obj, m.ModelElement):
return {"uuid": obj.uuid, "display_name": _get_name(obj)}
elif isinstance(obj, c.ElementList):
elif isinstance(obj, m.ElementList):
return [{"uuid": i.uuid, "display_name": _get_name(i)} for i in obj]
elif isinstance(obj, (enum.Enum, enum.Flag)):
return obj.name
Expand Down Expand Up @@ -202,7 +201,7 @@ def get_commit_hashes(path: str) -> list[RevisionInfo]:
return commits


def _get_name(obj: m.diagram.Diagram | c.ModelObject) -> str:
def _get_name(obj: m.ModelObject) -> str:
"""Return the object's name.

If the object doesn't own a name, its type is returned instead.
Expand Down Expand Up @@ -242,18 +241,16 @@ def compare_objects(
children: dict[str, t.Any] = {}
for attr in dir(type(new_object)):
acc = getattr(type(new_object), attr, None)
if isinstance(acc, c.AttributeProperty):
_handle_attribute_property(
attr, old_object, new_object, attributes
)
if isinstance(acc, m.BasePOD):
_handle_pod(attr, old_object, new_object, attributes)
elif isinstance(
acc, c.AttrProxyAccessor | c.LinkAccessor | c.ParentAccessor
acc, m.AttrProxyAccessor | m.LinkAccessor | m.ParentAccessor
):
_handle_accessors(attr, old_object, new_object, attributes)
elif (
# pylint: disable=unidiomatic-typecheck
type(acc) is c.RoleTagAccessor
or (type(acc) is c.DirectProxyAccessor and not acc.rootelem)
type(acc) is m.RoleTagAccessor
or (type(acc) is m.DirectProxyAccessor and not acc.rootelem)
):
_handle_direct_accessors(
attr, old_object, new_object, children, old_model
Expand All @@ -270,7 +267,7 @@ def compare_objects(
return {}


def _handle_attribute_property(attr, old_object, new_object, attributes):
def _handle_pod(attr, old_object, new_object, attributes):
if attr != "uuid":
try:
old_value = getattr(old_object, attr, None)
Expand All @@ -289,8 +286,8 @@ def _handle_attribute_property(attr, old_object, new_object, attributes):
def _handle_accessors(attr, old_object, new_object, attributes):
old_value = getattr(old_object, attr, None)
new_value = getattr(new_object, attr, None)
if isinstance(old_value, c.GenericElement | type(None)) and isinstance(
new_value, c.GenericElement | type(None)
if isinstance(old_value, m.ModelElement | type(None)) and isinstance(
new_value, m.ModelElement | type(None)
):
if old_value is new_value is None:
pass
Expand All @@ -309,8 +306,8 @@ def _handle_accessors(attr, old_object, new_object, attributes):
"previous": _serialize_obj(old_value),
"current": _serialize_obj(new_value),
}
elif isinstance(old_value, c.ElementList | type(None)) and isinstance(
new_value, c.ElementList
elif isinstance(old_value, m.ElementList | type(None)) and isinstance(
new_value, m.ElementList
):
old_value = old_value or []
if [i.uuid for i in old_value] != [i.uuid for i in new_value]:
Expand All @@ -330,8 +327,8 @@ def _handle_direct_accessors(
):
old_value = getattr(old_object, attr, None)
new_value = getattr(new_object, attr, None)
if isinstance(old_value, c.GenericElement | type(None)) and isinstance(
new_value, c.GenericElement | type(None)
if isinstance(old_value, m.ModelElement | type(None)) and isinstance(
new_value, m.ModelElement | type(None)
):
if old_value is new_value is None:
pass
Expand All @@ -357,8 +354,8 @@ def _handle_direct_accessors(
children[new_value.uuid] = compare_objects(
None, new_value, old_model
)
elif isinstance(old_value, c.ElementList | type(None)) and isinstance(
new_value, c.ElementList
elif isinstance(old_value, m.ElementList | type(None)) and isinstance(
new_value, m.ElementList
):
old_value = old_value or []
for item in new_value:
Expand Down
3 changes: 2 additions & 1 deletion capella_model_explorer/backend/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from typing import Any, Dict, List, Optional

import capellambse
import capellambse.model as m
import yaml
from pydantic import BaseModel, Field

Expand All @@ -28,7 +29,7 @@ def find_objects(model, obj_type=None, below=None, attr=None, filters=None):
objects = getter(model)
if hasattr(objects, "_element"):
objects = [objects]
elif not isinstance(objects, capellambse.model.ElementList):
elif not isinstance(objects, m.ElementList):
raise ValueError(
f"Expected a list of model objects or a single model object"
f" for {attr!r} of the model, got {objects!r}"
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ classifiers = [
"Programming Language :: Python :: 3.12",
]
dependencies = [
"capellambse>=0.5.72,<0.6",
"capellambse-context-diagrams",
"capellambse>=0.6.6,<0.7",
"capellambse-context-diagrams>=0.4.0",
"capella-diff-tools",
"diff-match-patch",
"jinja2",
Expand Down
Loading