workflow.core 1.11.0__tar.gz → 1.11.2__tar.gz
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.
- {workflow_core-1.11.0 → workflow_core-1.11.2}/PKG-INFO +2 -1
- {workflow_core-1.11.0 → workflow_core-1.11.2}/pyproject.toml +1 -1
- {workflow_core-1.11.0 → workflow_core-1.11.2}/workflow/cli/configs.py +133 -2
- {workflow_core-1.11.0 → workflow_core-1.11.2}/workflow/cli/run.py +10 -8
- {workflow_core-1.11.0 → workflow_core-1.11.2}/workflow/daemons/transfer.py +5 -1
- {workflow_core-1.11.0 → workflow_core-1.11.2}/workflow/http/buckets.py +3 -3
- {workflow_core-1.11.0 → workflow_core-1.11.2}/workflow/http/configs.py +22 -1
- {workflow_core-1.11.0 → workflow_core-1.11.2}/workflow/lifecycle/configure.py +43 -11
- {workflow_core-1.11.0 → workflow_core-1.11.2}/workflow/lifecycle/execute.py +1 -4
- workflow_core-1.11.2/workflow/utils/format.py +89 -0
- {workflow_core-1.11.0 → workflow_core-1.11.2}/workflow/utils/renderers.py +21 -7
- {workflow_core-1.11.0 → workflow_core-1.11.2}/README.md +0 -0
- {workflow_core-1.11.0 → workflow_core-1.11.2}/workflow/__init__.py +0 -0
- {workflow_core-1.11.0 → workflow_core-1.11.2}/workflow/cli/__init__.py +0 -0
- {workflow_core-1.11.0 → workflow_core-1.11.2}/workflow/cli/buckets.py +0 -0
- {workflow_core-1.11.0 → workflow_core-1.11.2}/workflow/cli/main.py +0 -0
- {workflow_core-1.11.0 → workflow_core-1.11.2}/workflow/cli/pipelines.py +0 -0
- {workflow_core-1.11.0 → workflow_core-1.11.2}/workflow/cli/results.py +0 -0
- {workflow_core-1.11.0 → workflow_core-1.11.2}/workflow/cli/schedules.py +0 -0
- {workflow_core-1.11.0 → workflow_core-1.11.2}/workflow/cli/workspace.py +0 -0
- {workflow_core-1.11.0 → workflow_core-1.11.2}/workflow/daemons/__init__.py +0 -0
- {workflow_core-1.11.0 → workflow_core-1.11.2}/workflow/daemons/audit.py +0 -0
- {workflow_core-1.11.0 → workflow_core-1.11.2}/workflow/definitions/__init__.py +0 -0
- {workflow_core-1.11.0 → workflow_core-1.11.2}/workflow/definitions/config.py +0 -0
- {workflow_core-1.11.0 → workflow_core-1.11.2}/workflow/definitions/jsonschema.md +0 -0
- {workflow_core-1.11.0 → workflow_core-1.11.2}/workflow/definitions/notify.py +0 -0
- {workflow_core-1.11.0 → workflow_core-1.11.2}/workflow/definitions/work.py +0 -0
- {workflow_core-1.11.0 → workflow_core-1.11.2}/workflow/definitions/workspace.py +0 -0
- {workflow_core-1.11.0 → workflow_core-1.11.2}/workflow/examples/autocomplete.py +0 -0
- {workflow_core-1.11.0 → workflow_core-1.11.2}/workflow/examples/function.py +0 -0
- {workflow_core-1.11.0 → workflow_core-1.11.2}/workflow/examples/sample.svg +0 -0
- {workflow_core-1.11.0 → workflow_core-1.11.2}/workflow/examples/sample.workflow.yml +0 -0
- {workflow_core-1.11.0 → workflow_core-1.11.2}/workflow/exceptions.py +0 -0
- {workflow_core-1.11.0 → workflow_core-1.11.2}/workflow/helpers/__init__.py +0 -0
- {workflow_core-1.11.0 → workflow_core-1.11.2}/workflow/helpers/date.py +0 -0
- {workflow_core-1.11.0 → workflow_core-1.11.2}/workflow/http/__init__.py +0 -0
- {workflow_core-1.11.0 → workflow_core-1.11.2}/workflow/http/client.py +0 -0
- {workflow_core-1.11.0 → workflow_core-1.11.2}/workflow/http/context.py +0 -0
- {workflow_core-1.11.0 → workflow_core-1.11.2}/workflow/http/pipelines.py +0 -0
- {workflow_core-1.11.0 → workflow_core-1.11.2}/workflow/http/results.py +0 -0
- {workflow_core-1.11.0 → workflow_core-1.11.2}/workflow/http/schedules.py +0 -0
- {workflow_core-1.11.0 → workflow_core-1.11.2}/workflow/lifecycle/__init__.py +0 -0
- {workflow_core-1.11.0 → workflow_core-1.11.2}/workflow/lifecycle/archive/__init__.py +0 -0
- {workflow_core-1.11.0 → workflow_core-1.11.2}/workflow/lifecycle/archive/http.py +0 -0
- {workflow_core-1.11.0 → workflow_core-1.11.2}/workflow/lifecycle/archive/posix.py +0 -0
- {workflow_core-1.11.0 → workflow_core-1.11.2}/workflow/lifecycle/archive/s3.py +0 -0
- {workflow_core-1.11.0 → workflow_core-1.11.2}/workflow/lifecycle/attempt.py +0 -0
- {workflow_core-1.11.0 → workflow_core-1.11.2}/workflow/utils/__init__.py +0 -0
- {workflow_core-1.11.0 → workflow_core-1.11.2}/workflow/utils/decorators.py +0 -0
- {workflow_core-1.11.0 → workflow_core-1.11.2}/workflow/utils/logger.py +0 -0
- {workflow_core-1.11.0 → workflow_core-1.11.2}/workflow/utils/prompt.py +0 -0
- {workflow_core-1.11.0 → workflow_core-1.11.2}/workflow/utils/read.py +0 -0
- {workflow_core-1.11.0 → workflow_core-1.11.2}/workflow/utils/tmate.sh +0 -0
- {workflow_core-1.11.0 → workflow_core-1.11.2}/workflow/utils/validate.py +0 -0
- {workflow_core-1.11.0 → workflow_core-1.11.2}/workflow/utils/variables.py +0 -0
- {workflow_core-1.11.0 → workflow_core-1.11.2}/workflow/utils/write.py +0 -0
- {workflow_core-1.11.0 → workflow_core-1.11.2}/workflow/workspaces/__init__.py +0 -0
- {workflow_core-1.11.0 → workflow_core-1.11.2}/workflow/workspaces/chimefrb.yml +0 -0
- {workflow_core-1.11.0 → workflow_core-1.11.2}/workflow/workspaces/development.yml +0 -0
- {workflow_core-1.11.0 → workflow_core-1.11.2}/workflow/workspaces/site-dev.yml +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: workflow.core
|
|
3
|
-
Version: 1.11.
|
|
3
|
+
Version: 1.11.2
|
|
4
4
|
Summary: Workflow Core
|
|
5
5
|
Home-page: https://github.com/chimefrb/workflow
|
|
6
6
|
License: MIT
|
|
@@ -13,6 +13,7 @@ Classifier: Programming Language :: Python :: 3.9
|
|
|
13
13
|
Classifier: Programming Language :: Python :: 3.10
|
|
14
14
|
Classifier: Programming Language :: Python :: 3.11
|
|
15
15
|
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
17
|
Requires-Dist: click (>=8.1,<9.0)
|
|
17
18
|
Requires-Dist: click-params (>=0.5,<0.6)
|
|
18
19
|
Requires-Dist: docker (>=6.1)
|
|
@@ -2,19 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
import json
|
|
4
4
|
from typing import Any, Dict, List, Optional
|
|
5
|
+
from urllib.parse import urlencode
|
|
5
6
|
|
|
6
7
|
import click
|
|
7
8
|
import requests
|
|
8
9
|
import yaml
|
|
9
10
|
from rich import pretty
|
|
10
11
|
from rich.console import Console
|
|
12
|
+
from rich.progress import BarColumn, Progress, TextColumn
|
|
11
13
|
from rich.syntax import Syntax
|
|
12
|
-
from rich.table import Table
|
|
14
|
+
from rich.table import Column, Table
|
|
13
15
|
from rich.text import Text
|
|
14
16
|
from yaml.loader import SafeLoader
|
|
15
17
|
|
|
16
18
|
from workflow.http.context import HTTPContext
|
|
17
|
-
from workflow.utils import validate
|
|
19
|
+
from workflow.utils import format, validate
|
|
18
20
|
from workflow.utils.renderers import render_config
|
|
19
21
|
|
|
20
22
|
pretty.install()
|
|
@@ -306,3 +308,132 @@ def retry(name: str, id: str):
|
|
|
306
308
|
)
|
|
307
309
|
content = table
|
|
308
310
|
console.print(content)
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
@configs.command("reformat", help="Reformat V1 YAML files to V2.")
|
|
314
|
+
@click.argument(
|
|
315
|
+
"filename",
|
|
316
|
+
type=click.Path(exists=True, dir_okay=False, readable=True),
|
|
317
|
+
required=True,
|
|
318
|
+
)
|
|
319
|
+
def reformat(filename: click.Path):
|
|
320
|
+
"""Reformat YAML file to V2.
|
|
321
|
+
|
|
322
|
+
Parameters
|
|
323
|
+
----------
|
|
324
|
+
filename : click.Path
|
|
325
|
+
Filename.
|
|
326
|
+
"""
|
|
327
|
+
filepath: str = str(filename)
|
|
328
|
+
data: Dict[str, Any] = {}
|
|
329
|
+
with open(filepath) as reader:
|
|
330
|
+
data = yaml.load(reader, Loader=SafeLoader) # type: ignore
|
|
331
|
+
|
|
332
|
+
steps, matrix, version = format.needs_reformat(data)
|
|
333
|
+
if any([steps, matrix, version]):
|
|
334
|
+
console.print(Text("Version 1 YAML, reformatting...", style="red"))
|
|
335
|
+
data = format.reformat(
|
|
336
|
+
data=data,
|
|
337
|
+
r_steps=steps,
|
|
338
|
+
r_matrix=matrix,
|
|
339
|
+
r_version=version,
|
|
340
|
+
console=console,
|
|
341
|
+
)
|
|
342
|
+
else:
|
|
343
|
+
console.print(Text("Reformat not needed.", style="red"))
|
|
344
|
+
return
|
|
345
|
+
|
|
346
|
+
with open(filepath, "w") as file:
|
|
347
|
+
new_data: str = yaml.dump(data)
|
|
348
|
+
file.write(new_data)
|
|
349
|
+
console.print(f"Reformatted file {filename}", style="green")
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
@configs.command("migrate", help="Sends running Config to Pipelines V2.")
|
|
353
|
+
@click.argument("name", type=str, required=True)
|
|
354
|
+
@click.argument("base_url", type=str, required=True)
|
|
355
|
+
@click.option(
|
|
356
|
+
"status",
|
|
357
|
+
"-s",
|
|
358
|
+
"--status",
|
|
359
|
+
type=click.Choice(["success", "failure", "running", "queued", "cancelled"]),
|
|
360
|
+
default="running",
|
|
361
|
+
)
|
|
362
|
+
@click.option("delete", "-d", "--delete", is_flag=True, default=False)
|
|
363
|
+
def migrate(name: str, base_url: str, status: str, delete: bool):
|
|
364
|
+
"""Migrates V1 Configs to V2.
|
|
365
|
+
|
|
366
|
+
Parameters
|
|
367
|
+
----------
|
|
368
|
+
name : str
|
|
369
|
+
Configuration name.
|
|
370
|
+
base_url : str
|
|
371
|
+
Pipelines V1 backend URL.
|
|
372
|
+
status : str
|
|
373
|
+
Status filter.
|
|
374
|
+
delete : bool
|
|
375
|
+
WIP.
|
|
376
|
+
"""
|
|
377
|
+
http = HTTPContext(backends=["configs"])
|
|
378
|
+
params = {
|
|
379
|
+
"skip": 0,
|
|
380
|
+
"length": 100,
|
|
381
|
+
"projection": json.dumps({}),
|
|
382
|
+
"query": json.dumps({"status": {"$in": status.split(",")}}),
|
|
383
|
+
"name": name,
|
|
384
|
+
}
|
|
385
|
+
url = f"{base_url}?{urlencode(params)}"
|
|
386
|
+
response = requests.get(url)
|
|
387
|
+
pipelines = response.json()
|
|
388
|
+
text_column = TextColumn("{task.description}", table_column=Column(ratio=1))
|
|
389
|
+
bar_column = BarColumn(bar_width=None, table_column=Column(ratio=2))
|
|
390
|
+
progress = Progress(text_column, bar_column, expand=True)
|
|
391
|
+
|
|
392
|
+
if not pipelines:
|
|
393
|
+
console.print(f"No Config objects were found under the name {name}")
|
|
394
|
+
return
|
|
395
|
+
|
|
396
|
+
console.print(
|
|
397
|
+
f"Migrating {len(pipelines)} Pipeline objects from {name} collection to V2.",
|
|
398
|
+
style="bright_green",
|
|
399
|
+
)
|
|
400
|
+
with progress:
|
|
401
|
+
for obj in pipelines:
|
|
402
|
+
task = progress.add_task(f"[cyan]Migrating {obj['id']}", total=1)
|
|
403
|
+
# ? Reformat
|
|
404
|
+
reformatted_obj = format.reformat(
|
|
405
|
+
data=obj,
|
|
406
|
+
r_steps=False,
|
|
407
|
+
r_matrix=False,
|
|
408
|
+
r_version=True,
|
|
409
|
+
)
|
|
410
|
+
yaml_url = (
|
|
411
|
+
f"{base_url}/inspect?"
|
|
412
|
+
f"{urlencode({'name': name, 'id': reformatted_obj['id']})}"
|
|
413
|
+
)
|
|
414
|
+
yaml_response = requests.get(yaml_url)
|
|
415
|
+
old_yaml = yaml_response.json()["yaml"]
|
|
416
|
+
new_yaml = format.reformat(
|
|
417
|
+
data=yaml.safe_load(old_yaml),
|
|
418
|
+
r_steps=True,
|
|
419
|
+
r_matrix=True,
|
|
420
|
+
r_version=True,
|
|
421
|
+
)
|
|
422
|
+
progress.update(task, advance=0.3)
|
|
423
|
+
reformatted_obj["yaml"] = yaml.dump(new_yaml)
|
|
424
|
+
# ? Stop monitoring on V1
|
|
425
|
+
stopped = False
|
|
426
|
+
if obj["status"] == "running":
|
|
427
|
+
stop_params = urlencode(
|
|
428
|
+
{"name": obj["name"], "query": json.dumps({"id": obj["id"]})}
|
|
429
|
+
)
|
|
430
|
+
stop_url = f"{base_url}/cancel?" f"{stop_params}"
|
|
431
|
+
stop_response = requests.put(stop_url)
|
|
432
|
+
if stop_response.ok:
|
|
433
|
+
stopped = True
|
|
434
|
+
progress.update(task, advance=0.3)
|
|
435
|
+
# ? Migrate
|
|
436
|
+
migration_response = http.configs.migrate(reformatted_obj)
|
|
437
|
+
if migration_response.ok:
|
|
438
|
+
progress.update(task, advance=0.4 if stopped else 0.7)
|
|
439
|
+
console.print("Migration completed", style="bright_green")
|
|
@@ -208,17 +208,19 @@ def run(
|
|
|
208
208
|
)
|
|
209
209
|
else:
|
|
210
210
|
# Missing Logging config in Workspace
|
|
211
|
-
config.update(
|
|
212
|
-
|
|
213
|
-
"
|
|
214
|
-
"
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
211
|
+
config.update(
|
|
212
|
+
{
|
|
213
|
+
"logging": {
|
|
214
|
+
"loki": {
|
|
215
|
+
"tags": {
|
|
216
|
+
# Assumes that there is only one bucket
|
|
217
|
+
"pipeline": buckets[0],
|
|
218
|
+
"site": site,
|
|
219
|
+
}
|
|
218
220
|
}
|
|
219
221
|
}
|
|
220
222
|
}
|
|
221
|
-
|
|
223
|
+
)
|
|
222
224
|
loki_status: bool = configure.loki(logger=logger, config=config)
|
|
223
225
|
logger.info(f"Loki Logs: {'✅' if loki_status else '❌'}")
|
|
224
226
|
http: HTTPContext = HTTPContext(backends=["buckets"])
|
|
@@ -239,7 +239,11 @@ def perform(
|
|
|
239
239
|
|
|
240
240
|
if delete:
|
|
241
241
|
logger.info(f"deleting {len(delete)} works from buckets")
|
|
242
|
-
|
|
242
|
+
if len(delete) > 100:
|
|
243
|
+
for batch in range(0, len(delete), 100):
|
|
244
|
+
http.buckets.delete_ids(delete[batch : batch + 100])
|
|
245
|
+
else:
|
|
246
|
+
http.buckets.delete_ids(delete)
|
|
243
247
|
logger.info(f"transferred {transfered}, deleted {len(delete)} works")
|
|
244
248
|
return {
|
|
245
249
|
"transfered": transfered,
|
|
@@ -6,7 +6,7 @@ from urllib.parse import urlencode
|
|
|
6
6
|
from requests.models import Response
|
|
7
7
|
from tenacity import retry
|
|
8
8
|
from tenacity.stop import stop_after_delay
|
|
9
|
-
from tenacity.wait import wait_random
|
|
9
|
+
from tenacity.wait import wait_fixed, wait_random
|
|
10
10
|
|
|
11
11
|
from workflow.http.client import Client
|
|
12
12
|
from workflow.utils.logger import get_logger
|
|
@@ -123,7 +123,7 @@ class Buckets(Client):
|
|
|
123
123
|
response.raise_for_status()
|
|
124
124
|
return response.json()
|
|
125
125
|
|
|
126
|
-
@retry(wait=
|
|
126
|
+
@retry(wait=wait_fixed(30), stop=(stop_after_delay(30)))
|
|
127
127
|
def delete_ids(self, ids: List[str]) -> bool:
|
|
128
128
|
"""Delete works from the buckets backend with the given ids.
|
|
129
129
|
|
|
@@ -148,7 +148,7 @@ class Buckets(Client):
|
|
|
148
148
|
tags: Optional[List[str]] = None,
|
|
149
149
|
parent: Optional[str] = None,
|
|
150
150
|
force: bool = False,
|
|
151
|
-
limit: Optional[int] = 100
|
|
151
|
+
limit: Optional[int] = 100,
|
|
152
152
|
) -> bool:
|
|
153
153
|
"""Delete works belonging to a pipeline from the buckets backend.
|
|
154
154
|
|
|
@@ -44,6 +44,28 @@ class Configs(Client):
|
|
|
44
44
|
response.raise_for_status()
|
|
45
45
|
return response.json()
|
|
46
46
|
|
|
47
|
+
@retry(
|
|
48
|
+
reraise=True, wait=wait_random(min=0.3, max=1.8), stop=(stop_after_delay(15))
|
|
49
|
+
)
|
|
50
|
+
def migrate(self, data: Dict[str, Any]) -> Dict[str, Any]:
|
|
51
|
+
"""Migrates V1 objects to V2.
|
|
52
|
+
|
|
53
|
+
Parameters
|
|
54
|
+
----------
|
|
55
|
+
data : Dict[str, Any]
|
|
56
|
+
Object payload.
|
|
57
|
+
|
|
58
|
+
Returns
|
|
59
|
+
-------
|
|
60
|
+
Dict[str, Any]
|
|
61
|
+
Backend JSON response.
|
|
62
|
+
"""
|
|
63
|
+
with self.session as session:
|
|
64
|
+
url = f"{self.baseurl}/configs/migrate"
|
|
65
|
+
response: Response = session.post(url, json=data)
|
|
66
|
+
response.raise_for_status()
|
|
67
|
+
return response.json()
|
|
68
|
+
|
|
47
69
|
def count(self) -> Dict[str, Any]:
|
|
48
70
|
"""Count all documents in a collection.
|
|
49
71
|
|
|
@@ -164,7 +186,6 @@ class Configs(Client):
|
|
|
164
186
|
server_info = response.json()
|
|
165
187
|
return {"client": client_info, "server": server_info}
|
|
166
188
|
|
|
167
|
-
|
|
168
189
|
@retry(
|
|
169
190
|
reraise=True, wait=wait_random(min=0.3, max=1.8), stop=(stop_after_delay(15))
|
|
170
191
|
)
|
|
@@ -91,7 +91,7 @@ def loki(logger: Logger, config: Dict[str, Any]) -> bool:
|
|
|
91
91
|
return status
|
|
92
92
|
|
|
93
93
|
|
|
94
|
-
def arguments(
|
|
94
|
+
def arguments(func: Callable[..., Any], work: Work) -> List[str]:
|
|
95
95
|
"""Return a list of CLI arguments.
|
|
96
96
|
|
|
97
97
|
Args:
|
|
@@ -101,14 +101,44 @@ def arguments(arguments: Optional[Dict[str, Any]]) -> List[str]:
|
|
|
101
101
|
List[str]: List of CLI arguments
|
|
102
102
|
"""
|
|
103
103
|
args: List[str] = []
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
104
|
+
|
|
105
|
+
for parameter in func.params: # type: ignore
|
|
106
|
+
parameter_name_in_cli = parameter.opts[-1]
|
|
107
|
+
paraneter_name_in_function = parameter.name
|
|
108
|
+
parameter_value_in_work = work.parameters.get( # type: ignore
|
|
109
|
+
paraneter_name_in_function, None
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
if parameter_value_in_work:
|
|
113
|
+
if isinstance(parameter_value_in_work, list):
|
|
114
|
+
parameter_value_in_work = " ".join(parameter_value_in_work)
|
|
115
|
+
|
|
116
|
+
if isinstance(parameter, click.Argument):
|
|
117
|
+
# If argument, then the parameter is purely positional without a key
|
|
118
|
+
args.append(f"{parameter_value_in_work}")
|
|
119
|
+
elif isinstance(parameter, click.Option):
|
|
120
|
+
if hasattr(parameter, "is_flag") and parameter.is_flag:
|
|
121
|
+
# If is_flag=True,
|
|
122
|
+
# then the parameter is a flag and doesn't have a value
|
|
123
|
+
args.append(f"{parameter_name_in_cli}")
|
|
124
|
+
else:
|
|
125
|
+
if len(parameter_name_in_cli) == 2:
|
|
126
|
+
# Short options
|
|
127
|
+
# (often denoted by a single hyphen and a single letter like -r)
|
|
128
|
+
# are commonly written with a space
|
|
129
|
+
# between the option and its value
|
|
130
|
+
args.append(
|
|
131
|
+
f"{parameter_name_in_cli} {parameter_value_in_work}"
|
|
132
|
+
)
|
|
133
|
+
elif len(parameter_name_in_cli) > 2:
|
|
134
|
+
# Long options
|
|
135
|
+
# (often denoted by two hyphens and a word like --recursive)
|
|
136
|
+
# are commonly written with an equals sign
|
|
137
|
+
# between the option and its value
|
|
138
|
+
args.append(
|
|
139
|
+
f"{parameter_name_in_cli}={parameter_value_in_work}"
|
|
140
|
+
)
|
|
141
|
+
|
|
112
142
|
return args
|
|
113
143
|
|
|
114
144
|
|
|
@@ -142,7 +172,8 @@ def defaults(func: Callable[..., Any], work: Work) -> Work:
|
|
|
142
172
|
|
|
143
173
|
if hasattr(parameter, "is_flag") and parameter.is_flag:
|
|
144
174
|
if parameter_default_value is True:
|
|
145
|
-
# Flags aren't assigned values
|
|
175
|
+
# Flags aren't assigned values
|
|
176
|
+
# its CLI name is just included or not included
|
|
146
177
|
options[name_in_cli] = None
|
|
147
178
|
else:
|
|
148
179
|
options[name_in_cli] = parameter_default_value
|
|
@@ -151,7 +182,8 @@ def defaults(func: Callable[..., Any], work: Work) -> Work:
|
|
|
151
182
|
|
|
152
183
|
if hasattr(parameter, "is_flag") and parameter.is_flag:
|
|
153
184
|
if parameter_given_value is True:
|
|
154
|
-
# Flags aren't assigned values
|
|
185
|
+
# Flags aren't assigned values
|
|
186
|
+
# its CLI name is just included or not included
|
|
155
187
|
options[name_in_cli] = None
|
|
156
188
|
else:
|
|
157
189
|
options[name_in_cli] = parameter_given_value
|
|
@@ -36,13 +36,10 @@ def function(work: Work) -> Work:
|
|
|
36
36
|
assert isinstance(work.function, str), "missing function to execute"
|
|
37
37
|
func: Callable[..., Any] = validate.function(work.function)
|
|
38
38
|
arguments: List[str] = []
|
|
39
|
-
# Configure default values for the function
|
|
40
|
-
work = configure.defaults(func, work)
|
|
41
|
-
# Paramters to execute the function with
|
|
42
39
|
parameters: Dict[str, Any] = work.parameters or {}
|
|
43
40
|
|
|
44
41
|
if isinstance(func, click.Command):
|
|
45
|
-
arguments = configure.arguments(
|
|
42
|
+
arguments = configure.arguments(func, work)
|
|
46
43
|
logger.info(
|
|
47
44
|
f"executing: {func.name}.main(args={arguments}, standalone_mode=False)"
|
|
48
45
|
)
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"""Refomat functions."""
|
|
2
|
+
|
|
3
|
+
from typing import Any, Dict, List, Optional, Tuple
|
|
4
|
+
|
|
5
|
+
from rich.console import Console
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def needs_reformat(data: Dict[str, Any]) -> Tuple[bool, bool, bool]:
|
|
9
|
+
"""Determines if data needs reformat.
|
|
10
|
+
|
|
11
|
+
Parameters
|
|
12
|
+
----------
|
|
13
|
+
data : Dict[str, Any]
|
|
14
|
+
Payload.
|
|
15
|
+
|
|
16
|
+
Returns
|
|
17
|
+
-------
|
|
18
|
+
Tuple[bool, bool, bool]
|
|
19
|
+
Tuple of fields that need reformat.
|
|
20
|
+
"""
|
|
21
|
+
matrix = False
|
|
22
|
+
steps = False
|
|
23
|
+
version = False
|
|
24
|
+
if isinstance(data["pipeline"], dict):
|
|
25
|
+
if "steps" not in data["pipeline"].keys():
|
|
26
|
+
steps = True
|
|
27
|
+
if "matrix" in data.keys():
|
|
28
|
+
matrix = True
|
|
29
|
+
if data["version"] == "1" or isinstance(data["version"], int):
|
|
30
|
+
version = True
|
|
31
|
+
return steps, matrix, version
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def reformat(
|
|
35
|
+
data: Dict[str, Any],
|
|
36
|
+
r_steps: bool,
|
|
37
|
+
r_matrix: bool,
|
|
38
|
+
r_version: bool,
|
|
39
|
+
console: Optional[Console] = None,
|
|
40
|
+
) -> Dict[str, Any]:
|
|
41
|
+
"""Reformats data to work on Pipeline V2 backend.
|
|
42
|
+
|
|
43
|
+
Parameters
|
|
44
|
+
----------
|
|
45
|
+
data : Dict[str, Any]
|
|
46
|
+
Config payload.
|
|
47
|
+
r_steps: bool
|
|
48
|
+
If steps needs to be reformatted.
|
|
49
|
+
r_matrix : bool
|
|
50
|
+
If matrix needs to be reformatted.
|
|
51
|
+
r_version: bool,
|
|
52
|
+
If version needs to be reformatted.
|
|
53
|
+
console: Console,
|
|
54
|
+
Console object.
|
|
55
|
+
|
|
56
|
+
Returns
|
|
57
|
+
-------
|
|
58
|
+
Dict[str, Any]
|
|
59
|
+
Reformatted data.
|
|
60
|
+
"""
|
|
61
|
+
# ? Reformat steps
|
|
62
|
+
if r_steps:
|
|
63
|
+
if console:
|
|
64
|
+
console.print("Reformatting steps.", style="green")
|
|
65
|
+
steps: List[Dict[str, Any]] = []
|
|
66
|
+
for step_name in data["pipeline"].keys():
|
|
67
|
+
step = data["pipeline"][step_name]
|
|
68
|
+
step["name"] = step_name.replace("_", "-")
|
|
69
|
+
steps.append(step)
|
|
70
|
+
data.pop("pipeline")
|
|
71
|
+
data["pipeline"] = {"steps": steps}
|
|
72
|
+
|
|
73
|
+
# ? Check top level matrix
|
|
74
|
+
if r_matrix:
|
|
75
|
+
if console:
|
|
76
|
+
console.print("Reformatting top level matrix.", style="green")
|
|
77
|
+
matrix: Optional[Dict[str, Any]] = None
|
|
78
|
+
if data.get("matrix", None):
|
|
79
|
+
matrix = data["matrix"]
|
|
80
|
+
data.pop("matrix")
|
|
81
|
+
data["pipeline"]["matrix"] = matrix
|
|
82
|
+
|
|
83
|
+
# ? Fix version
|
|
84
|
+
if r_version:
|
|
85
|
+
if console:
|
|
86
|
+
console.print("Fixing version.", style="green")
|
|
87
|
+
data["version"] = "2"
|
|
88
|
+
|
|
89
|
+
return data
|
|
@@ -11,10 +11,22 @@ from workflow.http.context import HTTPContext
|
|
|
11
11
|
from workflow.utils.variables import status_colors, status_symbols
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
def render_timestamp(timestamp: float):
|
|
15
|
-
timestamp
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
def render_timestamp(timestamp: float) -> str:
|
|
15
|
+
"""Converts a timestamp into a readable string.
|
|
16
|
+
|
|
17
|
+
Parameters
|
|
18
|
+
----------
|
|
19
|
+
timestamp : float
|
|
20
|
+
Timestamp.
|
|
21
|
+
|
|
22
|
+
Returns
|
|
23
|
+
-------
|
|
24
|
+
str
|
|
25
|
+
Formatted timestamp.
|
|
26
|
+
"""
|
|
27
|
+
from_dt: dt.datetime = dt.datetime.fromtimestamp(timestamp)
|
|
28
|
+
formatted_dt: str = dt.datetime.strftime(from_dt, "%m-%d-%Y, %H:%M:%S")
|
|
29
|
+
return formatted_dt
|
|
18
30
|
|
|
19
31
|
|
|
20
32
|
def render_pipeline(payload: Dict[str, Any], history: bool = False) -> Text:
|
|
@@ -24,6 +36,8 @@ def render_pipeline(payload: Dict[str, Any], history: bool = False) -> Text:
|
|
|
24
36
|
----------
|
|
25
37
|
payload : Dict[str, Any]
|
|
26
38
|
Pipeline payload.
|
|
39
|
+
history : bool
|
|
40
|
+
If history field needs to be rendered.
|
|
27
41
|
|
|
28
42
|
Returns
|
|
29
43
|
-------
|
|
@@ -41,7 +55,7 @@ def render_pipeline(payload: Dict[str, Any], history: bool = False) -> Text:
|
|
|
41
55
|
continue
|
|
42
56
|
key_value_text = Text()
|
|
43
57
|
if k in time_fields and v:
|
|
44
|
-
v = render_timestamp(v)
|
|
58
|
+
v = render_timestamp(float(v))
|
|
45
59
|
if k == steps_field:
|
|
46
60
|
key_value_text = Text(f"{k}: \n", style="bright_blue")
|
|
47
61
|
for step in v:
|
|
@@ -50,7 +64,7 @@ def render_pipeline(payload: Dict[str, Any], history: bool = False) -> Text:
|
|
|
50
64
|
elif k == history_field:
|
|
51
65
|
key_value_text = Text(f"{k}: \n", style="bright_blue")
|
|
52
66
|
for timestamp in v.keys():
|
|
53
|
-
rendered = render_timestamp(
|
|
67
|
+
rendered = render_timestamp(float(timestamp))
|
|
54
68
|
key_value_text.append(f" {rendered}:\n", style="bright_green")
|
|
55
69
|
for execution in v[timestamp].keys():
|
|
56
70
|
key_value_text.append(f"{' ' * 4}{execution}:\n")
|
|
@@ -96,7 +110,7 @@ def render_config(http: HTTPContext, payload: Dict[str, Any]) -> Text:
|
|
|
96
110
|
continue
|
|
97
111
|
key_value_text = Text()
|
|
98
112
|
if k in time_fields and v:
|
|
99
|
-
v = render_timestamp(v)
|
|
113
|
+
v = render_timestamp(float(v))
|
|
100
114
|
if k == "pipelines":
|
|
101
115
|
key_value_text.append(f"{k}: \n", style="bright_blue")
|
|
102
116
|
for status in pipelines_statuses:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|