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

Raise error for groups that decorate non-operation functions #544

Merged
merged 34 commits into from
Nov 23, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
0445141
Raise error for groups that decorate non-operation functions
kidrahahjo Jun 19, 2021
d57f051
Update changelog
kidrahahjo Jun 19, 2021
0a8399c
Update error message.
bdice Jun 19, 2021
42e7442
Update changelog.txt
bdice Jun 19, 2021
ba6e2af
Merge remote-tracking branch 'origin/master' into fix/group-decorator…
kidrahahjo Jun 23, 2021
dadc341
Merge branch 'master' into fix/group-decorator-error
kidrahahjo Jun 23, 2021
67a2674
Update changelog version
kidrahahjo Jun 24, 2021
a0dcd34
Update with Bradley's changes
kidrahahjo Jun 24, 2021
aff635e
Merge branch 'master' into fix/group-decorator-error
kidrahahjo Jul 8, 2021
6f6cc89
Merge branch 'master' into fix/group-decorator-error
bdice Jul 30, 2021
792bd81
resolve merge conflicts
kidrahahjo Aug 12, 2021
4a4bc0b
resolve merge conflicts
kidrahahjo Aug 12, 2021
9cd8065
Merge branch 'master' into fix/group-decorator-error
bdice Aug 19, 2021
39ab112
Update changelog.
bdice Aug 19, 2021
63e757e
Use FlowProjectDefinitionError.
bdice Aug 19, 2021
80233f2
Use mock_project for creating FlowProject instances.
bdice Aug 19, 2021
4296546
Add test for multiple lambda functions as operations.
bdice Aug 19, 2021
9aa4a27
Add tests for anonymous functions in groups.
bdice Aug 19, 2021
ee92b19
Use sets instead of lists for operation._flow_groups and group._opera…
bdice Aug 19, 2021
8b14160
Make FlowGroupEntry._operations private.
bdice Aug 19, 2021
6636943
Move error for assigning non-operation to group to definition.
b-butler Sep 17, 2021
df3a754
Update tests to use new decorator ordering.
b-butler Sep 17, 2021
8017e85
Merge branch 'master' into fix/group-decorator-error
bdice Oct 17, 2021
d03fb0f
Move changelog entry.
bdice Oct 17, 2021
06b66e5
Reorder group decorators.
bdice Oct 17, 2021
fe84df8
Merge branch 'master' into fix/group-decorator-error
bdice Nov 8, 2021
6b37a8f
Use correct number of fields in tuple.
bdice Nov 8, 2021
5e67984
Merge remote-tracking branch 'origin/master' into fix/group-decorator…
vyasr Nov 17, 2021
83a3d83
Merge branch 'master' into fix/group-decorator-error
vyasr Nov 18, 2021
884377b
Merge branch 'fix/group-decorator-error' of github.com:glotzerlab/sig…
vyasr Nov 18, 2021
ec32ebb
Fix bug in status generation script that was regenerating without force.
vyasr Nov 18, 2021
ccc6daa
Update reference data.
vyasr Nov 18, 2021
7e6623f
Address PR reviews.
vyasr Nov 19, 2021
774c799
Update flow/project.py
vyasr Nov 19, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions flow/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,14 +686,11 @@ def __call__(self, func):
f"operation. Add @MyProjectClass.operation below group decorator."
)

if hasattr(func, "_flow_groups"):
if self.name in func._flow_groups:
raise FlowProjectDefinitionError(
f"Cannot reregister operation '{func}' with the group '{self.name}'."
)
func._flow_groups.add(self.name)
else:
func._flow_groups = {self.name}
if self.name in func._flow_groups[self._project]:
raise FlowProjectDefinitionError(
f"Cannot reregister operation '{func}' with the group '{self.name}'."
)
func._flow_groups[self._project].add(self.name)
return func

def _set_directives(self, func, directives):
Expand Down Expand Up @@ -1469,10 +1466,10 @@ def __call__(self, func, name=None):
self._parent_class._GROUPS.append(
FlowGroupEntry(name=name, project=self._parent_class, options="")
)
if hasattr(func, "_flow_groups"):
func._flow_groups.add(name)
else:
func._flow_groups = {name}
if not hasattr(func, "_flow_groups"):
func._flow_groups = {}
if self._parent_class not in func._flow_groups:
func._flow_groups[self._parent_class] = {name}
vyasr marked this conversation as resolved.
Show resolved Hide resolved
return func

def with_directives(self, directives, name=None):
Expand Down Expand Up @@ -4366,9 +4363,11 @@ def _register_groups(self):
else:
func = operation._op_func

if hasattr(func, "_flow_groups"):
op_directives = getattr(func, "_flow_group_operation_directives", {})
for group_name in func._flow_groups:
op_directives = getattr(func, "_flow_group_operation_directives", {})
for cls in self.__class__.__mro__:
# Need to use `get` since we don't know which class in the
# hierarchy this function was registered to.
for group_name in func._flow_groups.get(cls, []):
directives = op_directives.get(group_name)
self._groups[group_name].add_operation(
operation_name, operation, directives
Expand Down
2 changes: 1 addition & 1 deletion tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -1802,7 +1802,7 @@ class A(FlowProject):
def test_op(job):
pass

# Make test_op into an operation, then project creation should succeed.
# Make test_op into an operation, then group addition should succeed.
@group
@A.operation
def test_op_2(job):
Expand Down