-
Notifications
You must be signed in to change notification settings - Fork 1
Implement recursive copying helper #563
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
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
cdc496b
[TMP] Prototype recursive clone code
greschd 7f0d6c6
Add docstring to recursive_copy
greschd f5a400d
Add more recursive_copy tests
greschd 0a0967b
Improve docstrings
greschd 692c49e
Fix LUT copying in recursive copy
greschd 435df2a
Fix allowed values in reference_direction_field, small bugfix in .sto…
greschd 82f0ed9
Use linked_object_helpers to replace links
greschd 080d33b
Update src/ansys/acp/core/_recursive_copy.py
greschd 22a2b0c
Implement KEEP / COPY / DISCARD link handling modes
greschd 7113b81
Make tree objects hashable, use them in dict
greschd 74c00ae
Switch to returning an old -> new mapping
greschd 20d9f12
Fix tests
greschd c2ba9a1
Fix pre-commit hooks and doc build
greschd 5525c3d
Remove _traversal helpers, move dependency graph generation to separa…
greschd f6f9fb0
Implement suggestions from code review
greschd b32c7aa
Fix tests
greschd 8eea31d
Test exceptions when copying across models
greschd 3418124
Merge branch 'main' into feat/recursive_clone
greschd 0063971
Improve test_properties performance
greschd 2222235
Adapt test_workflow_unit_system_dat to server changes
greschd 500b2b8
Add tests for EdgePropertyType clone
greschd 37c5c0c
Add tests for the .parent property
greschd 9a3d478
Add multiple coverage uploads
greschd 27174ef
Remove broken HTML coverage upload
greschd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ and attributes. | |
| material_property_sets | ||
| enum_types | ||
| plot_utils | ||
| other_utils | ||
| workflow | ||
| example_helpers | ||
| internal | ||
This file contains hidden or 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,9 @@ | ||
| Other utilities | ||
| --------------- | ||
|
|
||
| .. currentmodule:: ansys.acp.core | ||
|
|
||
| .. autosummary:: | ||
| :toctree: _autosummary | ||
|
|
||
| recursive_copy |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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,108 @@ | ||
| # Copyright (C) 2022 - 2024 ANSYS, Inc. and/or its affiliates. | ||
| # SPDX-License-Identifier: MIT | ||
| # | ||
| # | ||
| # Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| # of this software and associated documentation files (the "Software"), to deal | ||
| # in the Software without restriction, including without limitation the rights | ||
| # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| # copies of the Software, and to permit persons to whom the Software is | ||
| # furnished to do so, subject to the following conditions: | ||
| # | ||
| # The above copyright notice and this permission notice shall be included in all | ||
| # copies or substantial portions of the Software. | ||
| # | ||
| # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| # SOFTWARE. | ||
|
|
||
| from collections.abc import Iterable, Iterator | ||
| from dataclasses import dataclass | ||
|
|
||
| import networkx as nx | ||
|
|
||
| from ._tree_objects._grpc_helpers.linked_object_helpers import get_linked_paths | ||
| from ._tree_objects._grpc_helpers.mapping import Mapping | ||
| from ._tree_objects._grpc_helpers.polymorphic_from_pb import tree_object_from_resource_path | ||
| from ._tree_objects.base import CreatableTreeObject, TreeObject | ||
|
|
||
|
|
||
| @dataclass | ||
| class _WalkTreeOptions: | ||
| include_children: bool | ||
| include_linked_objects: bool | ||
|
|
||
|
|
||
| def _build_dependency_graph( | ||
| *, source_objects: Iterable[CreatableTreeObject], options: _WalkTreeOptions | ||
| ) -> nx.DiGraph: | ||
| """Build a dependency graph of the given objects.""" | ||
| graph = nx.DiGraph() | ||
|
|
||
| # We need to manually keep track of which objects have been visited, | ||
| # since the node may also be created when being linked to. | ||
| visited_objects: set[CreatableTreeObject] = set() | ||
| for tree_object in source_objects: | ||
| _build_dependency_graph_impl( | ||
| tree_object=tree_object, graph=graph, visited_objects=visited_objects, options=options | ||
| ) | ||
| return graph | ||
|
|
||
|
|
||
| def _build_dependency_graph_impl( | ||
| *, | ||
| tree_object: CreatableTreeObject, | ||
| graph: nx.DiGraph, | ||
| visited_objects: set[CreatableTreeObject], | ||
| options: _WalkTreeOptions, | ||
| ) -> None: | ||
|
|
||
| if tree_object in visited_objects: | ||
| return | ||
|
|
||
| visited_objects.add(tree_object) | ||
| graph.add_node(tree_object) | ||
|
|
||
| if options.include_children: | ||
| for child_object in _yield_child_objects(tree_object): | ||
| if not isinstance(child_object, CreatableTreeObject): | ||
| continue | ||
| graph.add_edge(child_object, tree_object) | ||
| _build_dependency_graph_impl( | ||
| tree_object=child_object, | ||
| graph=graph, | ||
| visited_objects=visited_objects, | ||
| options=options, | ||
| ) | ||
| if options.include_linked_objects: | ||
| for linked_object in _yield_linked_objects(tree_object): | ||
| graph.add_edge(tree_object, linked_object) | ||
| _build_dependency_graph_impl( | ||
| tree_object=linked_object, | ||
| graph=graph, | ||
| visited_objects=visited_objects, | ||
| options=options, | ||
| ) | ||
|
|
||
|
|
||
| def _yield_child_objects(tree_object: TreeObject) -> Iterator[TreeObject]: | ||
| for attr_name in tree_object._GRPC_PROPERTIES: | ||
| try: | ||
| attr = getattr(tree_object, attr_name) | ||
| except (AttributeError, RuntimeError): | ||
| continue | ||
| if isinstance(attr, Mapping): | ||
| yield from attr.values() | ||
|
|
||
|
|
||
| def _yield_linked_objects(tree_object: TreeObject) -> Iterator[CreatableTreeObject]: | ||
| for linked_path in get_linked_paths(tree_object._pb_object.properties): | ||
| linked_object = tree_object_from_resource_path( | ||
| linked_path, server_wrapper=tree_object._server_wrapper | ||
| ) | ||
| assert isinstance(linked_object, CreatableTreeObject) | ||
| yield linked_object | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.