-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added newer DefaultTraversal rules to align with V3 sharp connectors (#…
…367) * First Pass * Updated traversal --------- Co-authored-by: KatKatKateryna <[email protected]>
- Loading branch information
1 parent
0fbfff5
commit 405972f
Showing
3 changed files
with
45 additions
and
6 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
src/specklepy/objects/graph_traversal/default_traversal.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from specklepy.objects.base import Base | ||
from specklepy.objects.graph_traversal.traversal import GraphTraversal, TraversalRule | ||
|
||
DISPLAY_VALUE_PROPERTY_ALIASES = {"displayValue", "@displayValue"} | ||
ELEMENTS_PROPERTY_ALIASES = {"elements", "@elements"} | ||
|
||
|
||
def has_display_value(x: Base): | ||
return any(hasattr(x, alias) for alias in DISPLAY_VALUE_PROPERTY_ALIASES) | ||
|
||
|
||
def create_default_traversal_function() -> GraphTraversal: | ||
""" | ||
Traversal func for traversing the root object of a Speckle Model | ||
""" | ||
|
||
convertible_rule = TraversalRule( | ||
[lambda b: b.speckle_type != "Base", has_display_value], | ||
lambda _: ELEMENTS_PROPERTY_ALIASES, | ||
) | ||
|
||
default_rule = TraversalRule( | ||
[lambda _: True], | ||
# NOTE: Unlike the C# implementation, this does not ignore Obsolete members | ||
lambda o: o.get_member_names(), | ||
False, | ||
) | ||
|
||
return GraphTraversal([convertible_rule, default_rule]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters