Skip to content
This repository was archived by the owner on Jan 21, 2023. It is now read-only.
This repository was archived by the owner on Jan 21, 2023. It is now read-only.

Support association of child elements through Python context blocks #29

Open
@yt-ms

Description

@yt-ms

Checklist

Is your feature related to a problem? Please describe it.

Constructing a tree of elements from Python is quite verbose today:

system = model.add_software_system(name="My System")
container1 = system.add_container(name="Container 1")
component1 = container1.add_component(name="Component 1")
component2 = container1.add_component(name="Component 2")
component1.add_relationship(description="Sends events to", destination=component2)
etc.

Describe the solution you would like.

Using Python context, we could achieve the same outcome in an easier to read manner:

with model:
  with SoftwareSystem("My System"):
    with Container("Container 1") as container1:
      Component("Component 1") >> "Sends events to" >> Component("Component 2")

This would involve establishing appropriate ContextVars in __enter__()/__exit__() and checking for those during constructors to auto-register via the parent's add().

Additional context

This is inspired by mingrammer/diagrams.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions