-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevents.py
153 lines (98 loc) · 2.92 KB
/
events.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import dataclasses
import typing
from pathlib import Path
import util.general
import util.ordering
# ## Interfaces.
#
# Each interface defined here forms a preorder (the priority preorder).
# The partial order relation is inherited from the attribute _key.
# This attribute defines the priority of an instance.
# If a._key <= b._key, then a has priority over b.
_dataclass_incomparable = dataclasses.dataclass(eq=False)
def _decorator(x):
return _dataclass_incomparable(
# pylint: disable-next=protected-access
util.ordering.preorder_from_key(x, key=lambda x: x._key)
)
@_decorator
class ProgramEvent:
pass
@_decorator
class CourseEvent:
pass
@_decorator
class LabEvent:
pass
@_decorator
class GroupProjectEvent:
pass
@_decorator
class GroupProjectResponseEvent:
pass
# ## Instances of ProgramEvent.
@_dataclass_incomparable
class TerminateProgram(ProgramEvent):
_key = (0,)
@_dataclass_incomparable
class ProgramEventInCourse(ProgramEvent):
course_dir: Path
course_event: CourseEvent
@property
def _key(self):
return (1, util.ordering.DiscreteOrder(self.course_dir), self.course_event)
# ## Instances of CourseEvent.
@_dataclass_incomparable
class ReloadCourse(CourseEvent):
_key = (0,)
@_dataclass_incomparable
class SyncFromCanvas(CourseEvent):
_key = (1, util.ordering.DiscreteOrder(0))
@_dataclass_incomparable
class CourseEventInLab(CourseEvent):
lab_id: typing.Any
lab_event: LabEvent
@property
def _key(self):
return (
1,
util.ordering.DiscreteOrder(1),
util.ordering.DiscreteOrder(self.lab_id),
self.lab_event,
)
# ## Instances of LabEvent.
@_dataclass_incomparable
class RefreshLab(LabEvent):
_key = (0,)
@_dataclass_incomparable
class LabEventInGroupProject(LabEvent):
group_id: typing.Any
group_project_event: GroupProjectEvent
@property
def _key(self):
return (1, util.ordering.DiscreteOrder(self.group_id), self.group_project_event)
# ## Instances of GroupProjectEvent.
@_dataclass_incomparable
class GroupProjectWebhookEvent(GroupProjectEvent):
pass
@_dataclass_incomparable
class GroupProjectTagEvent(GroupProjectWebhookEvent):
_key = (0,)
@_dataclass_incomparable
class GroupProjectWebhookResponseEvent(GroupProjectWebhookEvent):
"""
GroupProjectResponseEvent has priority over GroupProjectTagEvent.
This is because we need to reload requests anyway
after reloading responses before merging them.
"""
group_project_response_event: GroupProjectResponseEvent
@property
def _key(self):
return (1, self.group_project_response_event)
# ## Instances of GroupProjectResponseEvent
@_dataclass_incomparable
class GroupProjectIssueEvent(GroupProjectResponseEvent):
_key = ()
@_dataclass_incomparable
class GroupProjectGradingMergeRequestEvent(GroupProjectResponseEvent):
_key = ()