workflow.core 1.12.4__tar.gz → 1.12.6__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.12.4 → workflow_core-1.12.6}/PKG-INFO +1 -1
- {workflow_core-1.12.4 → workflow_core-1.12.6}/pyproject.toml +1 -1
- workflow_core-1.12.6/workflow/utils/write.py +60 -0
- workflow_core-1.12.4/workflow/utils/write.py +0 -44
- {workflow_core-1.12.4 → workflow_core-1.12.6}/README.md +0 -0
- {workflow_core-1.12.4 → workflow_core-1.12.6}/workflow/__init__.py +0 -0
- {workflow_core-1.12.4 → workflow_core-1.12.6}/workflow/cli/__init__.py +0 -0
- {workflow_core-1.12.4 → workflow_core-1.12.6}/workflow/cli/buckets.py +0 -0
- {workflow_core-1.12.4 → workflow_core-1.12.6}/workflow/cli/configs.py +0 -0
- {workflow_core-1.12.4 → workflow_core-1.12.6}/workflow/cli/main.py +0 -0
- {workflow_core-1.12.4 → workflow_core-1.12.6}/workflow/cli/pipelines.py +0 -0
- {workflow_core-1.12.4 → workflow_core-1.12.6}/workflow/cli/results.py +0 -0
- {workflow_core-1.12.4 → workflow_core-1.12.6}/workflow/cli/run.py +0 -0
- {workflow_core-1.12.4 → workflow_core-1.12.6}/workflow/cli/schedules.py +0 -0
- {workflow_core-1.12.4 → workflow_core-1.12.6}/workflow/cli/workspace.py +0 -0
- {workflow_core-1.12.4 → workflow_core-1.12.6}/workflow/daemons/__init__.py +0 -0
- {workflow_core-1.12.4 → workflow_core-1.12.6}/workflow/daemons/audit.py +0 -0
- {workflow_core-1.12.4 → workflow_core-1.12.6}/workflow/daemons/transfer.py +0 -0
- {workflow_core-1.12.4 → workflow_core-1.12.6}/workflow/definitions/__init__.py +0 -0
- {workflow_core-1.12.4 → workflow_core-1.12.6}/workflow/definitions/config.py +0 -0
- {workflow_core-1.12.4 → workflow_core-1.12.6}/workflow/definitions/jsonschema.md +0 -0
- {workflow_core-1.12.4 → workflow_core-1.12.6}/workflow/definitions/notify.py +0 -0
- {workflow_core-1.12.4 → workflow_core-1.12.6}/workflow/definitions/work.py +0 -0
- {workflow_core-1.12.4 → workflow_core-1.12.6}/workflow/definitions/workspace.py +0 -0
- {workflow_core-1.12.4 → workflow_core-1.12.6}/workflow/examples/autocomplete.py +0 -0
- {workflow_core-1.12.4 → workflow_core-1.12.6}/workflow/examples/function.py +0 -0
- {workflow_core-1.12.4 → workflow_core-1.12.6}/workflow/examples/sample.svg +0 -0
- {workflow_core-1.12.4 → workflow_core-1.12.6}/workflow/examples/sample.workflow.yml +0 -0
- {workflow_core-1.12.4 → workflow_core-1.12.6}/workflow/exceptions.py +0 -0
- {workflow_core-1.12.4 → workflow_core-1.12.6}/workflow/helpers/__init__.py +0 -0
- {workflow_core-1.12.4 → workflow_core-1.12.6}/workflow/helpers/date.py +0 -0
- {workflow_core-1.12.4 → workflow_core-1.12.6}/workflow/http/__init__.py +0 -0
- {workflow_core-1.12.4 → workflow_core-1.12.6}/workflow/http/buckets.py +0 -0
- {workflow_core-1.12.4 → workflow_core-1.12.6}/workflow/http/client.py +0 -0
- {workflow_core-1.12.4 → workflow_core-1.12.6}/workflow/http/configs.py +0 -0
- {workflow_core-1.12.4 → workflow_core-1.12.6}/workflow/http/context.py +0 -0
- {workflow_core-1.12.4 → workflow_core-1.12.6}/workflow/http/pipelines.py +0 -0
- {workflow_core-1.12.4 → workflow_core-1.12.6}/workflow/http/results.py +0 -0
- {workflow_core-1.12.4 → workflow_core-1.12.6}/workflow/http/schedules.py +0 -0
- {workflow_core-1.12.4 → workflow_core-1.12.6}/workflow/lifecycle/__init__.py +0 -0
- {workflow_core-1.12.4 → workflow_core-1.12.6}/workflow/lifecycle/archive/__init__.py +0 -0
- {workflow_core-1.12.4 → workflow_core-1.12.6}/workflow/lifecycle/archive/http.py +0 -0
- {workflow_core-1.12.4 → workflow_core-1.12.6}/workflow/lifecycle/archive/posix.py +0 -0
- {workflow_core-1.12.4 → workflow_core-1.12.6}/workflow/lifecycle/archive/s3.py +0 -0
- {workflow_core-1.12.4 → workflow_core-1.12.6}/workflow/lifecycle/attempt.py +0 -0
- {workflow_core-1.12.4 → workflow_core-1.12.6}/workflow/lifecycle/configure.py +0 -0
- {workflow_core-1.12.4 → workflow_core-1.12.6}/workflow/lifecycle/execute.py +0 -0
- {workflow_core-1.12.4 → workflow_core-1.12.6}/workflow/utils/__init__.py +0 -0
- {workflow_core-1.12.4 → workflow_core-1.12.6}/workflow/utils/decorators.py +0 -0
- {workflow_core-1.12.4 → workflow_core-1.12.6}/workflow/utils/format.py +0 -0
- {workflow_core-1.12.4 → workflow_core-1.12.6}/workflow/utils/logger.py +0 -0
- {workflow_core-1.12.4 → workflow_core-1.12.6}/workflow/utils/prompt.py +0 -0
- {workflow_core-1.12.4 → workflow_core-1.12.6}/workflow/utils/read.py +0 -0
- {workflow_core-1.12.4 → workflow_core-1.12.6}/workflow/utils/renderers.py +0 -0
- {workflow_core-1.12.4 → workflow_core-1.12.6}/workflow/utils/tmate.sh +0 -0
- {workflow_core-1.12.4 → workflow_core-1.12.6}/workflow/utils/validate.py +0 -0
- {workflow_core-1.12.4 → workflow_core-1.12.6}/workflow/utils/variables.py +0 -0
- {workflow_core-1.12.4 → workflow_core-1.12.6}/workflow/workspaces/__init__.py +0 -0
- {workflow_core-1.12.4 → workflow_core-1.12.6}/workflow/workspaces/chimefrb.yml +0 -0
- {workflow_core-1.12.4 → workflow_core-1.12.6}/workflow/workspaces/development.yml +0 -0
- {workflow_core-1.12.4 → workflow_core-1.12.6}/workflow/workspaces/site-dev.yml +0 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"""Writing utilities for workflow."""
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import shutil
|
|
5
|
+
import tempfile
|
|
6
|
+
from datetime import datetime
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from typing import Any, Dict, Union
|
|
9
|
+
|
|
10
|
+
import yaml
|
|
11
|
+
|
|
12
|
+
from workflow import DEFAULT_WORKSPACE_PATH
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def workspace(
|
|
16
|
+
source: Union[Path, Dict[str, Any]], destination: Path = DEFAULT_WORKSPACE_PATH
|
|
17
|
+
) -> None:
|
|
18
|
+
"""Write a workspace to a destination.
|
|
19
|
+
|
|
20
|
+
The destination is replaced atomically, so a reader never finds it missing or
|
|
21
|
+
partly written; when it changes, the previous one is kept as a dated `.bak`.
|
|
22
|
+
A source file is copied, not moved.
|
|
23
|
+
|
|
24
|
+
Args:
|
|
25
|
+
source (Union[Path, Dict[str, Any]]): Workspace to write.
|
|
26
|
+
destination (Path): Destination to write the workspace.
|
|
27
|
+
|
|
28
|
+
Raises:
|
|
29
|
+
ValueError: If source is not a dictionary or a file path.
|
|
30
|
+
|
|
31
|
+
Returns:
|
|
32
|
+
None: None
|
|
33
|
+
"""
|
|
34
|
+
if isinstance(source, Path):
|
|
35
|
+
assert source.exists(), f"workspace {source} does not exist."
|
|
36
|
+
content: str = source.read_text()
|
|
37
|
+
elif isinstance(source, dict): # type: ignore
|
|
38
|
+
content = yaml.dump(source)
|
|
39
|
+
else:
|
|
40
|
+
raise ValueError(f"source {source} is not a dictionary or a file path.")
|
|
41
|
+
destination.parent.mkdir(parents=True, exist_ok=True)
|
|
42
|
+
# Runners can share one home (e.g. CANFAR sessions on /arc), so another one may be
|
|
43
|
+
# reading the workspace right now: it is never moved away or left half-written.
|
|
44
|
+
if destination.exists():
|
|
45
|
+
if destination.read_text() == content:
|
|
46
|
+
return
|
|
47
|
+
# Back up the one being replaced, as a copy so it stays in place meanwhile.
|
|
48
|
+
date: str = datetime.now().strftime("%Y%m%d%H%M%S")
|
|
49
|
+
shutil.copy2(destination, destination.with_suffix(f".{date}.bak"))
|
|
50
|
+
# Write beside it, then rename into place: readers see the old or the new file.
|
|
51
|
+
descriptor, temporary = tempfile.mkstemp(
|
|
52
|
+
dir=destination.parent, prefix=f".{destination.name}.", suffix=".tmp"
|
|
53
|
+
)
|
|
54
|
+
try:
|
|
55
|
+
with os.fdopen(descriptor, "w") as filename:
|
|
56
|
+
filename.write(content)
|
|
57
|
+
os.replace(temporary, destination)
|
|
58
|
+
except BaseException:
|
|
59
|
+
Path(temporary).unlink(missing_ok=True)
|
|
60
|
+
raise
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"""Writing utilities for workflow."""
|
|
2
|
-
|
|
3
|
-
from datetime import datetime
|
|
4
|
-
from pathlib import Path
|
|
5
|
-
from typing import Any, Dict, Union
|
|
6
|
-
|
|
7
|
-
import yaml
|
|
8
|
-
|
|
9
|
-
from workflow import DEFAULT_WORKSPACE_PATH
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
def workspace(
|
|
13
|
-
source: Union[Path, Dict[str, Any]], destination: Path = DEFAULT_WORKSPACE_PATH
|
|
14
|
-
) -> None:
|
|
15
|
-
"""Write a workspace to a destination.
|
|
16
|
-
|
|
17
|
-
Args:
|
|
18
|
-
source (Union[Path, Dict[str, Any]]): Workspace to write.
|
|
19
|
-
destination (Path): Destination to write the workspace.
|
|
20
|
-
|
|
21
|
-
Raises:
|
|
22
|
-
ValueError: If source is not a dictionary or a file path.
|
|
23
|
-
|
|
24
|
-
Returns:
|
|
25
|
-
None: None
|
|
26
|
-
"""
|
|
27
|
-
if not destination.parent.exists():
|
|
28
|
-
destination.parent.mkdir(parents=True, exist_ok=True)
|
|
29
|
-
# If destination file exists, move it to a backup location file.
|
|
30
|
-
date: str = datetime.now().strftime("%Y%m%d%H%M%S")
|
|
31
|
-
if destination.exists():
|
|
32
|
-
destination.replace(destination.with_suffix(f".{date}.bak"))
|
|
33
|
-
# Make sure the source path exists.
|
|
34
|
-
if isinstance(source, Path):
|
|
35
|
-
assert source.exists(), f"workspace {source} does not exist."
|
|
36
|
-
source.replace(destination)
|
|
37
|
-
return
|
|
38
|
-
# Write dictionary to destination.
|
|
39
|
-
elif isinstance(source, dict): # type: ignore
|
|
40
|
-
with open(destination, "w") as filename:
|
|
41
|
-
yaml.dump(source, filename)
|
|
42
|
-
return
|
|
43
|
-
else:
|
|
44
|
-
raise ValueError(f"source {source} is not a dictionary or a file path.")
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|