Skip to content

Save model namespace #3531

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

Merged
merged 23 commits into from
Oct 27, 2024
Merged

Save model namespace #3531

merged 23 commits into from
Oct 27, 2024

Conversation

amolenaar
Copy link
Member

@amolenaar amolenaar commented Oct 13, 2024

PR Type

What kind of change does this PR introduce?

  • Bug fix
  • Feature
  • Chore (refactoring, formatting, local variables, other cleanup)
  • Documentation content changes

What is the current behavior?

All model elements are stored in a flat namespace. Hence we cannot have elements with the same name in different models.

In the application we have the concept of ModelingLanguages. This concept should be extended to file storage.

Issue Number: #1399, #2584

What is the new behavior?

  • Elements are saved in a namespace that matches the modeling language its part of.
  • Elements are stored and loaded by the right ModelingLanguage.
  • Gaphor can check beforehand (based on XML namespaces) if the required modeling language is available.
  • The C4 model will have components with normal names: Container (not C4Container) and Dependency (not C4Dependency).
  • Use model name in ElementDispatcher service (maybe use default modeling language (based on package) and fall back on global search?
  • Use model name in Recovery service
  • Use model name in merge conflict resolver
  • Optional: models use aliases for all imported types: e.g. from core import Element as _Element separate PR, see TODO's.
  • Update model loader. Dependency -> UML.Dependency, C4Dependency -> C4Model:Dependency, and rename other C4 elements.
  • Update modeling language documentation: mention __modeling_language__ convention.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

To make it work, at the modeling language toplevel, I added a special property __modeling_language__. This property should match the name of the modeling language as defined in pyproject.toml.

Replaced Base.umlproperties() by Base.__properties__. That looks more in line with our __modeling_language__ meta property.

I introduced new namespaces for the new model feature: https://gaphor.org/model, and https://gaphor.org/modelinglanguage/{modeling_language}.

The general diagram items (comment, line, etc.) now have their own modeling language object.

The XML writer has been modernized.

@amolenaar amolenaar marked this pull request as draft October 13, 2024 08:36
@github-actions github-actions bot added the python Pull requests that update Python code label Oct 13, 2024
@amolenaar amolenaar force-pushed the save-model-namespace branch 2 times, most recently from 2dfc9af to b04d22c Compare October 13, 2024 14:59
@amolenaar amolenaar force-pushed the save-model-namespace branch 2 times, most recently from f90880a to 7a4a7a4 Compare October 13, 2024 19:47
@amolenaar amolenaar force-pushed the save-model-namespace branch 2 times, most recently from 23fea7e to 6fe65ef Compare October 15, 2024 21:31
Base automatically changed from element-base to main October 16, 2024 00:38
This gives us the opportunity to derive the
modeling language from the stored element name (with NS).
It makes little sense to implement the SAX ContentHandler interface
for writing. Instead let's use a small Pythonic interface based on
with-blocks.
This makes it easier to look up the modeling language
from a class.
Use dunder syntax, since it kind of meta data for the class.
Also introduced extra syntax to tell which modeling language
an element is coming from.
@amolenaar amolenaar force-pushed the save-model-namespace branch from 3464df6 to 3fa6ac1 Compare October 16, 2024 08:39
@amolenaar amolenaar marked this pull request as ready for review October 16, 2024 08:41
@amolenaar amolenaar force-pushed the save-model-namespace branch from ed6294c to d8fa658 Compare October 16, 2024 12:44
@amolenaar amolenaar requested a review from danyeaw October 16, 2024 12:47
@amolenaar amolenaar force-pushed the save-model-namespace branch 3 times, most recently from abad84a to 529f8d5 Compare October 16, 2024 14:16
Now it's no longer mixed with the UML model, which is, I think,
more clean.
@amolenaar amolenaar force-pushed the save-model-namespace branch from 529f8d5 to 8bf4626 Compare October 16, 2024 14:22
@amolenaar amolenaar mentioned this pull request Oct 19, 2024
6 tasks
Copy link
Member

@danyeaw danyeaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @amolenaar, this is fantastic, I really like the split of the namespaces like this!

@danyeaw danyeaw added feature A new feature and removed python Pull requests that update Python code documentation labels Oct 27, 2024
@danyeaw danyeaw merged commit b01c529 into main Oct 27, 2024
23 checks passed
@danyeaw danyeaw deleted the save-model-namespace branch October 27, 2024 11:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants