Skip to content

Commit

Permalink
merge: CapellaMBSE Coding Friday
Browse files Browse the repository at this point in the history
  • Loading branch information
Wuestengecko committed Nov 18, 2022
2 parents 60ab552 + 7b7dad9 commit 44fc986
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 6 deletions.
2 changes: 1 addition & 1 deletion capellambse/aird/capstyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class in the form::
and diagramclass
and objectclass not in STYLES.get(diagramclass, {})
):
LOGGER.warning(
LOGGER.debug(
"No default style for %r in %r", objectclass, diagramclass
)
try:
Expand Down
2 changes: 1 addition & 1 deletion capellambse/loader/filehandler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def load_entrypoint(handler_name: str) -> type[FileHandler]:
)
if not eps:
raise ValueError(f"Unknown file handler {handler_name}")
return eps[0].load()
return next(iter(eps)).load()


def get_filehandler(path: str | os.PathLike, **kwargs: t.Any) -> FileHandler:
Expand Down
4 changes: 3 additions & 1 deletion capellambse/model/common/accessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,9 @@ def __init__(
"""
if not tag:
warnings.warn(
"Unspecified XML tag is deprecated", DeprecationWarning
"Unspecified XML tag is deprecated",
DeprecationWarning,
stacklevel=2,
)
elif not isinstance(tag, str):
raise TypeError(f"tag must be a str, not {type(tag).__name__}")
Expand Down
8 changes: 5 additions & 3 deletions capellambse/model/common/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,11 @@ def new_hash(self) -> int:

# <https://github.com/DSD-DBS/py-capellambse/issues/52>
warnings.warn(
"Hashing of this type is broken and will likely be removed in the future."
f" Consider using the `.uuid` or `.{attr}` directly instead.",
"Hashing of this type is broken and will likely be removed in"
f" the future. Please use the `.uuid` or `.{attr}` directly"
" instead.",
category=FutureWarning,
stacklevel=2,
)

return orig_hash(self)
Expand Down Expand Up @@ -120,7 +122,7 @@ class GenericElement:
)

constraints: accessors.Accessor
parent: accessors.Accessor
parent: accessors.ParentAccessor

_required_attrs = frozenset({"uuid", "xtype"})
_xmltag: str | None = None
Expand Down
21 changes: 21 additions & 0 deletions capellambse/repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@
import textwrap
import typing as t

from lxml import etree

import capellambse
from capellambse.loader import exs

try:
import readline
Expand Down Expand Up @@ -118,6 +121,11 @@ def _parse_args(args: list[str] | None = None) -> dict[str, t.Any]:
+ ", ".join(f"``{i}``" for i in known_models)
),
)
parser.add_argument(
"--disable-diagram-cache",
action="store_true",
help="Disable the diagram cache, if one was defined for the model",
)
parser.add_argument(
"--dump",
action="store_true",
Expand Down Expand Up @@ -158,6 +166,9 @@ def _parse_args(args: list[str] | None = None) -> dict[str, t.Any]:
if pargs.wipe:
modelinfo["disable_cache"] = True

if pargs.disable_diagram_cache and "diagram_cache" in modelinfo:
del modelinfo["diagram_cache"]

if pargs.dump:
print(json.dumps(modelinfo, indent=2))
raise SystemExit(0)
Expand Down Expand Up @@ -245,6 +256,14 @@ def suppress(
logging.info("Exception suppressed", exc_info=True)


def showxml(obj: capellambse.ModelObject | etree._Element) -> None:
if isinstance(obj, etree._Element):
elm = obj
else:
elm = obj._element
print(exs.to_string(elm), end="")


def main() -> None:
"""Launch a simple Python REPL with a Capella model."""
os.chdir(pathlib.Path(capellambse.__file__).parents[1])
Expand All @@ -256,12 +275,14 @@ def main() -> None:
interactive_locals = {
"__doc__": None,
"__name__": "__console__",
"etree": etree,
"im": importlib,
"imm": importlib.import_module("importlib.metadata"),
"imr": importlib.import_module("importlib.resources"),
"logtee": logtee,
"model": model,
"pprint": importlib.import_module("pprint").pprint,
"showxml": showxml,
"suppress": suppress,
}

Expand Down

0 comments on commit 44fc986

Please sign in to comment.