-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy path__init__.py
258 lines (257 loc) · 9.41 KB
/
__init__.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
"""
Extension module has to follow the naming convention gersemi_{module_name} like
gersemi_example_module, gersemi_acme_corporation, gersemi_qt etc.
"""
command_definitions = {
#
# Key defines canonical name. Usually builtin CMake commands are formatted
# with lower case. Among exception to this rule there are commands from
# ExternalProject module like ExternalProject_Add.
#
# In this example any variant of ExampleSpecificCanonicalName like:
# - examplespecificcanonicalname
# - EXAMPLESPECIFICCANONICALNAME
# - eXaMpLeSpEcIfIcCaNoNiCaLnAmE
# will be reformatted to ExampleSpecificCanonicalName.
#
"ExampleSpecificCanonicalName": {},
#
# In the simplest case commands can have one signature and such signature
# will have the following properties:
# 1) Front positional arguments: these are arguments appearing at the front
# of command invocation that aren't attached to any keyword.
# Example from builtin CMake commands:
#
# configure_file(<input> <output> ...)
#
# 2) Back positional arguments: these are arguments appearing at the back
# of command invocation that aren't attached to any keyword.
# Example:
#
# get_source_file_property(... <property>)
#
# 3) Options: these are arguments that don't have any value following them.
# Example:
#
# include(... [OPTIONAL] [NO_POLICY_SCOPE] ...)
#
# 4) One value keywords: these are arguments that have one value following
# them. Example:
#
# add_test(NAME <name> ... [WORKING_DIRECTORY <dir>] ...)
#
# 5) Multi value keywords: these are arguments that have at least one value
# following them. Example:
#
# target_include_directories(
# ...
# <INTERFACE|PUBLIC|PRIVATE> [items1...]
# [<INTERFACE|PUBLIC|PRIVATE> [items2...]]
# ...
# )
#
"example_pick_movie_to_watch": {
"front_positional_arguments": ["how_to_pick_movie"],
"options": ["EXCLUDE_ALREADY_WATCHED", "IS_FAMILY_FRIENDLY"],
"one_value_keywords": ["DIRECTOR"],
"multi_value_keywords": ["GENRES", "YEAR_RANGE", "RATING_RANGE"],
"back_positional_arguments": ["output_variable"],
},
#
# Names of positional arguments aren't used so they can represented as empty
# strings or gibberish names as long as number of these arguments correctly
# model the command. For documentation purposes it's better to name these
# arguments though.
#
"example_unnamed_positional_arguments": {
"front_positional_arguments": ["", "lorem-ipsum-dolor-sit-amet", ""],
"multi_value_keywords": ["THINGS"],
"back_positional_arguments": ["", ""],
},
#
# 6) Multi value keywords can form sections with their own positional
# arguments and keywords. Example from CMake builtins:
#
# export(
# SETUP <export-name>
# [PACKAGE_DEPENDENCY
# <dep>
# [ENABLED (<bool-true>|<bool-false>|AUTO)]
# [EXTRA_ARGS <args>...]
# ] [...]
# [TARGET
# <target>
# [XCFRAMEWORK_LOCATION <location>]
# ] [...]
# )
#
"example_rate_movies": {
"front_positional_arguments": ["database"],
"options": ["RATE_IN_ONE_TRANSACTION"],
"multi_value_keywords": ["MOVIE"],
#
# Each multi value keyword defined in "sections" can be customized
# in the same way as base case presented in example_pick_movie_to_watch.
#
"sections": {
"MOVIE": {
"front_positional_arguments": ["original_title"],
"options": ["ROUND_UP", "ROUND_DOWN", "ROUND_TO_THE_NEAREST"],
"one_value_keywords": ["RATING"],
"multi_value_keywords": ["ALTERNATIVE_TITLES"],
}
},
},
#
# Nested sections are supported but perhaps it's better to avoid designing
# such commands.
#
"example_nested_sections": {
"front_positional_arguments": ["level_0_arg_1", "level_0_arg_2"],
"back_positional_arguments": ["level_0_arg_3", "level_0_arg_4"],
"options": [
"LEVEL_0___OPTION_1",
"LEVEL_0___OPTION_2",
"LEVEL_0___OPTION_3",
],
"one_value_keywords": ["LEVEL_0___ONE_VALUE_KEYWORD"],
"multi_value_keywords": ["LEVEL_0___MULTI_VALUE_KEYWORD"],
"sections": {
"LEVEL_0___MULTI_VALUE_KEYWORD": {
"front_positional_arguments": [
"level_1_arg_1",
"level_1_arg_2",
],
"back_positional_arguments": [
"level_1_arg_3",
"level_1_arg_4",
],
"options": [
"LEVEL_1___OPTION_1",
"LEVEL_1___OPTION_2",
"LEVEL_1___OPTION_3",
],
"one_value_keywords": ["LEVEL_1___ONE_VALUE_KEYWORD"],
"multi_value_keywords": ["LEVEL_1___MULTI_VALUE_KEYWORD"],
"sections": {
"LEVEL_1___MULTI_VALUE_KEYWORD": {
"front_positional_arguments": [
"level_2_arg_1",
"level_2_arg_2",
],
"back_positional_arguments": [
"level_2_arg_3",
"level_2_arg_4",
],
"options": [
"LEVEL_2___OPTION_1",
"LEVEL_2___OPTION_2",
"LEVEL_2___OPTION_3",
],
"one_value_keywords": ["LEVEL_2___ONE_VALUE_KEYWORD"],
"multi_value_keywords": ["LEVEL_2___MULTI_VALUE_KEYWORD"],
}
},
}
},
},
#
# 7) Another kind of specialized formatting available for multi value
# keywords is specifying "keyword_kinds" entry. Available kinds:
# - "pairs": values after the keyword will be grouped into pairs
# Example (PROPERTIES keyword):
#
# set_directory_properties(
# PROPERTIES
# <prop1> <value1>
# [<prop2> <value2>]
# ...
# )
#
# - "command_line": values after the keyword are treated like a sequence of
# words in command line and will flow to the next line once line length
# limit is reached.
# Example (COMMAND keyword):
#
# execute_process(
# COMMAND <cmd1> [<arguments>]
# [COMMAND <cmd2> [<arguments>]]...
# ...
# )
#
"example_add_movie_to_database": {
"front_positional_arguments": ["movie-name"],
"one_value_keywords": ["DIRECTOR"],
"multi_value_keywords": ["AVAILABLE_SUBTITLES", "CAST", "SUMMARY"],
"keyword_kinds": {
"CAST": "pairs",
"SUMMARY": "command_line",
},
},
#
# "sections" take precedence over "keyword_kinds" because these properties
# are mutually exclusive.
#
"example_keyword_cant_be_both_section_and_special_kind": {
"front_positional_arguments": ["something"],
"multi_value_keywords": ["CONFUSING_ARGUMENTS"],
"sections": {
"CONFUSING_ARGUMENTS": {"one_value_keywords": ["ARG1", "ARG2"]},
},
# dead property
"keyword_kinds": {
"CONFUSING_ARGUMENTS": "command_line",
},
},
#
# 8) Finally command can have multiple signatures which are selected
# through value of first argument. Example:
#
# install(TARGETS <target>... [...])
# install(IMPORTED_RUNTIME_ARTIFACTS <target>... [...])
# install({FILES | PROGRAMS} <file>... [...])
# install(DIRECTORY <dir>... [...])
# install(SCRIPT <file> [...])
# install(CODE <code> [...])
# install(EXPORT <export-name> [...])
# install(PACKAGE_INFO <package-name> [...])
# install(RUNTIME_DEPENDENCY_SET <set-name> [...])
#
# Signatures are specified through "signatures" entries
# and each signature can specify the same properties as in base case.
#
"example_compute_value": {
"signatures": {
"SUM": {
"front_positional_arguments": ["result-variable"],
"multi_value_keywords": ["VALUES"],
},
"PRODUCT": {
"front_positional_arguments": ["result-variable"],
"multi_value_keywords": ["VALUES"],
},
"MAP": {
"front_positional_arguments": ["result-variable"],
"one_value_keywords": ["FUNCTION"],
"multi_value_keywords": ["VALUES"],
},
}
},
#
# Since "signatures" property takes precedence over base case properties
# one should avoid specifying other properties.
#
"example_dead_properties": {
"signatures": {
"SOME_SIGNATURE": {
"options": [
"OPTION_KEYWORD_SIGNATURE___1",
"OPTION_KEYWORD_SIGNATURE___2",
],
"multi_value_keywords": ["THINGS"],
},
},
# dead property
"options": ["THIS_KEYWORD_IS_NOT_RECOGNIZED", "THAT_ONE_AS_WELL"],
},
}