Skip to content
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

Gaphas 3 support #501

Merged
merged 39 commits into from Dec 19, 2020
Merged

Gaphas 3 support #501

merged 39 commits into from Dec 19, 2020

Conversation

amolenaar
Copy link
Member

@amolenaar amolenaar commented Oct 26, 2020

PR Type

What kind of change does this PR introduce?

  • Feature / refactoring

What is the current behavior?

The Gaphas 2 architecture is 10+ years old. We want to add some new features (e.g. grey our elements a line can not connect to) we need an upgrade of the library.

See: https://github.com/orgs/gaphor/projects/1

What is the new behavior?

In this branch I'll keep up to date with the changes made to gaphas, so I do not have to make all changes in one shot after a new Gaphas version has been released. I tried to limit the changes and add functionality that was removed from gaphas (like pre/post update). This way I hope to limit the actual code change.

  • Diagram implements the gaphas.view.Model protocol
  • pre/post_update() is no longer part of Gaphas. Has been implemented in Gaphor for the time being.
  • Tools are implemented as GTK Event controllers
  • Items get an explicit connections object. Used to manage in- and external constraints.
  • Loading and saving no longer need workarounds to avoid the canvas being updated too often
  • Implemented a custom Selection object, where we can manage dropzone_item and dragged item/handle at some point

Future work

  • Diagram should replace the functionality of gaphas.Canvas
  • Items still have their reference to a canvas. This can be replaced by an association to the containing diagram
  • Parent/child relationships are still managed by the canvas. This can be changed to use normal UML associations

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@amolenaar amolenaar force-pushed the gaphas-3 branch 2 times, most recently from d22c482 to 0f24ba3 Compare December 4, 2020 20:33
This may fix the windows build.
Cleaned up mypy config.
They will be removed from Gaphas.
@danyeaw danyeaw added the chore Maintenance related PR label Dec 16, 2020
@amolenaar amolenaar marked this pull request as ready for review December 17, 2020 07:22
mypy.ini Show resolved Hide resolved
gaphor/UML/tests/test_sanitizerservice.py Outdated Show resolved Hide resolved
yield item
yield from self._tree.get_ancestors(item)

all_dirty_items = list(reversed(list(sort(dirty_items_with_ancestors()))))
Copy link
Member

Choose a reason for hiding this comment

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

Would it be better to call sorted(list(dirty_items_with_ancestors())), reversed=True)? I got a lot lost here and below on line 293 to be honest with sorting the generator, converting it to a list, reversing it, and then creating another list.

Copy link
Member Author

Choose a reason for hiding this comment

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

The sort() method is coming from the canvas.

It's not the prettiest bit of code. I removed the reversed flag from the sort method: it was only used for this case, and I remove pre/post_update methods from the library, therefore it seemed to make sense to remove the reversed argument as well. It's a bummer you can only reverse a list and not a iterable.

My cunning plan is to het rid of pre/post_update in gaphor as well. We'll have to see how that works out, though :).

gaphor/services/copyservice.py Outdated Show resolved Hide resolved
gaphor/ui/diagrampage.py Show resolved Hide resolved
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.

Really awesome job migrating everything to support the updates to Gaphas! 👍 I saw you started to use EventControllers which also looks really good.

Sorry most of my comments are nitpicks 😄

gaphor/diagram/selection.py Outdated Show resolved Hide resolved
return gesture


def on_drag_begin(gesture, start_x, start_y, placement_state):
Copy link
Member

Choose a reason for hiding this comment

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

I noticed some of the new code doesn't have type hints, did we want to add those in before merging?

danyeaw and others added 2 commits December 18, 2020 08:57
Signed-off-by: Dan Yeaw <dan@yeaw.me>

# Conflicts:
#	poetry.lock
@amolenaar
Copy link
Member Author

amolenaar commented Dec 18, 2020

I noticed that redraws do not happen, when undo'ing. I have to look into it.

Update: fixed

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Dec 18, 2020

Sourcery Code Quality Report

✅  Merging this PR will increase code quality in the affected files by 0.28%.

