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

Support association of child elements through Python context blocks #29

Open
1 task done
yt-ms opened this issue Sep 27, 2020 · 2 comments
Open
1 task done

Support association of child elements through Python context blocks #29

yt-ms opened this issue Sep 27, 2020 · 2 comments
Labels
enhancement New feature or request low priority Low priority issue

Comments

@yt-ms
Copy link
Collaborator

yt-ms commented Sep 27, 2020

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.

@Midnighter
Copy link
Owner

I'm less enthusiastic about this feature request. In mingrammer it makes more sense to me because the context provides a logical block to add elements to a diagram or sub-cluster. However, even there it is very implicit that every instance and relationship is automatically added to the context object.

Additionally, It seems to me like nesting levels would escalate rather quickly. In my opinion, it will actually make it harder to understand because I have to parse every statement keeping in mind which element is in the active context. I think the other syntax elements that you proposed in #28 and #13 already improve the situation a lot.

So I'm not convinced this is an improvement and I'd rather prioritize adding missing behaviour to the classes.

@yt-ms
Copy link
Collaborator Author

yt-ms commented Sep 27, 2020

OK, fair enough.

@Midnighter Midnighter added enhancement New feature or request low priority Low priority issue labels Sep 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request low priority Low priority issue
Projects
None yet
Development

No branches or pull requests

2 participants