-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
Copy path__init__.py
326 lines (260 loc) · 9.19 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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
from jina.helper import GATEWAY_NAME
from jina.parsers.helper import _SHOW_ALL_ARGS
from jina.parsers.logging import mixin_suppress_root_logging_parser
from jina.parsers.orchestrate.runtimes.container import mixin_container_runtime_parser
from jina.parsers.orchestrate.runtimes.grpc_channel import (
mixin_grpc_channel_options_parser,
)
from jina.parsers.orchestrate.runtimes.head import mixin_head_parser
def set_pod_parser(parser=None, default_name=None):
"""Set the parser for the Pod
:param parser: an optional existing parser to build upon
:param default_name: default pod name
:return: the parser
"""
if not parser:
from jina.parsers.base import set_base_parser
parser = set_base_parser()
from hubble.executor.parsers.pull import mixin_hub_pull_options_parser
from jina.parsers.orchestrate.base import mixin_scalable_deployment_parser
from jina.parsers.orchestrate.pod import mixin_pod_parser
from jina.parsers.orchestrate.runtimes.container import (
mixin_container_runtime_parser,
)
from jina.parsers.orchestrate.runtimes.remote import mixin_remote_runtime_parser
from jina.parsers.orchestrate.runtimes.worker import mixin_worker_runtime_parser
mixin_scalable_deployment_parser(parser, default_name=default_name)
mixin_worker_runtime_parser(parser)
mixin_container_runtime_parser(parser)
mixin_remote_runtime_parser(parser)
mixin_pod_parser(parser)
mixin_hub_pull_options_parser(parser)
mixin_head_parser(parser)
return parser
def set_deployment_parser(parser=None):
"""Set the parser for the Deployment
:param parser: an optional existing parser to build upon
:return: the parser
"""
if not parser:
from jina.parsers.base import set_base_parser
parser = set_base_parser()
set_pod_parser(parser, default_name='executor')
from jina.parsers.orchestrate.deployment import mixin_base_deployment_parser
mixin_base_deployment_parser(parser)
return parser
def set_gateway_parser(parser=None):
"""Set the parser for the gateway arguments
:param parser: an optional existing parser to build upon
:return: the parser
"""
if not parser:
from jina.parsers.base import set_base_parser
parser = set_base_parser()
from jina.parsers.orchestrate.base import mixin_base_deployment_parser
from jina.parsers.orchestrate.pod import mixin_pod_parser
from jina.parsers.orchestrate.runtimes.remote import (
mixin_gateway_parser,
mixin_graphql_parser,
mixin_http_gateway_parser,
mixin_prefetch_parser,
)
mixin_base_deployment_parser(parser)
mixin_container_runtime_parser(parser, pod_type='gateway')
mixin_prefetch_parser(parser)
mixin_http_gateway_parser(parser)
mixin_graphql_parser(parser)
mixin_gateway_parser(parser)
mixin_pod_parser(parser, pod_type='gateway')
from jina.enums import DeploymentRoleType
parser.set_defaults(
name=GATEWAY_NAME,
runtime_cls='GatewayRuntime',
deployment_role=DeploymentRoleType.GATEWAY,
)
return parser
def set_gateway_runtime_args_parser(parser=None):
"""Set the parser for the gateway runtime arguments
:param parser: an optional existing parser to build upon
:return: the parser
"""
if not parser:
from jina.parsers.base import set_base_parser
parser = set_base_parser()
from jina.parsers.orchestrate.pod import mixin_pod_runtime_args_parser
from jina.parsers.orchestrate.runtimes.remote import (
_add_host,
mixin_gateway_streamer_parser,
mixin_prefetch_parser,
)
mixin_gateway_streamer_parser(parser)
mixin_pod_runtime_args_parser(parser, pod_type='gateway')
mixin_prefetch_parser(parser)
_add_host(parser)
return parser
def set_client_cli_parser(parser=None):
"""Set the parser for the cli client
:param parser: an optional existing parser to build upon
:return: the parser
"""
if not parser:
from jina.parsers.base import set_base_parser
parser = set_base_parser()
from jina.parsers.client import (
mixin_client_features_parser,
mixin_client_protocol_parser,
)
from jina.parsers.orchestrate.runtimes.remote import (
mixin_client_gateway_parser,
mixin_prefetch_parser,
)
mixin_client_gateway_parser(parser)
mixin_client_features_parser(parser)
mixin_client_protocol_parser(parser)
mixin_grpc_channel_options_parser(parser)
mixin_prefetch_parser(parser)
mixin_suppress_root_logging_parser(parser)
return parser
def set_help_parser(parser=None):
"""Set the parser for the jina help lookup
:param parser: an optional existing parser to build upon
:return: the parser
"""
if not parser:
from jina.parsers.base import set_base_parser
parser = set_base_parser()
parser.add_argument(
'query',
type=str,
help='Look up usage & mention of argument name in Jina API. The name can be fuzzy',
)
return parser
def get_main_parser():
"""The main parser for Jina
:return: the parser
"""
from jina.parsers.base import set_base_parser
from jina.parsers.create import set_new_project_parser
from jina.parsers.export import set_export_parser
from jina.parsers.flow import set_flow_parser
from jina.parsers.helper import _SHOW_ALL_ARGS, _chf
from jina.parsers.ping import set_ping_parser
# create the top-level parser
parser = set_base_parser()
sp = parser.add_subparsers(
dest='cli',
required=True,
)
set_pod_parser(
sp.add_parser(
'executor',
help='Start an Executor',
description='Start an Executor. Jina uses Executors process Documents',
formatter_class=_chf,
)
)
set_flow_parser(
sp.add_parser(
'flow',
description='Start a Flow. Jina uses Flows to streamline and distribute Executors',
help='Start a Flow',
formatter_class=_chf,
)
)
set_ping_parser(
sp.add_parser(
'ping',
help='Ping an Executor/Flow',
description='Ping a remote Executor or Flow.',
formatter_class=_chf,
)
)
set_export_parser(
sp.add_parser(
'export',
help='Export Jina API/Flow',
description='Export Jina API and Flow to JSONSchema, Kubernetes YAML, or SVG flowchart',
formatter_class=_chf,
)
)
set_new_project_parser(
sp.add_parser(
'new',
help='Create a new Jina project',
description='Create a new Jina project with a predefined template',
formatter_class=_chf,
)
)
set_gateway_parser(
sp.add_parser(
'gateway',
description='Start a Gateway to receive client Requests via gRPC/RESTful interface',
**(dict(help='Start a Gateway')) if _SHOW_ALL_ARGS else {},
formatter_class=_chf,
)
)
from hubble.executor.parsers import get_main_parser as get_hub_parser
from hubble.parsers import get_main_parser as get_auth_parser
get_auth_parser(
sp.add_parser(
'auth',
description='Log in to Jina AI with your GitHub/Google/Email account',
formatter_class=_chf,
help='Login to Jina AI',
)
)
get_hub_parser(
sp.add_parser(
'hub',
help='Manage Executor on Executor Hub',
description='Push/pull Executor to/from Executor Hub',
formatter_class=_chf,
)
)
from jcloud.parsers import get_main_parser as get_jcloud_parser
get_jcloud_parser(
sp.add_parser(
'cloud',
description='Manage Flows on Jina Cloud',
formatter_class=_chf,
help='Manage Flows on Jina Cloud',
)
)
set_help_parser(
sp.add_parser(
'help',
help='Show help text of a CLI argument',
description='Show help text of a CLI argument',
formatter_class=_chf,
)
)
# Below are low-level / internal / experimental CLIs, hidden from users by default
set_pod_parser(
sp.add_parser(
'pod',
description='Start a Pod. '
'You should rarely use this directly unless you '
'are doing low-level orchestration',
formatter_class=_chf,
**(dict(help='Start a Pod')) if _SHOW_ALL_ARGS else {},
)
)
set_deployment_parser(
sp.add_parser(
'deployment',
description='Start a Deployment. '
'You should rarely use this directly unless you '
'are doing low-level orchestration',
formatter_class=_chf,
**(dict(help='Start a Deployment')) if _SHOW_ALL_ARGS else {},
)
)
set_client_cli_parser(
sp.add_parser(
'client',
description='Start a Python client that connects to a Jina Gateway',
formatter_class=_chf,
**(dict(help='Start a Client')) if _SHOW_ALL_ARGS else {},
)
)
return parser