Quality metrics Before After Change
Complexity 2.98 ⭐ 2.85 ⭐ -0.13 👍
Method Length 47.24 ⭐ 46.05 ⭐ -1.19 👍
Working memory 8.58 🙂 8.55 🙂 -0.03 👍
Quality 73.95% 🙂 74.23% 🙂 0.28% 👍
Other metrics Before After Change
Lines 14235 14110 -125
Changed files Quality Before Quality After Quality Change
docs/conf.py 58.38% 🙂 58.15% 🙂 -0.23% 👎
gaphor/SysML/toolbox.py 54.18% 🙂 54.69% 🙂 0.51% 👍
gaphor/SysML/blocks/block.py 64.08% 🙂 63.96% 🙂 -0.12% 👎
gaphor/SysML/blocks/blockstoolbox.py 48.83% 😞 49.69% 😞 0.86% 👍
gaphor/SysML/blocks/property.py 82.78% ⭐ 81.17% ⭐ -1.61% 👎
gaphor/SysML/blocks/proxyport.py 83.22% ⭐ 85.56% ⭐ 2.34% 👍
gaphor/SysML/requirements/relationships.py 81.77% ⭐ 81.67% ⭐ -0.10% 👎
gaphor/SysML/requirements/requirement.py 54.76% 🙂 54.62% 🙂 -0.14% 👎
gaphor/SysML/requirements/requirementstoolbox.py 51.52% 🙂 52.48% 🙂 0.96% 👍
gaphor/UML/sanitizerservice.py 75.33% ⭐ 75.26% ⭐ -0.07% 👎
gaphor/UML/actions/action.py 71.98% 🙂 71.85% 🙂 -0.13% 👎
gaphor/UML/actions/actionseditors.py 83.80% ⭐ 83.69% ⭐ -0.11% 👎
gaphor/UML/actions/actionstoolbox.py 67.98% 🙂 68.04% 🙂 0.06% 👍
gaphor/UML/actions/activitynodes.py 75.63% ⭐ 76.87% ⭐ 1.24% 👍
gaphor/UML/actions/flow.py 71.07% 🙂 70.77% 🙂 -0.30% 👎
gaphor/UML/actions/flowconnect.py 63.83% 🙂 63.83% 🙂 0.00%
gaphor/UML/actions/objectnode.py 74.30% 🙂 74.20% 🙂 -0.10% 👎
gaphor/UML/actions/partition.py 77.20% ⭐ 77.15% ⭐ -0.05% 👎
gaphor/UML/actions/tests/conftest.py % % %
gaphor/UML/actions/tests/test_activitynodes.py 77.01% ⭐ 78.91% ⭐ 1.90% 👍
gaphor/UML/actions/tests/test_flow.py 87.31% ⭐ 86.41% ⭐ -0.90% 👎
gaphor/UML/actions/tests/test_partition_placement.py 95.02% ⭐ 95.80% ⭐ 0.78% 👍
gaphor/UML/classes/association.py 67.49% 🙂 67.52% 🙂 0.03% 👍
gaphor/UML/classes/classeseditors.py 61.17% 🙂 61.11% 🙂 -0.06% 👎
gaphor/UML/classes/classespropertypages.py 72.68% 🙂 72.67% 🙂 -0.01% 👎
gaphor/UML/classes/classestoolbox.py 85.26% ⭐ 85.34% ⭐ 0.08% 👍
gaphor/UML/classes/dependency.py 83.46% ⭐ 83.46% ⭐ 0.00%
gaphor/UML/classes/generalization.py 90.87% ⭐ 90.76% ⭐ -0.11% 👎
gaphor/UML/classes/implementation.py 81.83% ⭐ 81.77% ⭐ -0.06% 👎
gaphor/UML/classes/interface.py 60.96% 🙂 61.23% 🙂 0.27% 👍
gaphor/UML/classes/interfaceconnect.py 89.77% ⭐ 89.77% ⭐ 0.00%
gaphor/UML/classes/klass.py 70.34% 🙂 70.22% 🙂 -0.12% 👎
gaphor/UML/classes/package.py 68.92% 🙂 68.84% 🙂 -0.08% 👎
gaphor/UML/classes/tests/test_association.py 80.60% ⭐ 80.53% ⭐ -0.07% 👎
gaphor/UML/classes/tests/test_associationconnect.py 84.14% ⭐ 84.14% ⭐ 0.00%
gaphor/UML/classes/tests/test_class.py 68.89% 🙂 68.48% 🙂 -0.41% 👎
gaphor/UML/classes/tests/test_classconnect.py 73.59% 🙂 73.57% 🙂 -0.02% 👎
gaphor/UML/classes/tests/test_interface.py 87.95% ⭐ 87.72% ⭐ -0.23% 👎
gaphor/UML/classes/tests/test_interfaceconnect.py 81.53% ⭐ 81.22% ⭐ -0.31% 👎
gaphor/UML/components/artifact.py 72.47% 🙂 71.52% 🙂 -0.95% 👎
gaphor/UML/components/component.py 62.99% 🙂 62.28% 🙂 -0.71% 👎
gaphor/UML/components/componentstoolbox.py 53.07% 🙂 53.70% 🙂 0.63% 👍
gaphor/UML/components/connector.py 79.07% ⭐ 78.94% ⭐ -0.13% 👎
gaphor/UML/components/connectorconnect.py 62.87% 🙂 62.81% 🙂 -0.06% 👎
gaphor/UML/components/node.py 80.04% ⭐ 79.02% ⭐ -1.02% 👎
gaphor/UML/components/tests/test_connect.py 71.95% 🙂 71.91% 🙂 -0.04% 👎
gaphor/UML/interactions/executionspecification.py 76.58% ⭐ 79.39% ⭐ 2.81% 👍
gaphor/UML/interactions/interaction.py 70.81% 🙂 70.72% 🙂 -0.09% 👎
gaphor/UML/interactions/interactionsconnect.py 73.81% 🙂 73.75% 🙂 -0.06% 👎
gaphor/UML/interactions/interactionstoolbox.py 59.96% 🙂 60.04% 🙂 0.08% 👍
gaphor/UML/interactions/lifeline.py 71.70% 🙂 71.34% 🙂 -0.36% 👎
gaphor/UML/interactions/message.py 75.30% ⭐ 74.48% 🙂 -0.82% 👎
gaphor/UML/interactions/tests/test_executionspecification.py 80.79% ⭐ 81.22% ⭐ 0.43% 👍
gaphor/UML/interactions/tests/test_message.py 80.24% ⭐ 80.30% ⭐ 0.06% 👍
gaphor/UML/profiles/extension.py 86.43% ⭐ 86.31% ⭐ -0.12% 👎
gaphor/UML/profiles/packageimport.py 81.72% ⭐ 79.19% ⭐ -2.53% 👎
gaphor/UML/profiles/profilestoolbox.py 87.93% ⭐ 88.29% ⭐ 0.36% 👍
gaphor/UML/profiles/tests/test_classifier_stereotypes.py 70.62% 🙂 70.65% 🙂 0.03% 👍
gaphor/UML/states/finalstate.py 75.36% ⭐ 75.26% ⭐ -0.10% 👎
gaphor/UML/states/pseudostates.py 85.21% ⭐ 84.57% ⭐ -0.64% 👎
gaphor/UML/states/state.py 67.86% 🙂 67.21% 🙂 -0.65% 👎
gaphor/UML/states/statestoolbox.py 65.02% 🙂 65.08% 🙂 0.06% 👍
gaphor/UML/states/transition.py 71.22% 🙂 70.92% 🙂 -0.30% 👎
gaphor/UML/states/vertexconnect.py 71.12% 🙂 74.17% 🙂 3.05% 👍
gaphor/UML/states/tests/test_states.py 73.49% 🙂 74.92% 🙂 1.43% 👍
gaphor/UML/tests/test_diagrampage_tools.py 80.40% ⭐ 79.01% ⭐ -1.39% 👎
gaphor/UML/tests/test_sanitizerservice.py 78.16% ⭐ 78.00% ⭐ -0.16% 👎
gaphor/UML/usecases/actor.py 61.51% 🙂 61.45% 🙂 -0.06% 👎
gaphor/UML/usecases/extend.py 74.06% 🙂 73.75% 🙂 -0.31% 👎
gaphor/UML/usecases/include.py 74.06% 🙂 73.75% 🙂 -0.31% 👎
gaphor/UML/usecases/usecase.py 74.27% 🙂 74.14% 🙂 -0.13% 👎
gaphor/UML/usecases/usecasetoolbox.py 52.04% 🙂 53.44% 🙂 1.40% 👍
gaphor/core/modeling/diagram.py 82.99% ⭐ 83.91% ⭐ 0.92% 👍
gaphor/core/modeling/elementfactory.py 90.09% ⭐ 90.19% ⭐ 0.10% 👍
gaphor/core/modeling/presentation.py 93.75% ⭐ 93.07% ⭐ -0.68% 👎
gaphor/core/modeling/tests/test_diagram.py 95.13% ⭐ 95.21% ⭐ 0.08% 👍
gaphor/core/modeling/tests/test_diagram_style.py 97.27% ⭐ 96.65% ⭐ -0.62% 👎
gaphor/diagram/connectors.py 77.23% ⭐ 77.20% ⭐ -0.03% 👎
gaphor/diagram/copypaste.py 77.98% ⭐ 77.97% ⭐ -0.01% 👎
gaphor/diagram/diagramtoolbox.py 64.25% 🙂 64.69% 🙂 0.44% 👍
gaphor/diagram/inlineeditors.py 68.24% 🙂 68.18% 🙂 -0.06% 👎
gaphor/diagram/painter.py 83.42% ⭐ 80.71% ⭐ -2.71% 👎
gaphor/diagram/presentation.py 77.27% ⭐ 77.55% ⭐ 0.28% 👍
gaphor/diagram/propertypages.py 85.04% ⭐ 84.98% ⭐ -0.06% 👎
gaphor/diagram/text.py 62.24% 🙂 62.24% 🙂 0.00%
gaphor/diagram/general/comment.py 68.20% 🙂 68.08% 🙂 -0.12% 👎
gaphor/diagram/general/commentline.py 84.75% ⭐ 84.93% ⭐ 0.18% 👍
gaphor/diagram/general/generaleditors.py 73.55% 🙂 73.46% 🙂 -0.09% 👎
gaphor/diagram/general/simpleitem.py 82.20% ⭐ 84.29% ⭐ 2.09% 👍
gaphor/diagram/general/tests/test_comment.py 81.75% ⭐ 81.65% ⭐ -0.10% 👎
gaphor/diagram/general/tests/test_simpleitem.py 98.61% ⭐ 99.88% ⭐ 1.27% 👍
gaphor/diagram/tests/fixtures.py 88.33% ⭐ 88.23% ⭐ -0.10% 👎
gaphor/diagram/tests/test_copypaste.py 76.63% ⭐ 76.23% ⭐ -0.40% 👎
gaphor/diagram/tests/test_diagramtools.py 67.18% 🙂 67.18% 🙂 0.00%
gaphor/diagram/tests/test_presentation.py 83.02% ⭐ 82.91% ⭐ -0.11% 👎
gaphor/plugins/diagramexport/init.py 82.08% ⭐ 80.79% ⭐ -1.29% 👎
gaphor/plugins/diagramexport/gaphorconvert.py 48.54% 😞 48.54% 😞 0.00%
gaphor/services/copyservice.py 85.51% ⭐ 85.67% ⭐ 0.16% 👍
gaphor/services/properties.py 87.63% ⭐ 87.63% ⭐ 0.00%
gaphor/services/tests/test_copyservice.py 71.06% 🙂 70.82% 🙂 -0.24% 👎
gaphor/storage/storage.py 56.40% 🙂 56.36% 🙂 -0.04% 👎
gaphor/storage/tests/test_storage.py 69.80% 🙂 69.95% 🙂 0.15% 👍
gaphor/tests/testcase.py 87.57% ⭐ 86.66% ⭐ -0.91% 👎
gaphor/ui/diagrampage.py 71.34% 🙂 71.80% 🙂 0.46% 👍
gaphor/ui/diagrams.py 82.55% ⭐ 82.51% ⭐ -0.04% 👎
gaphor/ui/elementeditor.py 85.53% ⭐ 85.52% ⭐ -0.01% 👎
gaphor/ui/namespace.py 66.08% 🙂 65.97% 🙂 -0.11% 👎
gaphor/ui/tests/test_diagrampage.py 89.25% ⭐ 89.25% ⭐ 0.00%
gaphor/ui/tests/test_handletool.py 65.25% 🙂 66.06% 🙂 0.81% 👍
tests/test_action_issue.py 49.77% 😞 49.69% 😞 -0.08% 👎
tests/test_issue_gaphas.py 75.24% ⭐ 75.83% ⭐ 0.59% 👍
tests/test_undo.py 71.46% 🙂 71.35% 🙂 -0.11% 👎
win-installer/misc/depcheck.py 63.74% 🙂 63.74% 🙂 0.00%

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
gaphor/UML/classes/association.py AssociationEnd.post_update 17 🙂 340 ⛔ 19 ⛔ 24.82% ⛔ Try splitting into smaller methods. Extract out complex expressions
gaphor/storage/storage.py save_element 28 😞 268 ⛔ 11 😞 29.67% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
gaphor/plugins/diagramexport/gaphorconvert.py pkg2dir.main 25 😞 247 ⛔ 11 😞 32.36% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
gaphor/ui/diagrampage.py DiagramPage._on_drag_data_received 11 🙂 202 😞 27 ⛔ 32.64% 😞 Try splitting into smaller methods. Extract out complex expressions
gaphor/storage/storage.py _load_elements_and_canvasitems 21 😞 195 😞 13 😞 34.99% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Let us know what you think of it by mentioning @sourcery-ai in a comment.

@amolenaar amolenaar merged commit 2e046f5 into master Dec 19, 2020
@amolenaar amolenaar deleted the gaphas-3 branch December 19, 2020 13:04
@amolenaar amolenaar added this to the 2.2 milestone Dec 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Maintenance related PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants