workflow.core 1.4.0__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.
Files changed (58) hide show
  1. workflow/__init__.py +17 -0
  2. workflow/cli/__init__.py +0 -0
  3. workflow/cli/buckets.py +124 -0
  4. workflow/cli/configs.py +279 -0
  5. workflow/cli/main.py +48 -0
  6. workflow/cli/pipelines.py +146 -0
  7. workflow/cli/results.py +168 -0
  8. workflow/cli/run.py +283 -0
  9. workflow/cli/schedules.py +234 -0
  10. workflow/cli/workspace.py +149 -0
  11. workflow/daemons/__init__.py +0 -0
  12. workflow/daemons/audit.py +74 -0
  13. workflow/daemons/transfer.py +255 -0
  14. workflow/definitions/__init__.py +0 -0
  15. workflow/definitions/config.py +124 -0
  16. workflow/definitions/jsonschema.md +28 -0
  17. workflow/definitions/notify.py +91 -0
  18. workflow/definitions/work.py +520 -0
  19. workflow/definitions/workspace.py +252 -0
  20. workflow/examples/function.py +92 -0
  21. workflow/examples/sample.svg +12 -0
  22. workflow/examples/sample.workflow.yml +31 -0
  23. workflow/helpers/__init__.py +0 -0
  24. workflow/helpers/date.py +33 -0
  25. workflow/http/__init__.py +0 -0
  26. workflow/http/buckets.py +286 -0
  27. workflow/http/client.py +136 -0
  28. workflow/http/configs.py +165 -0
  29. workflow/http/context.py +170 -0
  30. workflow/http/pipelines.py +123 -0
  31. workflow/http/results.py +305 -0
  32. workflow/http/schedules.py +157 -0
  33. workflow/lifecycle/__init__.py +1 -0
  34. workflow/lifecycle/archive/__init__.py +102 -0
  35. workflow/lifecycle/archive/http.py +58 -0
  36. workflow/lifecycle/archive/posix.py +185 -0
  37. workflow/lifecycle/archive/s3.py +157 -0
  38. workflow/lifecycle/attempt.py +112 -0
  39. workflow/lifecycle/configure.py +152 -0
  40. workflow/lifecycle/execute.py +159 -0
  41. workflow/utils/__init__.py +0 -0
  42. workflow/utils/decorators.py +29 -0
  43. workflow/utils/logger.py +93 -0
  44. workflow/utils/prompt.py +26 -0
  45. workflow/utils/read.py +146 -0
  46. workflow/utils/renderers.py +113 -0
  47. workflow/utils/tmate.sh +17 -0
  48. workflow/utils/validate.py +198 -0
  49. workflow/utils/variables.py +24 -0
  50. workflow/utils/write.py +44 -0
  51. workflow/workspaces/__init__.py +0 -0
  52. workflow/workspaces/chimefrb.yml +48 -0
  53. workflow/workspaces/development.yml +48 -0
  54. workflow/workspaces/site-dev.yml +36 -0
  55. workflow_core-1.4.0.dist-info/METADATA +115 -0
  56. workflow_core-1.4.0.dist-info/RECORD +58 -0
  57. workflow_core-1.4.0.dist-info/WHEEL +4 -0
  58. workflow_core-1.4.0.dist-info/entry_points.txt +3 -0
@@ -0,0 +1,252 @@
1
+ """Definition of Workflow Workspace Configuration."""
2
+
3
+ from typing import Any, Dict, List, Literal, Optional, Union
4
+
5
+ from docker.types import DriverConfig, Mount
6
+ from pydantic import BaseModel, Field, model_validator
7
+
8
+
9
+ class DockerDeployerNetwork(BaseModel):
10
+ """Definition of Workflow Docker Deployer Network Configuration.
11
+
12
+ Args:
13
+ BaseModel (BaseModel): Pydantic BaseModel.
14
+
15
+ Attributes:
16
+ attachable (Optional[bool]):
17
+ Whether the network is attachable by external containers.
18
+ driver (Literal["host", "bridge", "overlay"]):
19
+ The driver to use for the network.
20
+ """
21
+
22
+ attachable: Optional[bool] = Field(
23
+ title="attachable",
24
+ description="Whether the overlay network is attachable by external containers.",
25
+ examples=[True, False],
26
+ default=None,
27
+ )
28
+ driver: Literal["host", "bridge", "overlay"] = Field(
29
+ ...,
30
+ title="driver",
31
+ description="The driver to use for the network.",
32
+ examples=["host", "bridge", "overlay"],
33
+ )
34
+
35
+ class Config:
36
+ """Pydantic configuration for the DockerDeployerNetwork model."""
37
+
38
+ allow_population_by_field_name = True
39
+ # Allow extra fields in the model.
40
+ extra = "allow"
41
+
42
+
43
+ class WorkspaceDockerDeployer(BaseModel):
44
+ """Definition of Workflow Workspace Docker Deployer Configuration.
45
+
46
+ Args:
47
+ BaseModel (BaseModel): Pydantic BaseModel.
48
+
49
+ Attributes:
50
+ client_url (str):
51
+ The URL pointing to the client's exposed Docker daemon.
52
+ volumes (Optional[Dict[str, Mount]]):
53
+ The volumes to be created (if non-existing)
54
+ and mounted to each Docker Service.
55
+ networks (Optional[Dict[str, DockerDeployerNetwork]]):
56
+ The networks to be created (if non-existing)
57
+ and mounted to each Docker Service.
58
+ labels (Optional[Dict[str, str]]):
59
+ The custom key-value labels to be mounted to each Docker Service.
60
+ constraints (Optional[List[str]]):
61
+ The Docker constraints to constrain the scheduling of each Docker Service.
62
+ log_driver (Optional[DriverConfig]):
63
+ The log driver to determine where logs are sent to for each Docker Service.
64
+ """
65
+
66
+ client_url: str = Field(
67
+ ...,
68
+ title="client_url",
69
+ description="The URL pointing to the client's exposed Docker daemon.",
70
+ examples=[
71
+ "http://localhost:2375",
72
+ "tcp://localhost:4444",
73
+ "unix://var/run/docker.sock",
74
+ ],
75
+ )
76
+ volumes: Optional[Dict[str, Mount]] = Field(
77
+ title="volumes",
78
+ description=(
79
+ "The volumes to be created (if non-existing) "
80
+ "and mounted to each Docker Service."
81
+ ),
82
+ examples=[
83
+ {
84
+ "volume-mount": {
85
+ "type": "volume",
86
+ "target": "/test/",
87
+ "driver_config": {
88
+ "driver": "local",
89
+ "driver_opts": {
90
+ "type": "nfs",
91
+ "o": ("nfsvers=4.0,noatime,nodiratime,soft,addr=nfs,rw"),
92
+ "device": ":/",
93
+ },
94
+ },
95
+ },
96
+ "bind-mount": {"type": "bind", "target": "/data/", "source": "/data/"},
97
+ "tmpfs-mount": {
98
+ "type": "tmpfs",
99
+ "target": "/dev/shm", # nosec
100
+ "tmpfs_size": 10000000,
101
+ },
102
+ }
103
+ ],
104
+ default=None,
105
+ )
106
+ networks: Optional[Dict[str, DockerDeployerNetwork]] = Field(
107
+ title="networks",
108
+ description=(
109
+ "The networks to be created (if non-existing) "
110
+ "and mounted to each Docker Service."
111
+ ),
112
+ examples=[
113
+ {
114
+ "swarm-network": {"attachable": True, "driver": "overlay"},
115
+ "local-network": {"driver": "bridge"},
116
+ }
117
+ ],
118
+ default=None,
119
+ )
120
+ labels: Optional[Dict[str, str]] = Field(
121
+ title="labels",
122
+ description=(
123
+ "The custom key-value labels to be attached to each Docker Service"
124
+ ),
125
+ examples=[{"label1": "value1", "label2": "value2"}],
126
+ default=None,
127
+ )
128
+ constraints: Optional[List[str]] = Field(
129
+ title="constraints",
130
+ description=(
131
+ "The Docker constraints to constrain "
132
+ "the scheduling of each Docker Service"
133
+ ),
134
+ examples=[["node.role == worker", "node.labels.type == compute"]],
135
+ default=None,
136
+ )
137
+ log_driver: Optional[DriverConfig] = Field(
138
+ title="log_driver",
139
+ description=(
140
+ "The log driver to determine where logs "
141
+ "are sent to for each Docker Service"
142
+ ),
143
+ examples=[
144
+ {
145
+ "name": "json-file",
146
+ "options": {
147
+ "max-size": "200k",
148
+ "max-file": "10",
149
+ "labels": "production_status",
150
+ },
151
+ },
152
+ {
153
+ "name": "loki",
154
+ "options": {
155
+ "loki-url": "http://loki:3100/loki/api/v1/push",
156
+ "loki-batch-size": "400",
157
+ "loki-batch-wait": "1s",
158
+ "loki-min-level": "info",
159
+ "loki-retries": "5",
160
+ },
161
+ },
162
+ ],
163
+ default=None,
164
+ )
165
+
166
+ class Config:
167
+ """Pydantic configuration for the WorkspaceDockerDeployer model."""
168
+
169
+ populate_by_name = True
170
+ # Allow extra fields in the model.
171
+ extra = "allow"
172
+
173
+
174
+ class Workspace(BaseModel):
175
+ """Definition of Workflow Workspace Configuration.
176
+
177
+ Args:
178
+ BaseModel (BaseModel): Pydantic BaseModel.
179
+
180
+ Attributes:
181
+ workspace (str): Name of the workflow workspace.
182
+ sites (List[str]): Valid sites for workflow.
183
+ http (Dict): Workflow HTTP URLs.
184
+ deployers (Dict[str, Dict[Literal["docker"], WorkspaceDockerDeployer]]):
185
+ Workflow Deployers.
186
+ """
187
+
188
+ workspace: str = Field(
189
+ ...,
190
+ title="Name of the workflow workspace.",
191
+ description="Name describing the purpose/usecase of the workspace.",
192
+ examples=["chimefrb", "champss"],
193
+ )
194
+ sites: List[str] = Field(
195
+ ...,
196
+ title="Valid sites for workflow.",
197
+ description="""
198
+ List of valid sites where work belonging to a workspace can be performed.
199
+ """,
200
+ examples=[["chime", "hco", "frb"]],
201
+ )
202
+ http: Dict[
203
+ Literal["baseurls"],
204
+ Dict[
205
+ Literal[
206
+ "buckets",
207
+ "results",
208
+ "schedules",
209
+ "pipelines",
210
+ "configs",
211
+ "loki",
212
+ "products",
213
+ ],
214
+ Union[str, List[str]],
215
+ ],
216
+ ] = Field(
217
+ ...,
218
+ title="Workflow HTTP URLs",
219
+ description="Baseurls define, the backend services for the workflow system.",
220
+ )
221
+ deployers: Dict[str, Dict[Literal["docker"], WorkspaceDockerDeployer]] = Field(
222
+ ...,
223
+ title="Workflow Deployers",
224
+ description="Deployer driver configs per site to deploy Workflow Deployments.",
225
+ )
226
+
227
+ @model_validator(mode="before")
228
+ def pre_validation(cls, data: Any) -> Any:
229
+ """Validate the Workspace model before creating the object.
230
+
231
+ Args:
232
+ data (Any): Workspace data to validate.
233
+
234
+ Raises:
235
+ ValueError: If a site in 'deployers' is not in 'sites'.
236
+
237
+ Returns:
238
+ Any: Validated Workspace data.
239
+ """
240
+ for site in data.get("deployers", {}):
241
+ if site not in data.get("sites", []):
242
+ raise ValueError(
243
+ f"Site '{site}' in deployers mapping is not in provided sites list."
244
+ )
245
+ return data
246
+
247
+ class Config:
248
+ """Pydantic configuration for the Workspace model."""
249
+
250
+ populate_by_name = True
251
+ # Allow extra fields in the model.
252
+ extra = "allow"
@@ -0,0 +1,92 @@
1
+ """Sample CHIME/FRB Workflow Compatible Function."""
2
+
3
+ from pathlib import Path
4
+ from typing import Dict, List, Tuple, Union
5
+
6
+ import click
7
+ from click_params import FirstOf
8
+
9
+
10
+ def math(
11
+ alpha: Union[float, int], beta: Union[float, int] = 1.0
12
+ ) -> Tuple[Dict[str, float], List[str], List[str]]:
13
+ """Sample CHIME/FRB Workflow Compatible Function.
14
+
15
+ Args:
16
+ a (Union[float, int]): A number
17
+ b (Union[float, int]): Another number
18
+
19
+ Raises:
20
+ error: If the arguments are not numbers
21
+
22
+ Returns:
23
+ Tuple[Dict[str, float], List[str], List[str]]:
24
+ The results, products, and plots
25
+ """
26
+ try:
27
+ assert isinstance(alpha, (float, int)), "alpha must be a number"
28
+ assert isinstance(beta, (float, int)), "beta must be a number"
29
+ results: Dict[str, float] = {
30
+ "sum": alpha + beta,
31
+ "difference": alpha - beta,
32
+ "product": alpha * beta,
33
+ "quotient": alpha / beta,
34
+ "power": alpha**beta,
35
+ "root": alpha ** (1 / beta),
36
+ "log": alpha ** (1 / beta),
37
+ }
38
+ # Make a csv file with results
39
+ with open("/tmp/sample.csv", "w") as file:
40
+ for key, value in results.items():
41
+ file.write(f"{key},{value}\n")
42
+ products: List[str] = ["/tmp/sample.csv"]
43
+ # Get the directory of whereever this file is
44
+ current: Path = Path(__file__).parent
45
+ # Copy sample svg file to /tmp
46
+ source: Path = current / "sample.svg"
47
+ destination: Path = Path("/tmp/sample.svg")
48
+ destination.write_text(source.read_text())
49
+ plots: List[str] = [destination.as_posix()]
50
+ return results, products, plots
51
+ except AssertionError as error:
52
+ raise error
53
+
54
+
55
+ @click.command("math", help="Sample CHIME/FRB Workflow Compatible Function.")
56
+ @click.option(
57
+ "--alpha",
58
+ "-a",
59
+ default=1.0,
60
+ type=FirstOf(click.FLOAT, click.INT),
61
+ required=True,
62
+ help="A number.",
63
+ )
64
+ @click.option(
65
+ "--beta",
66
+ "-b",
67
+ default=2.0,
68
+ type=FirstOf(click.FLOAT, click.INT),
69
+ required=True,
70
+ help="Another number.",
71
+ )
72
+ @click.option(
73
+ "-v",
74
+ "--verbose",
75
+ is_flag=True,
76
+ help="Print verbose output.",
77
+ default=False,
78
+ )
79
+ def cli(
80
+ alpha: Union[float, int], beta: Union[float, int], verbose: bool
81
+ ) -> Tuple[Dict[str, float], List[str], List[str]]:
82
+ """Click command for the math function."""
83
+ results, products, plots = math(alpha, beta)
84
+ if verbose:
85
+ click.echo(f"results: {results}")
86
+ click.echo(f"products: {products}")
87
+ click.echo(f"plots: {plots}")
88
+ return results, products, plots
89
+
90
+
91
+ if __name__ == "__main__":
92
+ cli()
@@ -0,0 +1,12 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 300 300">
2
+ <defs>
3
+ <clipPath id="clippath">
4
+ <path fill="#77CBB9" d="M270.96 98.42v103.17c0 11.3-6.03 21.74-15.81 27.38l-89.34 51.58a31.612 31.612 0 01-31.62 0l-89.35-51.58a31.631 31.631 0 01-15.81-27.38V98.42c0-11.3 6.03-21.74 15.81-27.38l89.35-51.58a31.612 31.612 0 0131.62 0l89.34 51.58a31.631 31.631 0 0115.81 27.38z"></path>
5
+ </clipPath>
6
+ </defs>
7
+ <path fill="#77CBB9" d="M270.96 98.42v103.17c0 11.3-6.03 21.74-15.81 27.38l-89.34 51.58a31.612 31.612 0 01-31.62 0l-89.35-51.58a31.631 31.631 0 01-15.81-27.38V98.42c0-11.3 6.03-21.74 15.81-27.38l89.35-51.58a31.612 31.612 0 0131.62 0l89.34 51.58a31.631 31.631 0 0115.81 27.38z"></path>
8
+ <g clip-path="url(#clippath)">
9
+ <path fill="#FFFFFF" d="M270.96 93.67v121.78c0 2.77-1.48 5.33-3.87 6.71l-105.47 60.89c-5.16 2.98-11.62-.75-11.62-6.71V154.62c0-2.77 1.48-5.32 3.87-6.71l105.47-60.96c5.16-2.98 11.62.74 11.62 6.71z" opacity="0.08"></path>
10
+ <path fill="#252634" d="M150 154.61v121.76c0 5.95-6.44 9.67-11.59 6.69L32.9 222.14a7.723 7.723 0 01-3.86-6.69V93.63c0-5.95 6.44-9.67 11.6-6.69l105.51 60.98a7.723 7.723 0 013.86 6.69z" opacity="0.15"></path>
11
+ </g>
12
+ </svg>
@@ -0,0 +1,31 @@
1
+ version: "2"
2
+ name: example-pipeline
3
+
4
+ defaults:
5
+ user: developer
6
+ site: local
7
+
8
+ deployments:
9
+ - name: sm
10
+ site: local
11
+ image: chimefrb/workflow:latest
12
+ sleep: 1
13
+ resources:
14
+ cores: 1
15
+ ram: 2G
16
+ replicas: 1
17
+
18
+ pipeline:
19
+ runs_on: sm
20
+ steps:
21
+ - name: math
22
+ stage: 1
23
+ matrix:
24
+ alpha: [1, 2, 3]
25
+ beta: [1, 2, 3]
26
+ work:
27
+ site: chime
28
+ function: workflow.examples.function.math
29
+ parameters:
30
+ a: ${{ matrix.alpha }}
31
+ b: ${{ matrix.beta }}
File without changes
@@ -0,0 +1,33 @@
1
+ """Helper functions for working with dates and times."""
2
+
3
+ from datetime import datetime
4
+ from typing import Dict
5
+
6
+
7
+ def get(format: str) -> Dict[str, str]:
8
+ """Get the current date and time in the specified format.
9
+
10
+ Args:
11
+ format (str): The format to return the date and time in.
12
+
13
+ Example:
14
+ from workflow.helpers import date
15
+ date.get("%Y-%m-%d %H:%M:%S")
16
+
17
+ Returns:
18
+ str: The current date and time.
19
+ """
20
+ date = datetime.now().strftime(format)
21
+ results: Dict[str, str] = {"output": date}
22
+ return results
23
+
24
+
25
+ def get_ctime() -> Dict[str, float]:
26
+ """Get the current time in seconds since the epoch.
27
+
28
+ Returns:
29
+ float: The current time in seconds since the epoch.
30
+ """
31
+ ctime: float = datetime.now().timestamp()
32
+ results: Dict[str, float] = {"output": ctime}
33
+ return results
File without changes