LockedModel

class LockedModel

A SysML v2/KerML model interface. Top level elements (typically Packages) can be accessed through the lookup method, e.g. model.lookup("PackageName"). To create a new top level package use the new_top_level_package method.

The object is invalidated once unlocked, either explicitly or by leaving the outermost with-block when used as a context manager.

Note that LockedModel is generally not intended to be instantiated directly. Ideally, use either open_model or empty_model. Alternatively, instantiate UnlockedModel and use UnlockedModel.lock.

model : LockedModel = empty_model()

## Alternatively
unlocked_model = open_model_unlocked(...)

model : LockedModel = unlocked_model.lock()
Members defined in LockedModel (9 members)

diagnostics

R

Diagnostics generated when the model was loaded.

lookup

If path is empty, yields the (unique) top-level owned member element with name name if it exists, otherwise returns None. Note that elements other than owned member elements, such as imported or inherited ones, are not taken into account.

new_top_level_library_package

Creates a (named) new top level package.

new_top_level_package

Creates a (named) new top level package.

top_elements

Yields all top level named elements (typically Packages) that are owned members of a root namespace in the model. Note that imported members are not taken into account.

top_elements_from

Yields top level owned member elements (typically Packages) loaded from the specified path(or from files below that path if it is a directory). Note that imported members are not taken into account.

top_named_elements

Yields all named top level named elements (typically Packages) that are owned members of a root namespace in the model, together with (one of) their names. Note that imported members are not taken into account.

top_names

Yields names of all top level named elements (typically Packages) that are owned members of a root namespace in the model. Note that imported members are not taken into account.

unlock

Unlocks the model, freeing it up for others to lock.

Attributes

property diagnostics: syside.Diagnostics

Diagnostics generated when the model was loaded.

Methods

lookup(name: str, *path: str) syside.Element | None

If path is empty, yields the (unique) top-level owned member element with name name if it exists, otherwise returns None. Note that elements other than owned member elements, such as imported or inherited ones, are not taken into account.

Otherwise .lookup(name, name, path1, ..., pathn) is equal to .lookup(name).lookup(path1).[...].lookup(pathn), unless any intermediate value is None. If any intermediate value is None the whole expression evaluates to None.

Parameters:
  • name – name of element to find

  • path – sequence of names to (recursively) lookup

Returns:

(unique) element with name name or None (if not found)

Raises:
  • RuntimeError – if used after unlocking

  • TypeError – if trying to recursively look-up into a non-Namespace element.

  • NameError – if the name is ambiguous.

new_top_level_library_package(name: str) syside.LibraryPackage

Creates a (named) new top level package.

Parameters:

name – name of the new package

Returns:

a new syside.LibraryPackage named name (in a new global namespace)

Raises:

RuntimeError – if used after unlocking

new_top_level_package(name: str) syside.Package

Creates a (named) new top level package.

Parameters:

name – name of the new package

Returns:

a new syside.Package named name (in a new global namespace)

Raises:

RuntimeError – if used after unlocking

top_elements() Iterator[syside.Element]

Yields all top level named elements (typically Packages) that are owned members of a root namespace in the model. Note that imported members are not taken into account.

Returns:

sequence of top level elements

Raises:

RuntimeError – if used after unlocking

top_elements_from(path: str | pathlib.Path) Iterator[syside.Element]

Yields top level owned member elements (typically Packages) loaded from the specified path(or from files below that path if it is a directory). Note that imported members are not taken into account.

Parameters:

path – source file or directory path to return elements loaded from

Returns:

sequence of (top) model elements loaded from source file(s) matching path

Raises:

RuntimeError – if used after unlocking

top_named_elements() Iterator[tuple[str, syside.Element]]

Yields all named top level named elements (typically Packages) that are owned members of a root namespace in the model, together with (one of) their names. Note that imported members are not taken into account.

Prefers name over short name.

Returns:

sequence of (name, element) pairs of named top level elements

Raises:

RuntimeError – if used after unlocking

top_names() Iterator[str]

Yields names of all top level named elements (typically Packages) that are owned members of a root namespace in the model. Note that imported members are not taken into account.

Prefers name over short name.

Returns:

sequence of names of named top level elements

Raises:

RuntimeError – if used after unlocking

unlock() syside.preview.UnlockedModel

Unlocks the model, freeing it up for others to lock.

Returns:

UnlockedModel that can be used to re-acquire access to the model

Raises:

RuntimeError – if used after unlocking

Used in