metaflow 2.12.36__py2.py3-none-any.whl → 2.12.38__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- metaflow/__init__.py +3 -0
- metaflow/cli.py +84 -697
- metaflow/cli_args.py +17 -0
- metaflow/cli_components/__init__.py +0 -0
- metaflow/cli_components/dump_cmd.py +96 -0
- metaflow/cli_components/init_cmd.py +51 -0
- metaflow/cli_components/run_cmds.py +358 -0
- metaflow/cli_components/step_cmd.py +189 -0
- metaflow/cli_components/utils.py +140 -0
- metaflow/cmd/develop/stub_generator.py +9 -2
- metaflow/decorators.py +63 -2
- metaflow/extension_support/plugins.py +41 -27
- metaflow/flowspec.py +156 -16
- metaflow/includefile.py +50 -22
- metaflow/metaflow_config.py +1 -1
- metaflow/package.py +17 -3
- metaflow/parameters.py +80 -23
- metaflow/plugins/__init__.py +4 -0
- metaflow/plugins/airflow/airflow_cli.py +1 -0
- metaflow/plugins/argo/argo_workflows.py +41 -1
- metaflow/plugins/argo/argo_workflows_cli.py +1 -0
- metaflow/plugins/aws/batch/batch_decorator.py +2 -2
- metaflow/plugins/aws/step_functions/step_functions.py +32 -0
- metaflow/plugins/aws/step_functions/step_functions_cli.py +1 -0
- metaflow/plugins/datatools/s3/s3op.py +3 -3
- metaflow/plugins/kubernetes/kubernetes_cli.py +1 -1
- metaflow/plugins/kubernetes/kubernetes_decorator.py +2 -2
- metaflow/plugins/pypi/conda_decorator.py +22 -0
- metaflow/plugins/pypi/pypi_decorator.py +1 -0
- metaflow/plugins/timeout_decorator.py +2 -2
- metaflow/runner/click_api.py +73 -19
- metaflow/runtime.py +111 -73
- metaflow/sidecar/sidecar_worker.py +1 -1
- metaflow/user_configs/__init__.py +0 -0
- metaflow/user_configs/config_decorators.py +563 -0
- metaflow/user_configs/config_options.py +495 -0
- metaflow/user_configs/config_parameters.py +386 -0
- metaflow/util.py +17 -0
- metaflow/version.py +1 -1
- {metaflow-2.12.36.dist-info → metaflow-2.12.38.dist-info}/METADATA +3 -2
- {metaflow-2.12.36.dist-info → metaflow-2.12.38.dist-info}/RECORD +45 -35
- {metaflow-2.12.36.dist-info → metaflow-2.12.38.dist-info}/LICENSE +0 -0
- {metaflow-2.12.36.dist-info → metaflow-2.12.38.dist-info}/WHEEL +0 -0
- {metaflow-2.12.36.dist-info → metaflow-2.12.38.dist-info}/entry_points.txt +0 -0
- {metaflow-2.12.36.dist-info → metaflow-2.12.38.dist-info}/top_level.txt +0 -0
metaflow/cli.py
CHANGED
@@ -1,18 +1,18 @@
|
|
1
|
+
import functools
|
1
2
|
import inspect
|
2
|
-
import json
|
3
3
|
import sys
|
4
4
|
import traceback
|
5
5
|
from datetime import datetime
|
6
|
-
from functools import wraps
|
7
6
|
|
8
7
|
import metaflow.tracing as tracing
|
9
8
|
from metaflow._vendor import click
|
10
|
-
from metaflow.client.core import get_metadata
|
11
9
|
|
12
|
-
from . import decorators, lint, metaflow_version,
|
10
|
+
from . import decorators, lint, metaflow_version, parameters, plugins
|
13
11
|
from .cli_args import cli_args
|
14
|
-
from .
|
12
|
+
from .cli_components.utils import LazyGroup, LazyPluginCommandCollection
|
13
|
+
from .datastore import FlowDataStore
|
15
14
|
from .exception import CommandException, MetaflowException
|
15
|
+
from .flowspec import _FlowState
|
16
16
|
from .graph import FlowGraph
|
17
17
|
from .metaflow_config import (
|
18
18
|
DECOSPECS,
|
@@ -26,8 +26,6 @@ from .metaflow_config import (
|
|
26
26
|
from .metaflow_current import current
|
27
27
|
from metaflow.system import _system_monitor, _system_logger
|
28
28
|
from .metaflow_environment import MetaflowEnvironment
|
29
|
-
from .mflog import LOG_SOURCES, mflog
|
30
|
-
from .package import MetaflowPackage
|
31
29
|
from .plugins import (
|
32
30
|
DATASTORES,
|
33
31
|
ENVIRONMENTS,
|
@@ -37,16 +35,9 @@ from .plugins import (
|
|
37
35
|
)
|
38
36
|
from .pylint_wrapper import PyLint
|
39
37
|
from .R import metaflow_r_version, use_r
|
40
|
-
from .
|
41
|
-
from .
|
42
|
-
from .
|
43
|
-
from .unbounded_foreach import UBF_CONTROL, UBF_TASK
|
44
|
-
from .util import (
|
45
|
-
decompress_list,
|
46
|
-
get_latest_run_id,
|
47
|
-
resolve_identity,
|
48
|
-
write_latest_run_id,
|
49
|
-
)
|
38
|
+
from .util import resolve_identity
|
39
|
+
from .user_configs.config_options import LocalFileInput, config_options
|
40
|
+
from .user_configs.config_parameters import ConfigValue
|
50
41
|
|
51
42
|
ERASE_TO_EOL = "\033[K"
|
52
43
|
HIGHLIGHT = "red"
|
@@ -56,13 +47,6 @@ LOGGER_TIMESTAMP = "magenta"
|
|
56
47
|
LOGGER_COLOR = "green"
|
57
48
|
LOGGER_BAD_COLOR = "red"
|
58
49
|
|
59
|
-
try:
|
60
|
-
# Python 2
|
61
|
-
import cPickle as pickle
|
62
|
-
except ImportError:
|
63
|
-
# Python 3
|
64
|
-
import pickle
|
65
|
-
|
66
50
|
|
67
51
|
def echo_dev_null(*args, **kwargs):
|
68
52
|
pass
|
@@ -141,7 +125,16 @@ def config_merge_cb(ctx, param, value):
|
|
141
125
|
return tuple(list(value) + DECOSPECS.split())
|
142
126
|
|
143
127
|
|
144
|
-
@click.group(
|
128
|
+
@click.group(
|
129
|
+
cls=LazyGroup,
|
130
|
+
lazy_subcommands={
|
131
|
+
"init": "metaflow.cli_components.init_cmd.init",
|
132
|
+
"dump": "metaflow.cli_components.dump_cmd.dump",
|
133
|
+
"step": "metaflow.cli_components.step_cmd.step",
|
134
|
+
"run": "metaflow.cli_components.run_cmds.run",
|
135
|
+
"resume": "metaflow.cli_components.run_cmds.resume",
|
136
|
+
},
|
137
|
+
)
|
145
138
|
def cli(ctx):
|
146
139
|
pass
|
147
140
|
|
@@ -155,7 +148,13 @@ def cli(ctx):
|
|
155
148
|
)
|
156
149
|
@click.pass_obj
|
157
150
|
def check(obj, warnings=False):
|
158
|
-
|
151
|
+
if obj.is_quiet:
|
152
|
+
echo = echo_dev_null
|
153
|
+
else:
|
154
|
+
echo = echo_always
|
155
|
+
_check(
|
156
|
+
echo, obj.graph, obj.flow, obj.environment, pylint=obj.pylint, warnings=warnings
|
157
|
+
)
|
159
158
|
fname = inspect.getfile(obj.flow.__class__)
|
160
159
|
echo(
|
161
160
|
"\n*'{cmd} show'* shows a description of this flow.\n"
|
@@ -221,671 +220,32 @@ def output_dot(obj):
|
|
221
220
|
echo_always(obj.graph.output_dot(), err=False)
|
222
221
|
|
223
222
|
|
224
|
-
@cli.command(
|
225
|
-
help="Get data artifacts of a task or all tasks in a step. "
|
226
|
-
"The format for input-path is either <run_id>/<step_name> or "
|
227
|
-
"<run_id>/<step_name>/<task_id>."
|
228
|
-
)
|
229
|
-
@click.argument("input-path")
|
230
|
-
@click.option(
|
231
|
-
"--private/--no-private",
|
232
|
-
default=False,
|
233
|
-
show_default=True,
|
234
|
-
help="Show also private attributes.",
|
235
|
-
)
|
236
|
-
@click.option(
|
237
|
-
"--max-value-size",
|
238
|
-
default=1000,
|
239
|
-
show_default=True,
|
240
|
-
type=int,
|
241
|
-
help="Show only values that are smaller than this number. "
|
242
|
-
"Set to 0 to see only keys.",
|
243
|
-
)
|
244
|
-
@click.option(
|
245
|
-
"--include",
|
246
|
-
type=str,
|
247
|
-
default="",
|
248
|
-
help="Include only artifacts in the given comma-separated list.",
|
249
|
-
)
|
250
|
-
@click.option(
|
251
|
-
"--file", type=str, default=None, help="Serialize artifacts in the given file."
|
252
|
-
)
|
253
|
-
@click.pass_obj
|
254
|
-
def dump(obj, input_path, private=None, max_value_size=None, include=None, file=None):
|
255
|
-
output = {}
|
256
|
-
kwargs = {
|
257
|
-
"show_private": private,
|
258
|
-
"max_value_size": max_value_size,
|
259
|
-
"include": {t for t in include.split(",") if t},
|
260
|
-
}
|
261
|
-
|
262
|
-
# Pathspec can either be run_id/step_name or run_id/step_name/task_id.
|
263
|
-
parts = input_path.split("/")
|
264
|
-
if len(parts) == 2:
|
265
|
-
run_id, step_name = parts
|
266
|
-
task_id = None
|
267
|
-
elif len(parts) == 3:
|
268
|
-
run_id, step_name, task_id = parts
|
269
|
-
else:
|
270
|
-
raise CommandException(
|
271
|
-
"input_path should either be run_id/step_name or run_id/step_name/task_id"
|
272
|
-
)
|
273
|
-
|
274
|
-
datastore_set = TaskDataStoreSet(
|
275
|
-
obj.flow_datastore,
|
276
|
-
run_id,
|
277
|
-
steps=[step_name],
|
278
|
-
prefetch_data_artifacts=kwargs.get("include"),
|
279
|
-
)
|
280
|
-
if task_id:
|
281
|
-
ds_list = [datastore_set.get_with_pathspec(input_path)]
|
282
|
-
else:
|
283
|
-
ds_list = list(datastore_set) # get all tasks
|
284
|
-
|
285
|
-
for ds in ds_list:
|
286
|
-
echo(
|
287
|
-
"Dumping output of run_id=*{run_id}* "
|
288
|
-
"step=*{step}* task_id=*{task_id}*".format(
|
289
|
-
run_id=ds.run_id, step=ds.step_name, task_id=ds.task_id
|
290
|
-
),
|
291
|
-
fg="magenta",
|
292
|
-
)
|
293
|
-
|
294
|
-
if file is None:
|
295
|
-
echo_always(
|
296
|
-
ds.format(**kwargs), highlight="green", highlight_bold=False, err=False
|
297
|
-
)
|
298
|
-
else:
|
299
|
-
output[ds.pathspec] = ds.to_dict(**kwargs)
|
300
|
-
|
301
|
-
if file is not None:
|
302
|
-
with open(file, "wb") as f:
|
303
|
-
pickle.dump(output, f, protocol=pickle.HIGHEST_PROTOCOL)
|
304
|
-
echo("Artifacts written to *%s*" % file)
|
305
|
-
|
306
|
-
|
307
|
-
# TODO - move step and init under a separate 'internal' subcommand
|
308
|
-
|
309
|
-
|
310
|
-
@cli.command(help="Internal command to execute a single task.", hidden=True)
|
311
|
-
@click.argument("step-name")
|
312
|
-
@click.option(
|
313
|
-
"--run-id",
|
314
|
-
default=None,
|
315
|
-
required=True,
|
316
|
-
help="ID for one execution of all steps in the flow.",
|
317
|
-
)
|
318
|
-
@click.option(
|
319
|
-
"--task-id",
|
320
|
-
default=None,
|
321
|
-
required=True,
|
322
|
-
show_default=True,
|
323
|
-
help="ID for this instance of the step.",
|
324
|
-
)
|
325
|
-
@click.option(
|
326
|
-
"--input-paths",
|
327
|
-
help="A comma-separated list of pathspecs specifying inputs for this step.",
|
328
|
-
)
|
329
|
-
@click.option(
|
330
|
-
"--input-paths-filename",
|
331
|
-
type=click.Path(exists=True, readable=True, dir_okay=False, resolve_path=True),
|
332
|
-
help="A filename containing the argument typically passed to `input-paths`",
|
333
|
-
hidden=True,
|
334
|
-
)
|
335
|
-
@click.option(
|
336
|
-
"--split-index",
|
337
|
-
type=int,
|
338
|
-
default=None,
|
339
|
-
show_default=True,
|
340
|
-
help="Index of this foreach split.",
|
341
|
-
)
|
342
|
-
@click.option(
|
343
|
-
"--tag",
|
344
|
-
"opt_tag",
|
345
|
-
multiple=True,
|
346
|
-
default=None,
|
347
|
-
help="Annotate this run with the given tag. You can specify "
|
348
|
-
"this option multiple times to attach multiple tags in "
|
349
|
-
"the task.",
|
350
|
-
)
|
351
|
-
@click.option(
|
352
|
-
"--namespace",
|
353
|
-
"opt_namespace",
|
354
|
-
default=None,
|
355
|
-
help="Change namespace from the default (your username) to the specified tag.",
|
356
|
-
)
|
357
|
-
@click.option(
|
358
|
-
"--retry-count",
|
359
|
-
default=0,
|
360
|
-
help="How many times we have attempted to run this task.",
|
361
|
-
)
|
362
|
-
@click.option(
|
363
|
-
"--max-user-code-retries",
|
364
|
-
default=0,
|
365
|
-
help="How many times we should attempt running the user code.",
|
366
|
-
)
|
367
|
-
@click.option(
|
368
|
-
"--clone-only",
|
369
|
-
default=None,
|
370
|
-
help="Pathspec of the origin task for this task to clone. Do "
|
371
|
-
"not execute anything.",
|
372
|
-
)
|
373
|
-
@click.option(
|
374
|
-
"--clone-run-id",
|
375
|
-
default=None,
|
376
|
-
help="Run id of the origin flow, if this task is part of a flow being resumed.",
|
377
|
-
)
|
378
|
-
@click.option(
|
379
|
-
"--with",
|
380
|
-
"decospecs",
|
381
|
-
multiple=True,
|
382
|
-
help="Add a decorator to this task. You can specify this "
|
383
|
-
"option multiple times to attach multiple decorators "
|
384
|
-
"to this task.",
|
385
|
-
)
|
386
|
-
@click.option(
|
387
|
-
"--ubf-context",
|
388
|
-
default="none",
|
389
|
-
type=click.Choice(["none", UBF_CONTROL, UBF_TASK]),
|
390
|
-
help="Provides additional context if this task is of type unbounded foreach.",
|
391
|
-
)
|
392
|
-
@click.option(
|
393
|
-
"--num-parallel",
|
394
|
-
default=0,
|
395
|
-
type=int,
|
396
|
-
help="Number of parallel instances of a step. Ignored in local mode (see parallel decorator code).",
|
397
|
-
)
|
398
|
-
@click.pass_context
|
399
|
-
def step(
|
400
|
-
ctx,
|
401
|
-
step_name,
|
402
|
-
opt_tag=None,
|
403
|
-
run_id=None,
|
404
|
-
task_id=None,
|
405
|
-
input_paths=None,
|
406
|
-
input_paths_filename=None,
|
407
|
-
split_index=None,
|
408
|
-
opt_namespace=None,
|
409
|
-
retry_count=None,
|
410
|
-
max_user_code_retries=None,
|
411
|
-
clone_only=None,
|
412
|
-
clone_run_id=None,
|
413
|
-
decospecs=None,
|
414
|
-
ubf_context="none",
|
415
|
-
num_parallel=None,
|
416
|
-
):
|
417
|
-
if ubf_context == "none":
|
418
|
-
ubf_context = None
|
419
|
-
if opt_namespace is not None:
|
420
|
-
namespace(opt_namespace or None)
|
421
|
-
|
422
|
-
func = None
|
423
|
-
try:
|
424
|
-
func = getattr(ctx.obj.flow, step_name)
|
425
|
-
except:
|
426
|
-
raise CommandException("Step *%s* doesn't exist." % step_name)
|
427
|
-
if not func.is_step:
|
428
|
-
raise CommandException("Function *%s* is not a step." % step_name)
|
429
|
-
echo("Executing a step, *%s*" % step_name, fg="magenta", bold=False)
|
430
|
-
|
431
|
-
if decospecs:
|
432
|
-
decorators._attach_decorators_to_step(func, decospecs)
|
433
|
-
|
434
|
-
step_kwargs = ctx.params
|
435
|
-
# Remove argument `step_name` from `step_kwargs`.
|
436
|
-
step_kwargs.pop("step_name", None)
|
437
|
-
# Remove `opt_*` prefix from (some) option keys.
|
438
|
-
step_kwargs = dict(
|
439
|
-
[(k[4:], v) if k.startswith("opt_") else (k, v) for k, v in step_kwargs.items()]
|
440
|
-
)
|
441
|
-
cli_args._set_step_kwargs(step_kwargs)
|
442
|
-
|
443
|
-
ctx.obj.metadata.add_sticky_tags(tags=opt_tag)
|
444
|
-
if not input_paths and input_paths_filename:
|
445
|
-
with open(input_paths_filename, mode="r", encoding="utf-8") as f:
|
446
|
-
input_paths = f.read().strip(" \n\"'")
|
447
|
-
|
448
|
-
paths = decompress_list(input_paths) if input_paths else []
|
449
|
-
|
450
|
-
task = MetaflowTask(
|
451
|
-
ctx.obj.flow,
|
452
|
-
ctx.obj.flow_datastore,
|
453
|
-
ctx.obj.metadata,
|
454
|
-
ctx.obj.environment,
|
455
|
-
ctx.obj.echo,
|
456
|
-
ctx.obj.event_logger,
|
457
|
-
ctx.obj.monitor,
|
458
|
-
ubf_context,
|
459
|
-
)
|
460
|
-
if clone_only:
|
461
|
-
task.clone_only(
|
462
|
-
step_name,
|
463
|
-
run_id,
|
464
|
-
task_id,
|
465
|
-
clone_only,
|
466
|
-
retry_count,
|
467
|
-
)
|
468
|
-
else:
|
469
|
-
task.run_step(
|
470
|
-
step_name,
|
471
|
-
run_id,
|
472
|
-
task_id,
|
473
|
-
clone_run_id,
|
474
|
-
paths,
|
475
|
-
split_index,
|
476
|
-
retry_count,
|
477
|
-
max_user_code_retries,
|
478
|
-
)
|
479
|
-
|
480
|
-
echo("Success", fg="green", bold=True, indent=True)
|
481
|
-
|
482
|
-
|
483
|
-
@parameters.add_custom_parameters(deploy_mode=False)
|
484
|
-
@cli.command(help="Internal command to initialize a run.", hidden=True)
|
485
|
-
@click.option(
|
486
|
-
"--run-id",
|
487
|
-
default=None,
|
488
|
-
required=True,
|
489
|
-
help="ID for one execution of all steps in the flow.",
|
490
|
-
)
|
491
|
-
@click.option(
|
492
|
-
"--task-id", default=None, required=True, help="ID for this instance of the step."
|
493
|
-
)
|
494
|
-
@click.option(
|
495
|
-
"--tag",
|
496
|
-
"tags",
|
497
|
-
multiple=True,
|
498
|
-
default=None,
|
499
|
-
help="Tags for this instance of the step.",
|
500
|
-
)
|
501
|
-
@click.pass_obj
|
502
|
-
def init(obj, run_id=None, task_id=None, tags=None, **kwargs):
|
503
|
-
# init is a separate command instead of an option in 'step'
|
504
|
-
# since we need to capture user-specified parameters with
|
505
|
-
# @add_custom_parameters. Adding custom parameters to 'step'
|
506
|
-
# is not desirable due to the possibility of name clashes between
|
507
|
-
# user-specified parameters and our internal options. Note that
|
508
|
-
# user-specified parameters are often defined as environment
|
509
|
-
# variables.
|
510
|
-
|
511
|
-
obj.metadata.add_sticky_tags(tags=tags)
|
512
|
-
|
513
|
-
runtime = NativeRuntime(
|
514
|
-
obj.flow,
|
515
|
-
obj.graph,
|
516
|
-
obj.flow_datastore,
|
517
|
-
obj.metadata,
|
518
|
-
obj.environment,
|
519
|
-
obj.package,
|
520
|
-
obj.logger,
|
521
|
-
obj.entrypoint,
|
522
|
-
obj.event_logger,
|
523
|
-
obj.monitor,
|
524
|
-
run_id=run_id,
|
525
|
-
)
|
526
|
-
obj.flow._set_constants(obj.graph, kwargs)
|
527
|
-
runtime.persist_constants(task_id=task_id)
|
528
|
-
|
529
|
-
|
530
|
-
def common_run_options(func):
|
531
|
-
@click.option(
|
532
|
-
"--tag",
|
533
|
-
"tags",
|
534
|
-
multiple=True,
|
535
|
-
default=None,
|
536
|
-
help="Annotate this run with the given tag. You can specify "
|
537
|
-
"this option multiple times to attach multiple tags in "
|
538
|
-
"the run.",
|
539
|
-
)
|
540
|
-
@click.option(
|
541
|
-
"--max-workers",
|
542
|
-
default=16,
|
543
|
-
show_default=True,
|
544
|
-
help="Maximum number of parallel processes.",
|
545
|
-
)
|
546
|
-
@click.option(
|
547
|
-
"--max-num-splits",
|
548
|
-
default=100,
|
549
|
-
show_default=True,
|
550
|
-
help="Maximum number of splits allowed in a foreach. This "
|
551
|
-
"is a safety check preventing bugs from triggering "
|
552
|
-
"thousands of steps inadvertently.",
|
553
|
-
)
|
554
|
-
@click.option(
|
555
|
-
"--max-log-size",
|
556
|
-
default=10,
|
557
|
-
show_default=True,
|
558
|
-
help="Maximum size of stdout and stderr captured in "
|
559
|
-
"megabytes. If a step outputs more than this to "
|
560
|
-
"stdout/stderr, its output will be truncated.",
|
561
|
-
)
|
562
|
-
@click.option(
|
563
|
-
"--with",
|
564
|
-
"decospecs",
|
565
|
-
multiple=True,
|
566
|
-
help="Add a decorator to all steps. You can specify this "
|
567
|
-
"option multiple times to attach multiple decorators "
|
568
|
-
"in steps.",
|
569
|
-
)
|
570
|
-
@click.option(
|
571
|
-
"--run-id-file",
|
572
|
-
default=None,
|
573
|
-
show_default=True,
|
574
|
-
type=str,
|
575
|
-
help="Write the ID of this run to the file specified.",
|
576
|
-
)
|
577
|
-
@click.option(
|
578
|
-
"--runner-attribute-file",
|
579
|
-
default=None,
|
580
|
-
show_default=True,
|
581
|
-
type=str,
|
582
|
-
help="Write the metadata and pathspec of this run to the file specified. Used internally for Metaflow's Runner API.",
|
583
|
-
)
|
584
|
-
@wraps(func)
|
585
|
-
def wrapper(*args, **kwargs):
|
586
|
-
return func(*args, **kwargs)
|
587
|
-
|
588
|
-
return wrapper
|
589
|
-
|
590
|
-
|
591
|
-
@click.option(
|
592
|
-
"--origin-run-id",
|
593
|
-
default=None,
|
594
|
-
help="ID of the run that should be resumed. By default, the "
|
595
|
-
"last run executed locally.",
|
596
|
-
)
|
597
|
-
@click.option(
|
598
|
-
"--run-id",
|
599
|
-
default=None,
|
600
|
-
help="Run ID for the new run. By default, a new run-id will be generated",
|
601
|
-
hidden=True,
|
602
|
-
)
|
603
|
-
@click.option(
|
604
|
-
"--clone-only/--no-clone-only",
|
605
|
-
default=False,
|
606
|
-
show_default=True,
|
607
|
-
help="Only clone tasks without continuing execution",
|
608
|
-
hidden=True,
|
609
|
-
)
|
610
|
-
@click.option(
|
611
|
-
"--reentrant/--no-reentrant",
|
612
|
-
default=False,
|
613
|
-
show_default=True,
|
614
|
-
hidden=True,
|
615
|
-
help="If specified, allows this call to be called in parallel",
|
616
|
-
)
|
617
|
-
@click.option(
|
618
|
-
"--resume-identifier",
|
619
|
-
default=None,
|
620
|
-
show_default=True,
|
621
|
-
hidden=True,
|
622
|
-
help="If specified, it identifies the task that started this resume call. It is in the form of {step_name}-{task_id}",
|
623
|
-
)
|
624
|
-
@click.argument("step-to-rerun", required=False)
|
625
|
-
@cli.command(help="Resume execution of a previous run of this flow.")
|
626
|
-
@common_run_options
|
627
|
-
@click.pass_obj
|
628
|
-
def resume(
|
629
|
-
obj,
|
630
|
-
tags=None,
|
631
|
-
step_to_rerun=None,
|
632
|
-
origin_run_id=None,
|
633
|
-
run_id=None,
|
634
|
-
clone_only=False,
|
635
|
-
reentrant=False,
|
636
|
-
max_workers=None,
|
637
|
-
max_num_splits=None,
|
638
|
-
max_log_size=None,
|
639
|
-
decospecs=None,
|
640
|
-
run_id_file=None,
|
641
|
-
resume_identifier=None,
|
642
|
-
runner_attribute_file=None,
|
643
|
-
):
|
644
|
-
before_run(obj, tags, decospecs)
|
645
|
-
|
646
|
-
if origin_run_id is None:
|
647
|
-
origin_run_id = get_latest_run_id(obj.echo, obj.flow.name)
|
648
|
-
if origin_run_id is None:
|
649
|
-
raise CommandException(
|
650
|
-
"A previous run id was not found. Specify --origin-run-id."
|
651
|
-
)
|
652
|
-
|
653
|
-
if step_to_rerun is None:
|
654
|
-
steps_to_rerun = set()
|
655
|
-
else:
|
656
|
-
# validate step name
|
657
|
-
if step_to_rerun not in obj.graph.nodes:
|
658
|
-
raise CommandException(
|
659
|
-
"invalid step name {0} specified, must be step present in "
|
660
|
-
"current form of execution graph. Valid step names include: {1}".format(
|
661
|
-
step_to_rerun, ",".join(list(obj.graph.nodes.keys()))
|
662
|
-
)
|
663
|
-
)
|
664
|
-
steps_to_rerun = {step_to_rerun}
|
665
|
-
|
666
|
-
if run_id:
|
667
|
-
# Run-ids that are provided by the metadata service are always integers.
|
668
|
-
# External providers or run-ids (like external schedulers) always need to
|
669
|
-
# be non-integers to avoid any clashes. This condition ensures this.
|
670
|
-
try:
|
671
|
-
int(run_id)
|
672
|
-
except:
|
673
|
-
pass
|
674
|
-
else:
|
675
|
-
raise CommandException("run-id %s cannot be an integer" % run_id)
|
676
|
-
|
677
|
-
runtime = NativeRuntime(
|
678
|
-
obj.flow,
|
679
|
-
obj.graph,
|
680
|
-
obj.flow_datastore,
|
681
|
-
obj.metadata,
|
682
|
-
obj.environment,
|
683
|
-
obj.package,
|
684
|
-
obj.logger,
|
685
|
-
obj.entrypoint,
|
686
|
-
obj.event_logger,
|
687
|
-
obj.monitor,
|
688
|
-
run_id=run_id,
|
689
|
-
clone_run_id=origin_run_id,
|
690
|
-
clone_only=clone_only,
|
691
|
-
reentrant=reentrant,
|
692
|
-
steps_to_rerun=steps_to_rerun,
|
693
|
-
max_workers=max_workers,
|
694
|
-
max_num_splits=max_num_splits,
|
695
|
-
max_log_size=max_log_size * 1024 * 1024,
|
696
|
-
resume_identifier=resume_identifier,
|
697
|
-
)
|
698
|
-
write_file(run_id_file, runtime.run_id)
|
699
|
-
runtime.print_workflow_info()
|
700
|
-
|
701
|
-
runtime.persist_constants()
|
702
|
-
|
703
|
-
if runner_attribute_file:
|
704
|
-
with open(runner_attribute_file, "w", encoding="utf-8") as f:
|
705
|
-
json.dump(
|
706
|
-
{
|
707
|
-
"run_id": runtime.run_id,
|
708
|
-
"flow_name": obj.flow.name,
|
709
|
-
"metadata": obj.metadata.metadata_str(),
|
710
|
-
},
|
711
|
-
f,
|
712
|
-
)
|
713
|
-
|
714
|
-
# We may skip clone-only resume if this is not a resume leader,
|
715
|
-
# and clone is already complete.
|
716
|
-
if runtime.should_skip_clone_only_execution():
|
717
|
-
return
|
718
|
-
|
719
|
-
current._update_env(
|
720
|
-
{
|
721
|
-
"run_id": runtime.run_id,
|
722
|
-
}
|
723
|
-
)
|
724
|
-
_system_logger.log_event(
|
725
|
-
level="info",
|
726
|
-
module="metaflow.resume",
|
727
|
-
name="start",
|
728
|
-
payload={
|
729
|
-
"msg": "Resuming run",
|
730
|
-
},
|
731
|
-
)
|
732
|
-
|
733
|
-
with runtime.run_heartbeat():
|
734
|
-
if clone_only:
|
735
|
-
runtime.clone_original_run()
|
736
|
-
else:
|
737
|
-
runtime.clone_original_run(generate_task_obj=True, verbose=False)
|
738
|
-
runtime.execute()
|
739
|
-
|
740
|
-
|
741
|
-
@tracing.cli_entrypoint("cli/run")
|
742
|
-
@parameters.add_custom_parameters(deploy_mode=True)
|
743
|
-
@cli.command(help="Run the workflow locally.")
|
744
|
-
@common_run_options
|
745
|
-
@click.option(
|
746
|
-
"--namespace",
|
747
|
-
"user_namespace",
|
748
|
-
default=None,
|
749
|
-
help="Change namespace from the default (your username) to "
|
750
|
-
"the specified tag. Note that this option does not alter "
|
751
|
-
"tags assigned to the objects produced by this run, just "
|
752
|
-
"what existing objects are visible in the client API. You "
|
753
|
-
"can enable the global namespace with an empty string."
|
754
|
-
"--namespace=",
|
755
|
-
)
|
756
|
-
@click.pass_obj
|
757
|
-
def run(
|
758
|
-
obj,
|
759
|
-
tags=None,
|
760
|
-
max_workers=None,
|
761
|
-
max_num_splits=None,
|
762
|
-
max_log_size=None,
|
763
|
-
decospecs=None,
|
764
|
-
run_id_file=None,
|
765
|
-
runner_attribute_file=None,
|
766
|
-
user_namespace=None,
|
767
|
-
**kwargs
|
768
|
-
):
|
769
|
-
if user_namespace is not None:
|
770
|
-
namespace(user_namespace or None)
|
771
|
-
before_run(obj, tags, decospecs)
|
772
|
-
|
773
|
-
runtime = NativeRuntime(
|
774
|
-
obj.flow,
|
775
|
-
obj.graph,
|
776
|
-
obj.flow_datastore,
|
777
|
-
obj.metadata,
|
778
|
-
obj.environment,
|
779
|
-
obj.package,
|
780
|
-
obj.logger,
|
781
|
-
obj.entrypoint,
|
782
|
-
obj.event_logger,
|
783
|
-
obj.monitor,
|
784
|
-
max_workers=max_workers,
|
785
|
-
max_num_splits=max_num_splits,
|
786
|
-
max_log_size=max_log_size * 1024 * 1024,
|
787
|
-
)
|
788
|
-
write_latest_run_id(obj, runtime.run_id)
|
789
|
-
write_file(run_id_file, runtime.run_id)
|
790
|
-
|
791
|
-
obj.flow._set_constants(obj.graph, kwargs)
|
792
|
-
current._update_env(
|
793
|
-
{
|
794
|
-
"run_id": runtime.run_id,
|
795
|
-
}
|
796
|
-
)
|
797
|
-
_system_logger.log_event(
|
798
|
-
level="info",
|
799
|
-
module="metaflow.run",
|
800
|
-
name="start",
|
801
|
-
payload={
|
802
|
-
"msg": "Starting run",
|
803
|
-
},
|
804
|
-
)
|
805
|
-
with runtime.run_heartbeat():
|
806
|
-
runtime.print_workflow_info()
|
807
|
-
runtime.persist_constants()
|
808
|
-
|
809
|
-
if runner_attribute_file:
|
810
|
-
with open(runner_attribute_file, "w", encoding="utf-8") as f:
|
811
|
-
json.dump(
|
812
|
-
{
|
813
|
-
"run_id": runtime.run_id,
|
814
|
-
"flow_name": obj.flow.name,
|
815
|
-
"metadata": obj.metadata.metadata_str(),
|
816
|
-
},
|
817
|
-
f,
|
818
|
-
)
|
819
|
-
runtime.execute()
|
820
|
-
|
821
|
-
|
822
|
-
def write_file(file_path, content):
|
823
|
-
if file_path is not None:
|
824
|
-
with open(file_path, "w") as f:
|
825
|
-
f.write(str(content))
|
826
|
-
|
827
|
-
|
828
|
-
def before_run(obj, tags, decospecs):
|
829
|
-
validate_tags(tags)
|
830
|
-
|
831
|
-
# There's a --with option both at the top-level and for the run
|
832
|
-
# subcommand. Why?
|
833
|
-
#
|
834
|
-
# "run --with shoes" looks so much better than "--with shoes run".
|
835
|
-
# This is a very common use case of --with.
|
836
|
-
#
|
837
|
-
# A downside is that we need to have the following decorators handling
|
838
|
-
# in two places in this module and make sure _init_step_decorators
|
839
|
-
# doesn't get called twice.
|
840
|
-
|
841
|
-
# We want the order to be the following:
|
842
|
-
# - run level decospecs
|
843
|
-
# - top level decospecs
|
844
|
-
# - environment decospecs
|
845
|
-
all_decospecs = (
|
846
|
-
list(decospecs or [])
|
847
|
-
+ obj.tl_decospecs
|
848
|
-
+ list(obj.environment.decospecs() or [])
|
849
|
-
)
|
850
|
-
if all_decospecs:
|
851
|
-
decorators._attach_decorators(obj.flow, all_decospecs)
|
852
|
-
obj.graph = FlowGraph(obj.flow.__class__)
|
853
|
-
|
854
|
-
obj.check(obj.graph, obj.flow, obj.environment, pylint=obj.pylint)
|
855
|
-
# obj.environment.init_environment(obj.logger)
|
856
|
-
|
857
|
-
decorators._init_step_decorators(
|
858
|
-
obj.flow, obj.graph, obj.environment, obj.flow_datastore, obj.logger
|
859
|
-
)
|
860
|
-
|
861
|
-
obj.metadata.add_sticky_tags(tags=tags)
|
862
|
-
|
863
|
-
# Package working directory only once per run.
|
864
|
-
# We explicitly avoid doing this in `start` since it is invoked for every
|
865
|
-
# step in the run.
|
866
|
-
obj.package = MetaflowPackage(
|
867
|
-
obj.flow, obj.environment, obj.echo, obj.package_suffixes
|
868
|
-
)
|
869
|
-
|
870
|
-
|
871
223
|
@cli.command(help="Print the Metaflow version")
|
872
224
|
@click.pass_obj
|
873
225
|
def version(obj):
|
874
226
|
echo_always(obj.version)
|
875
227
|
|
876
228
|
|
877
|
-
|
229
|
+
# NOTE: add_decorator_options should be TL because it checks to make sure
|
230
|
+
# that no option conflict with the ones below
|
878
231
|
@decorators.add_decorator_options
|
232
|
+
@config_options
|
879
233
|
@click.command(
|
880
|
-
cls=
|
881
|
-
sources=[cli]
|
234
|
+
cls=LazyPluginCommandCollection,
|
235
|
+
sources=[cli],
|
236
|
+
lazy_sources=plugins.get_plugin_cli_path(),
|
882
237
|
invoke_without_command=True,
|
883
238
|
)
|
239
|
+
@tracing.cli_entrypoint("cli/start")
|
240
|
+
# Quiet is eager to make sure it is available when processing --config options since
|
241
|
+
# we need it to construct a context to pass to any DeployTimeField for the default
|
242
|
+
# value.
|
884
243
|
@click.option(
|
885
244
|
"--quiet/--not-quiet",
|
886
245
|
show_default=True,
|
887
246
|
default=False,
|
888
247
|
help="Suppress unnecessary messages",
|
248
|
+
is_eager=True,
|
889
249
|
)
|
890
250
|
@click.option(
|
891
251
|
"--metadata",
|
@@ -901,12 +261,14 @@ def version(obj):
|
|
901
261
|
type=click.Choice(["local"] + [m.TYPE for m in ENVIRONMENTS]),
|
902
262
|
help="Execution environment type",
|
903
263
|
)
|
264
|
+
# See comment for --quiet
|
904
265
|
@click.option(
|
905
266
|
"--datastore",
|
906
267
|
default=DEFAULT_DATASTORE,
|
907
268
|
show_default=True,
|
908
269
|
type=click.Choice([d.TYPE for d in DATASTORES]),
|
909
270
|
help="Data backend type",
|
271
|
+
is_eager=True,
|
910
272
|
)
|
911
273
|
@click.option("--datastore-root", help="Root path for datastore")
|
912
274
|
@click.option(
|
@@ -943,6 +305,15 @@ def version(obj):
|
|
943
305
|
type=click.Choice(MONITOR_SIDECARS),
|
944
306
|
help="Monitoring backend type",
|
945
307
|
)
|
308
|
+
@click.option(
|
309
|
+
"--local-config-file",
|
310
|
+
type=LocalFileInput(exists=True, readable=True, dir_okay=False, resolve_path=True),
|
311
|
+
required=False,
|
312
|
+
default=None,
|
313
|
+
help="A filename containing the dumped configuration values. Internal use only.",
|
314
|
+
hidden=True,
|
315
|
+
is_eager=True,
|
316
|
+
)
|
946
317
|
@click.pass_context
|
947
318
|
def start(
|
948
319
|
ctx,
|
@@ -956,9 +327,11 @@ def start(
|
|
956
327
|
pylint=None,
|
957
328
|
event_logger=None,
|
958
329
|
monitor=None,
|
330
|
+
local_config_file=None,
|
331
|
+
config_file_options=None,
|
332
|
+
config_value_options=None,
|
959
333
|
**deco_options
|
960
334
|
):
|
961
|
-
global echo
|
962
335
|
if quiet:
|
963
336
|
echo = echo_dev_null
|
964
337
|
else:
|
@@ -973,17 +346,27 @@ def start(
|
|
973
346
|
echo(" executing *%s*" % ctx.obj.flow.name, fg="magenta", nl=False)
|
974
347
|
echo(" for *%s*" % resolve_identity(), fg="magenta")
|
975
348
|
|
349
|
+
# At this point, we are able to resolve the user-configuration options so we can
|
350
|
+
# process all those decorators that the user added that will modify the flow based
|
351
|
+
# on those configurations. It is important to do this as early as possible since it
|
352
|
+
# actually modifies the flow itself
|
353
|
+
|
354
|
+
# When we process the options, the first one processed will return None and the
|
355
|
+
# second one processed will return the actual options. The order of processing
|
356
|
+
# depends on what (and in what order) the user specifies on the command line.
|
357
|
+
config_options = config_file_options or config_value_options
|
358
|
+
ctx.obj.flow = ctx.obj.flow._process_config_decorators(config_options)
|
359
|
+
|
976
360
|
cli_args._set_top_kwargs(ctx.params)
|
977
361
|
ctx.obj.echo = echo
|
978
362
|
ctx.obj.echo_always = echo_always
|
979
363
|
ctx.obj.is_quiet = quiet
|
980
|
-
ctx.obj.graph =
|
364
|
+
ctx.obj.graph = ctx.obj.flow._graph
|
981
365
|
ctx.obj.logger = logger
|
982
|
-
ctx.obj.check = _check
|
983
366
|
ctx.obj.pylint = pylint
|
367
|
+
ctx.obj.check = functools.partial(_check, echo)
|
984
368
|
ctx.obj.top_cli = cli
|
985
369
|
ctx.obj.package_suffixes = package_suffixes.split(",")
|
986
|
-
ctx.obj.reconstruct_cli = _reconstruct_cli
|
987
370
|
|
988
371
|
ctx.obj.environment = [
|
989
372
|
e for e in ENVIRONMENTS + [MetaflowEnvironment] if e.TYPE == environment
|
@@ -1029,6 +412,10 @@ def start(
|
|
1029
412
|
ctx.obj.monitor,
|
1030
413
|
)
|
1031
414
|
|
415
|
+
ctx.obj.config_options = config_options
|
416
|
+
|
417
|
+
decorators._init(ctx.obj.flow)
|
418
|
+
|
1032
419
|
# It is important to initialize flow decorators early as some of the
|
1033
420
|
# things they provide may be used by some of the objects initialized after.
|
1034
421
|
decorators._init_flow_decorators(
|
@@ -1051,10 +438,22 @@ def start(
|
|
1051
438
|
# initialize current and parameter context for deploy-time parameters
|
1052
439
|
current._set_env(flow=ctx.obj.flow, is_running=False)
|
1053
440
|
parameters.set_parameter_context(
|
1054
|
-
ctx.obj.flow.name,
|
441
|
+
ctx.obj.flow.name,
|
442
|
+
ctx.obj.echo,
|
443
|
+
ctx.obj.flow_datastore,
|
444
|
+
{
|
445
|
+
k: ConfigValue(v)
|
446
|
+
for k, v in ctx.obj.flow.__class__._flow_state.get(
|
447
|
+
_FlowState.CONFIGS, {}
|
448
|
+
).items()
|
449
|
+
},
|
1055
450
|
)
|
1056
451
|
|
1057
|
-
if
|
452
|
+
if (
|
453
|
+
hasattr(ctx, "saved_args")
|
454
|
+
and ctx.saved_args
|
455
|
+
and ctx.saved_args[0] not in ("run", "resume")
|
456
|
+
):
|
1058
457
|
# run/resume are special cases because they can add more decorators with --with,
|
1059
458
|
# so they have to take care of themselves.
|
1060
459
|
all_decospecs = ctx.obj.tl_decospecs + list(
|
@@ -1062,6 +461,7 @@ def start(
|
|
1062
461
|
)
|
1063
462
|
if all_decospecs:
|
1064
463
|
decorators._attach_decorators(ctx.obj.flow, all_decospecs)
|
464
|
+
decorators._init(ctx.obj.flow)
|
1065
465
|
# Regenerate graph if we attached more decorators
|
1066
466
|
ctx.obj.graph = FlowGraph(ctx.obj.flow.__class__)
|
1067
467
|
|
@@ -1075,25 +475,12 @@ def start(
|
|
1075
475
|
|
1076
476
|
# TODO (savin): Enable lazy instantiation of package
|
1077
477
|
ctx.obj.package = None
|
478
|
+
|
1078
479
|
if ctx.invoked_subcommand is None:
|
1079
480
|
ctx.invoke(check)
|
1080
481
|
|
1081
482
|
|
1082
|
-
def
|
1083
|
-
for k, v in params.items():
|
1084
|
-
if v:
|
1085
|
-
if k == "decospecs":
|
1086
|
-
k = "with"
|
1087
|
-
k = k.replace("_", "-")
|
1088
|
-
if not isinstance(v, tuple):
|
1089
|
-
v = [v]
|
1090
|
-
for value in v:
|
1091
|
-
yield "--%s" % k
|
1092
|
-
if not isinstance(value, bool):
|
1093
|
-
yield str(value)
|
1094
|
-
|
1095
|
-
|
1096
|
-
def _check(graph, flow, environment, pylint=True, warnings=False, **kwargs):
|
483
|
+
def _check(echo, graph, flow, environment, pylint=True, warnings=False, **kwargs):
|
1097
484
|
echo("Validating your flow...", fg="magenta", bold=False)
|
1098
485
|
linter = lint.linter
|
1099
486
|
# TODO set linter settings
|