stepup-data 4.3.0a0__tar.gz → 4.3.0a1__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.
- {stepup_data-4.3.0a0 → stepup_data-4.3.0a1}/PKG-INFO +3 -3
- {stepup_data-4.3.0a0 → stepup_data-4.3.0a1}/README.md +1 -1
- {stepup_data-4.3.0a0 → stepup_data-4.3.0a1}/pyproject.toml +11 -24
- stepup_data-4.3.0a1/stepup/data/api.py +403 -0
- stepup_data-4.3.0a1/stepup/data/arguments.py +70 -0
- stepup_data-4.3.0a1/stepup/data/check_inventory.py +83 -0
- {stepup_data-4.3.0a0 → stepup_data-4.3.0a1}/stepup/data/inventory.py +71 -43
- {stepup_data-4.3.0a0 → stepup_data-4.3.0a1}/stepup/data/make_inventory.py +130 -93
- {stepup_data-4.3.0a0 → stepup_data-4.3.0a1}/stepup/data/pytest.py +4 -3
- {stepup_data-4.3.0a0 → stepup_data-4.3.0a1}/stepup/data/sync_zenodo.py +86 -93
- stepup_data-4.3.0a1/stepup/data/zip_inventory.py +199 -0
- {stepup_data-4.3.0a0 → stepup_data-4.3.0a1}/stepup_data.egg-info/PKG-INFO +3 -3
- {stepup_data-4.3.0a0 → stepup_data-4.3.0a1}/stepup_data.egg-info/SOURCES.txt +1 -0
- {stepup_data-4.3.0a0 → stepup_data-4.3.0a1}/stepup_data.egg-info/requires.txt +1 -1
- {stepup_data-4.3.0a0 → stepup_data-4.3.0a1}/stepup_data.egg-info/scm_file_list.json +8 -2
- stepup_data-4.3.0a1/stepup_data.egg-info/scm_version.json +8 -0
- stepup_data-4.3.0a0/stepup/data/api.py +0 -244
- stepup_data-4.3.0a0/stepup/data/check_inventory.py +0 -54
- stepup_data-4.3.0a0/stepup/data/zip_inventory.py +0 -124
- stepup_data-4.3.0a0/stepup_data.egg-info/scm_version.json +0 -8
- {stepup_data-4.3.0a0 → stepup_data-4.3.0a1}/CITATION.cff +0 -0
- {stepup_data-4.3.0a0 → stepup_data-4.3.0a1}/LICENSE +0 -0
- {stepup_data-4.3.0a0 → stepup_data-4.3.0a1}/LICENSES/CC-BY-SA-4.0.txt +0 -0
- {stepup_data-4.3.0a0 → stepup_data-4.3.0a1}/LICENSES/LGPL-3.0-or-later.txt +0 -0
- {stepup_data-4.3.0a0 → stepup_data-4.3.0a1}/LICENSES/LicenseRef-StepUp-Logo-v1.txt +0 -0
- {stepup_data-4.3.0a0 → stepup_data-4.3.0a1}/MANIFEST.in +0 -0
- {stepup_data-4.3.0a0 → stepup_data-4.3.0a1}/REUSE.toml +0 -0
- {stepup_data-4.3.0a0 → stepup_data-4.3.0a1}/setup.cfg +0 -0
- {stepup_data-4.3.0a0 → stepup_data-4.3.0a1}/stepup/data/__init__.py +0 -0
- {stepup_data-4.3.0a0 → stepup_data-4.3.0a1}/stepup/data/env_vars.py +0 -0
- {stepup_data-4.3.0a0 → stepup_data-4.3.0a1}/stepup/data/zenodo_vocabularies.yaml +0 -0
- {stepup_data-4.3.0a0 → stepup_data-4.3.0a1}/stepup_data.egg-info/dependency_links.txt +0 -0
- {stepup_data-4.3.0a0 → stepup_data-4.3.0a1}/stepup_data.egg-info/entry_points.txt +0 -0
- {stepup_data-4.3.0a0 → stepup_data-4.3.0a1}/stepup_data.egg-info/top_level.txt +0 -0
- {stepup_data-4.3.0a0 → stepup_data-4.3.0a1}/tools/update_zenodo_vocabularies.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: stepup-data
|
|
3
|
-
Version: 4.3.
|
|
3
|
+
Version: 4.3.0a1
|
|
4
4
|
Summary: StepUp extension for data exchange and archiving
|
|
5
5
|
Author-email: Toon Verstraelen <toon.verstraelen@ugent.be>
|
|
6
6
|
License-Expression: LGPL-3.0-or-later
|
|
@@ -35,7 +35,7 @@ Requires-Dist: markdown-it-py>=3.0.0
|
|
|
35
35
|
Requires-Dist: pyyaml>=6.0
|
|
36
36
|
Requires-Dist: requests>=2.33.0
|
|
37
37
|
Requires-Dist: rich>=13.0.0
|
|
38
|
-
Requires-Dist: stepup<5.0.0a1,>=4.3.
|
|
38
|
+
Requires-Dist: stepup<5.0.0a1,>=4.3.0a2
|
|
39
39
|
Provides-Extra: tests
|
|
40
40
|
Requires-Dist: pytest>=8.2.0; extra == "tests"
|
|
41
41
|
Requires-Dist: pytest-asyncio>=0.24; extra == "tests"
|
|
@@ -80,7 +80,7 @@ of StepUp RepRep 4.2 under new names:
|
|
|
80
80
|
in an inventory, a JSON Lines file.
|
|
81
81
|
- `zip_inventory()` and `sd-zip-inventory` check the files against an inventory
|
|
82
82
|
and pack them into a reproducible ZIP file.
|
|
83
|
-
- `sd-check-inventory`
|
|
83
|
+
- `check_inventory()` and `sd-check-inventory` check files on disk against an inventory.
|
|
84
84
|
- `sync_zenodo()` and `sd-sync-zenodo` keep the files of an inventory in sync
|
|
85
85
|
with a draft dataset on Zenodo.
|
|
86
86
|
The token is taken from `STEPUP_DATA_ZENODO_TOKEN`.
|
|
@@ -28,7 +28,7 @@ of StepUp RepRep 4.2 under new names:
|
|
|
28
28
|
in an inventory, a JSON Lines file.
|
|
29
29
|
- `zip_inventory()` and `sd-zip-inventory` check the files against an inventory
|
|
30
30
|
and pack them into a reproducible ZIP file.
|
|
31
|
-
- `sd-check-inventory`
|
|
31
|
+
- `check_inventory()` and `sd-check-inventory` check files on disk against an inventory.
|
|
32
32
|
- `sync_zenodo()` and `sd-sync-zenodo` keep the files of an inventory in sync
|
|
33
33
|
with a draft dataset on Zenodo.
|
|
34
34
|
The token is taken from `STEPUP_DATA_ZENODO_TOKEN`.
|
|
@@ -58,7 +58,7 @@ dependencies = [
|
|
|
58
58
|
"pyyaml>=6.0",
|
|
59
59
|
"requests>=2.33.0",
|
|
60
60
|
"rich>=13.0.0",
|
|
61
|
-
"stepup>=4.3.
|
|
61
|
+
"stepup>=4.3.0a2,<5.0.0a1",
|
|
62
62
|
]
|
|
63
63
|
dynamic = ["version"]
|
|
64
64
|
|
|
@@ -99,7 +99,6 @@ data = "stepup.data.env_vars:env_vars"
|
|
|
99
99
|
|
|
100
100
|
[tool.pytest.ini_options]
|
|
101
101
|
addopts = "-n auto --dist worksteal --strict-markers -m 'not heavy'"
|
|
102
|
-
markers = ["heavy: requires CPU or memory resources not available in GitHub Actions"]
|
|
103
102
|
asyncio_default_fixture_loop_scope = "function"
|
|
104
103
|
filterwarnings = [
|
|
105
104
|
"error",
|
|
@@ -156,25 +155,13 @@ packages = ["stepup.data"]
|
|
|
156
155
|
version_scheme = "post-release"
|
|
157
156
|
local_scheme = "no-local-version"
|
|
158
157
|
|
|
159
|
-
[tool.
|
|
160
|
-
#
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
#
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
plugins.md013.heading_line_length = 100
|
|
170
|
-
plugins.md013.code_block_line_length = 100
|
|
171
|
-
# The changelog repeats headings such as "Fixed" under every release,
|
|
172
|
-
# which is fine as long as they do not repeat under the same release.
|
|
173
|
-
plugins.md024.siblings_only = true
|
|
174
|
-
# The default list does not include `script`, which the documentation uses to embed asciinema.
|
|
175
|
-
plugins.md033.allowed_elements = "!--,![CDATA[,!DOCTYPE,script"
|
|
176
|
-
# Rule md041 (first-line-heading) counts the SPDX header in an HTML comment
|
|
177
|
-
# as content preceding the first heading.
|
|
178
|
-
plugins.md041.enabled = false
|
|
179
|
-
# The documentation mixes fenced and indented code blocks on purpose.
|
|
180
|
-
plugins.md046.enabled = false
|
|
158
|
+
[tool.rumdl]
|
|
159
|
+
# Python-Markdown, and therefore Zensical, only nests a block in a list item
|
|
160
|
+
# when it is indented four spaces, which the MkDocs flavor checks.
|
|
161
|
+
flavor = "mkdocs"
|
|
162
|
+
line-length = 100
|
|
163
|
+
|
|
164
|
+
[tool.rumdl.MD025]
|
|
165
|
+
# Zensical sets the HTML title of a page from the `title` in its front matter,
|
|
166
|
+
# and only shows that title as a heading when the page has no level 1 heading of its own.
|
|
167
|
+
front-matter-title = ""
|
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2024 Toon Verstraelen <Toon.Verstraelen@UGent.be>
|
|
2
|
+
# SPDX-License-Identifier: LGPL-3.0-or-later
|
|
3
|
+
"""Application programming interface for StepUp Data.
|
|
4
|
+
|
|
5
|
+
## Detected Inputs
|
|
6
|
+
|
|
7
|
+
The steps of `zip_inventory()`, `check_inventory()` and `sync_zenodo()` read an inventory
|
|
8
|
+
and amend the files listed in it as inputs when they run.
|
|
9
|
+
Declaring such a file with `inp` is optional.
|
|
10
|
+
When another step builds the file, declaring it lets the step wait for that file,
|
|
11
|
+
instead of starting too early and being started again once the file is built.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from collections.abc import Iterable
|
|
15
|
+
|
|
16
|
+
from stepup.core.api import run, shq, subs_env_vars
|
|
17
|
+
from stepup.core.exceptions import StepUpError
|
|
18
|
+
from stepup.core.nglob import has_any_wildcards
|
|
19
|
+
from stepup.core.path import (
|
|
20
|
+
StrPath,
|
|
21
|
+
check_dest_not_input,
|
|
22
|
+
check_extension,
|
|
23
|
+
coerce_paths,
|
|
24
|
+
make_path_out,
|
|
25
|
+
)
|
|
26
|
+
from stepup.core.stepinfo import StepInfo
|
|
27
|
+
from stepup.core.utils import as_list
|
|
28
|
+
|
|
29
|
+
from .arguments import check_sync_zenodo_paths
|
|
30
|
+
from .inventory import DEFAULT_HASH_ALGO, HASH_ALGOS
|
|
31
|
+
|
|
32
|
+
__all__ = ("check_inventory", "make_inventory", "sync_zenodo", "zip_inventory")
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def make_inventory(
|
|
36
|
+
dest: StrPath,
|
|
37
|
+
*,
|
|
38
|
+
paths: StrPath | Iterable[StrPath] = (),
|
|
39
|
+
patterns: str | Iterable[str] = (),
|
|
40
|
+
paths_info_inp: StrPath | Iterable[StrPath] = (),
|
|
41
|
+
paths_info_out: StrPath | Iterable[StrPath] = (),
|
|
42
|
+
exclude: str | Iterable[str] = (),
|
|
43
|
+
hash_algo: str = DEFAULT_HASH_ALGO,
|
|
44
|
+
mode: bool = False,
|
|
45
|
+
optional: bool = False,
|
|
46
|
+
resources: dict[str, int] | str | None = None,
|
|
47
|
+
duration: float | None = None,
|
|
48
|
+
) -> StepInfo:
|
|
49
|
+
"""Create an inventory file in JSON Lines format.
|
|
50
|
+
|
|
51
|
+
The format and the selection of the files are explained in
|
|
52
|
+
[Inventory Files](../tutorials/inventory_files.md).
|
|
53
|
+
All paths and patterns are relative to the working directory of the step.
|
|
54
|
+
|
|
55
|
+
Parameters
|
|
56
|
+
----------
|
|
57
|
+
dest
|
|
58
|
+
Output destination: a file with the extension `.jsonl`.
|
|
59
|
+
paths
|
|
60
|
+
Files to include in the inventory, in the given order.
|
|
61
|
+
They are never interpreted as patterns, and may be outputs of other steps.
|
|
62
|
+
patterns
|
|
63
|
+
Patterns of files to include, which must contain wildcards and match static files.
|
|
64
|
+
The matches come after `paths`, sorted.
|
|
65
|
+
A pattern that matches no files is an error.
|
|
66
|
+
paths_info_inp, paths_info_out
|
|
67
|
+
Step info files, whose `inp` or `out` paths, respectively, are included,
|
|
68
|
+
e.g. written by `dump_step_info()` in StepUp Core.
|
|
69
|
+
The step info files are inputs of the step, and may be built by other steps.
|
|
70
|
+
The included files come after `paths`, sorted together with the matches of `patterns`.
|
|
71
|
+
exclude
|
|
72
|
+
Patterns or literal paths of files to leave out,
|
|
73
|
+
matched against the names of the files selected by the other arguments.
|
|
74
|
+
hash_algo
|
|
75
|
+
The name of the `hashlib` algorithm for the digests of the files.
|
|
76
|
+
The default, `md5`, is the one that Zenodo reports.
|
|
77
|
+
Use `sha256` when deliberate tampering with the files must be detected.
|
|
78
|
+
With `"none"`, no digests are recorded and the contents of the files are not read,
|
|
79
|
+
which saves time for large datasets,
|
|
80
|
+
but then changes that keep the size of a file are not detected,
|
|
81
|
+
and the inventory cannot be used by `sync_zenodo()`.
|
|
82
|
+
mode
|
|
83
|
+
When `True`, the permission bits of the files are recorded and checked.
|
|
84
|
+
Files have no permission bits on Windows,
|
|
85
|
+
where the recorded modes depend on the read-only attribute and the file names.
|
|
86
|
+
optional
|
|
87
|
+
When `True`, the step is only executed when needed by other steps.
|
|
88
|
+
resources
|
|
89
|
+
Named resources required to run this step, e.g. `{"gpu": 1}`.
|
|
90
|
+
See `stepup.core.api.step()` for details.
|
|
91
|
+
duration
|
|
92
|
+
An initial estimate of the step's wall time in seconds.
|
|
93
|
+
See `stepup.core.api.step()` for details.
|
|
94
|
+
|
|
95
|
+
Returns
|
|
96
|
+
-------
|
|
97
|
+
step_info
|
|
98
|
+
Holds relevant information of the step, useful for defining follow-up steps.
|
|
99
|
+
|
|
100
|
+
Raises
|
|
101
|
+
------
|
|
102
|
+
PathError
|
|
103
|
+
When `dest` does not have the extension `.jsonl`,
|
|
104
|
+
when `dest` is one of `paths`,
|
|
105
|
+
or when a file in `paths_info_inp` or `paths_info_out` does not have the extension `.json`.
|
|
106
|
+
StepUpError
|
|
107
|
+
When `hash_algo` is neither `"none"` nor the name of a supported hash algorithm,
|
|
108
|
+
when a pattern has no wildcards,
|
|
109
|
+
or when `paths`, `patterns`, `paths_info_inp` and `paths_info_out` are all empty.
|
|
110
|
+
|
|
111
|
+
Notes
|
|
112
|
+
-----
|
|
113
|
+
Environment variables in the paths and patterns of all arguments are substituted immediately,
|
|
114
|
+
and the variables referenced are added to the calling step's `env_deps` list with `amend()`.
|
|
115
|
+
These substitutions are based on the state of `os.environ` in the calling script,
|
|
116
|
+
at the time this function is called, not when the step is executed.
|
|
117
|
+
"""
|
|
118
|
+
with subs_env_vars() as subs_env:
|
|
119
|
+
su_dest = subs_env(dest)
|
|
120
|
+
su_paths = [subs_env(path) for path in coerce_paths(paths)]
|
|
121
|
+
su_patterns = [subs_env(pattern) for pattern in as_list(patterns)]
|
|
122
|
+
su_paths_info_inp = [subs_env(path) for path in coerce_paths(paths_info_inp)]
|
|
123
|
+
su_paths_info_out = [subs_env(path) for path in coerce_paths(paths_info_out)]
|
|
124
|
+
su_exclude = [subs_env(entry) for entry in as_list(exclude)]
|
|
125
|
+
check_extension(su_dest, ".jsonl", "dest")
|
|
126
|
+
check_dest_not_input(su_paths, su_dest)
|
|
127
|
+
for path_info in su_paths_info_inp:
|
|
128
|
+
check_extension(path_info, ".json", "paths_info_inp")
|
|
129
|
+
for path_info in su_paths_info_out:
|
|
130
|
+
check_extension(path_info, ".json", "paths_info_out")
|
|
131
|
+
if not (hash_algo == "none" or hash_algo in HASH_ALGOS):
|
|
132
|
+
raise StepUpError(
|
|
133
|
+
"`hash_algo` must be 'none' for no digests "
|
|
134
|
+
f"or one of {', '.join(map(repr, HASH_ALGOS))}, got {hash_algo!r}."
|
|
135
|
+
)
|
|
136
|
+
if not (su_paths or su_patterns or su_paths_info_inp or su_paths_info_out):
|
|
137
|
+
raise StepUpError(
|
|
138
|
+
"At least one of `paths`, `patterns`, `paths_info_inp` or `paths_info_out` is needed."
|
|
139
|
+
)
|
|
140
|
+
for pattern in su_patterns:
|
|
141
|
+
if not has_any_wildcards(pattern):
|
|
142
|
+
raise StepUpError(
|
|
143
|
+
f"The pattern {str(pattern)!r} has no wildcards. List a literal path in `paths`."
|
|
144
|
+
)
|
|
145
|
+
parts = ["sd-make-inventory", shq(su_dest)]
|
|
146
|
+
if len(su_paths) > 0:
|
|
147
|
+
parts.append(f"--paths {shq(su_paths)}")
|
|
148
|
+
parts.extend(f"--pattern={shq(pattern)}" for pattern in su_patterns)
|
|
149
|
+
if len(su_paths_info_inp) > 0:
|
|
150
|
+
parts.append(f"--info-inp {shq(su_paths_info_inp)}")
|
|
151
|
+
if len(su_paths_info_out) > 0:
|
|
152
|
+
parts.append(f"--info-out {shq(su_paths_info_out)}")
|
|
153
|
+
parts.extend(f"--exclude={shq(entry)}" for entry in su_exclude)
|
|
154
|
+
if hash_algo != DEFAULT_HASH_ALGO:
|
|
155
|
+
parts.append(f"--hash-algo={hash_algo}")
|
|
156
|
+
if mode:
|
|
157
|
+
parts.append("--mode")
|
|
158
|
+
# The step info files are declared,
|
|
159
|
+
# so that the step waits for them when another step builds them.
|
|
160
|
+
paths_inp = [*su_paths, *su_paths_info_inp, *su_paths_info_out]
|
|
161
|
+
return run(
|
|
162
|
+
" ".join(parts),
|
|
163
|
+
inp=paths_inp,
|
|
164
|
+
out=su_dest,
|
|
165
|
+
optional=optional,
|
|
166
|
+
resources=resources,
|
|
167
|
+
duration=duration,
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def zip_inventory(
|
|
172
|
+
path_inventory: StrPath,
|
|
173
|
+
dest: StrPath | None = None,
|
|
174
|
+
*,
|
|
175
|
+
inp: StrPath | Iterable[StrPath] = (),
|
|
176
|
+
optional: bool = False,
|
|
177
|
+
resources: dict[str, int] | str | None = None,
|
|
178
|
+
duration: float | None = None,
|
|
179
|
+
) -> StepInfo:
|
|
180
|
+
"""Create a reproducible ZIP file with all files listed in an inventory, after checking them.
|
|
181
|
+
|
|
182
|
+
Parameters
|
|
183
|
+
----------
|
|
184
|
+
path_inventory
|
|
185
|
+
An inventory file with the extension `.jsonl`,
|
|
186
|
+
created with `make_inventory()` or with the command-line script `sd-make-inventory`.
|
|
187
|
+
The files are stored in the ZIP file under the paths of their records,
|
|
188
|
+
which must therefore be inside the directory of the inventory.
|
|
189
|
+
They are also amended as inputs of the step,
|
|
190
|
+
so the ZIP file is rebuilt when they change, even when the inventory does not.
|
|
191
|
+
The inventory itself is not added to the ZIP file.
|
|
192
|
+
Keep the inventory next to the ZIP file
|
|
193
|
+
to check the unpacked files with `check_inventory()` or `sd-check-inventory`.
|
|
194
|
+
dest
|
|
195
|
+
Output destination: `None`, a directory with a trailing slash, or a file.
|
|
196
|
+
When `None`, the output is written next to `path_inventory`, with the extension `.zip`.
|
|
197
|
+
When `dest` is a directory, the output has the name of `path_inventory`,
|
|
198
|
+
with the extension `.zip`.
|
|
199
|
+
A file must have the extension `.zip`.
|
|
200
|
+
inp
|
|
201
|
+
Additional inputs of the step, e.g. files in the inventory that other steps build.
|
|
202
|
+
The files listed in the inventory are detected automatically when the step runs,
|
|
203
|
+
see [Detected Inputs][stepup.data.api--detected-inputs].
|
|
204
|
+
optional
|
|
205
|
+
When `True`, the step is only executed when needed by other steps.
|
|
206
|
+
resources
|
|
207
|
+
Named resources required to run this step, e.g. `{"gpu": 1}`.
|
|
208
|
+
See `stepup.core.api.step()` for details.
|
|
209
|
+
duration
|
|
210
|
+
An initial estimate of the step's wall time in seconds.
|
|
211
|
+
See `stepup.core.api.step()` for details.
|
|
212
|
+
|
|
213
|
+
Returns
|
|
214
|
+
-------
|
|
215
|
+
step_info
|
|
216
|
+
Holds relevant information of the step, useful for defining follow-up steps.
|
|
217
|
+
|
|
218
|
+
Raises
|
|
219
|
+
------
|
|
220
|
+
PathError
|
|
221
|
+
When `path_inventory` does not have the extension `.jsonl`,
|
|
222
|
+
or when `dest` is a file without the extension `.zip`.
|
|
223
|
+
|
|
224
|
+
Notes
|
|
225
|
+
-----
|
|
226
|
+
Environment variables in all path arguments are substituted immediately,
|
|
227
|
+
and the variables referenced are added to the calling step's `env_deps` list with `amend()`.
|
|
228
|
+
These substitutions are based on the state of `os.environ` in the calling script,
|
|
229
|
+
at the time this function is called, not when the step is executed.
|
|
230
|
+
"""
|
|
231
|
+
with subs_env_vars() as subs_env:
|
|
232
|
+
su_path_inventory = subs_env(path_inventory)
|
|
233
|
+
su_dest = subs_env(dest)
|
|
234
|
+
su_inp = [subs_env(path) for path in coerce_paths(inp)]
|
|
235
|
+
check_extension(su_path_inventory, ".jsonl", "path_inventory")
|
|
236
|
+
path_out = make_path_out(su_path_inventory, su_dest, ".zip")
|
|
237
|
+
parts = ["sd-zip-inventory", shq(su_path_inventory), shq(path_out)]
|
|
238
|
+
return run(
|
|
239
|
+
" ".join(parts),
|
|
240
|
+
inp=[su_path_inventory, *su_inp],
|
|
241
|
+
out=path_out,
|
|
242
|
+
optional=optional,
|
|
243
|
+
resources=resources,
|
|
244
|
+
duration=duration,
|
|
245
|
+
)
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
def check_inventory(
|
|
249
|
+
path_inventory: StrPath,
|
|
250
|
+
*,
|
|
251
|
+
inp: StrPath | Iterable[StrPath] = (),
|
|
252
|
+
resources: dict[str, int] | str | None = None,
|
|
253
|
+
duration: float | None = None,
|
|
254
|
+
) -> StepInfo:
|
|
255
|
+
"""Check that the files listed in an inventory match their records.
|
|
256
|
+
|
|
257
|
+
The size of every regular file is compared,
|
|
258
|
+
and so are its digest and its permission bits when the inventory has them,
|
|
259
|
+
and the target of every symbolic link.
|
|
260
|
+
The step fails when a file differs from its record.
|
|
261
|
+
|
|
262
|
+
Parameters
|
|
263
|
+
----------
|
|
264
|
+
path_inventory
|
|
265
|
+
An inventory file with the extension `.jsonl`,
|
|
266
|
+
created with `make_inventory()` or with the command-line script `sd-make-inventory`.
|
|
267
|
+
The paths of its records are relative to its parent directory.
|
|
268
|
+
The listed files are amended as inputs of the step,
|
|
269
|
+
so the check runs again when one of them changes, even when the inventory does not.
|
|
270
|
+
inp
|
|
271
|
+
Additional inputs of the step, e.g. files in the inventory that other steps build.
|
|
272
|
+
A typical example is a step that unpacks a ZIP file made by `zip_inventory()`.
|
|
273
|
+
The files listed in the inventory are detected automatically when the step runs,
|
|
274
|
+
see [Detected Inputs][stepup.data.api--detected-inputs].
|
|
275
|
+
resources
|
|
276
|
+
Named resources required to run this step, e.g. `{"gpu": 1}`.
|
|
277
|
+
See `stepup.core.api.step()` for details.
|
|
278
|
+
duration
|
|
279
|
+
An initial estimate of the step's wall time in seconds.
|
|
280
|
+
See `stepup.core.api.step()` for details.
|
|
281
|
+
|
|
282
|
+
Returns
|
|
283
|
+
-------
|
|
284
|
+
step_info
|
|
285
|
+
Holds relevant information of the step, useful for defining follow-up steps.
|
|
286
|
+
|
|
287
|
+
Raises
|
|
288
|
+
------
|
|
289
|
+
PathError
|
|
290
|
+
When `path_inventory` does not have the extension `.jsonl`.
|
|
291
|
+
|
|
292
|
+
Notes
|
|
293
|
+
-----
|
|
294
|
+
Environment variables in all path arguments are substituted immediately,
|
|
295
|
+
and the variables referenced are added to the calling step's `env_deps` list with `amend()`.
|
|
296
|
+
These substitutions are based on the state of `os.environ` in the calling script,
|
|
297
|
+
at the time this function is called, not when the step is executed.
|
|
298
|
+
"""
|
|
299
|
+
with subs_env_vars() as subs_env:
|
|
300
|
+
su_path_inventory = subs_env(path_inventory)
|
|
301
|
+
su_inp = [subs_env(path) for path in coerce_paths(inp)]
|
|
302
|
+
check_extension(su_path_inventory, ".jsonl", "path_inventory")
|
|
303
|
+
parts = ["sd-check-inventory", shq(su_path_inventory)]
|
|
304
|
+
return run(
|
|
305
|
+
" ".join(parts),
|
|
306
|
+
inp=[su_path_inventory, *su_inp],
|
|
307
|
+
resources=resources,
|
|
308
|
+
duration=duration,
|
|
309
|
+
)
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
def sync_zenodo(
|
|
313
|
+
path_config: StrPath,
|
|
314
|
+
path_description: StrPath,
|
|
315
|
+
path_inventory: StrPath,
|
|
316
|
+
*,
|
|
317
|
+
inp: StrPath | Iterable[StrPath] = (),
|
|
318
|
+
check_md5: bool = False,
|
|
319
|
+
verbose: bool = False,
|
|
320
|
+
resources: dict[str, int] | str | None = None,
|
|
321
|
+
duration: float | None = None,
|
|
322
|
+
) -> StepInfo:
|
|
323
|
+
"""Synchronize a draft dataset on Zenodo with local files and metadata.
|
|
324
|
+
|
|
325
|
+
The step runs at every start of StepUp, after every change of its inputs,
|
|
326
|
+
and in watch mode after the `R` key or `stepup rebuild --recheck`,
|
|
327
|
+
as a step with `recheck=True` in StepUp Core.
|
|
328
|
+
It contacts Zenodo only when the `STEPUP_DATA_ZENODO_TOKEN` environment variable is set
|
|
329
|
+
and StepUp does not run offline.
|
|
330
|
+
|
|
331
|
+
Parameters
|
|
332
|
+
----------
|
|
333
|
+
path_config
|
|
334
|
+
The configuration file for the Zenodo upload, in YAML, JSON or TOML format,
|
|
335
|
+
which is selected by the extension `.yaml`, `.yml`, `.json` or `.toml`.
|
|
336
|
+
path_description
|
|
337
|
+
A Markdown (`.md`) or HTML (`.html`) file with the description of the dataset.
|
|
338
|
+
Markdown is converted to HTML before it is sent to Zenodo.
|
|
339
|
+
path_inventory
|
|
340
|
+
The inventory of the files to upload, with the extension `.jsonl`,
|
|
341
|
+
usually written by `make_inventory()` with the default hash algorithm, MD5.
|
|
342
|
+
The paths in the inventory are relative to its parent directory.
|
|
343
|
+
Zenodo does not support directory layouts or symbolic links,
|
|
344
|
+
so all files must be regular files with different names.
|
|
345
|
+
At most 100 files can be uploaded to a single record.
|
|
346
|
+
The first file is selected for preview on Zenodo.
|
|
347
|
+
inp
|
|
348
|
+
Additional inputs of the step, e.g. files in the inventory that other steps build.
|
|
349
|
+
The files listed in the inventory are detected automatically when the step runs,
|
|
350
|
+
see [Detected Inputs][stepup.data.api--detected-inputs].
|
|
351
|
+
check_md5
|
|
352
|
+
When `True`, the MD5 checksums of the local files are computed again
|
|
353
|
+
and compared to those in the inventory before anything is uploaded.
|
|
354
|
+
This suits an inventory that is not built in the same workflow.
|
|
355
|
+
An inventory built by `make_inventory()` is always up to date,
|
|
356
|
+
so the check is then redundant.
|
|
357
|
+
verbose
|
|
358
|
+
When `True`, the Zenodo API requests and responses are printed on standard output.
|
|
359
|
+
resources
|
|
360
|
+
Named resources required to run this step, e.g. `{"zenodo": 1}`.
|
|
361
|
+
See `stepup.core.api.step()` for details.
|
|
362
|
+
duration
|
|
363
|
+
An initial estimate of the step's wall time in seconds.
|
|
364
|
+
See `stepup.core.api.step()` for details.
|
|
365
|
+
|
|
366
|
+
Returns
|
|
367
|
+
-------
|
|
368
|
+
step_info
|
|
369
|
+
Holds relevant information of the step, useful for defining follow-up steps.
|
|
370
|
+
|
|
371
|
+
Raises
|
|
372
|
+
------
|
|
373
|
+
PathError
|
|
374
|
+
When `path_config` is named `.zenodo.json` or has an unsupported extension,
|
|
375
|
+
when `path_description` has an extension other than `.md` or `.html`,
|
|
376
|
+
or when `path_inventory` does not have the extension `.jsonl`.
|
|
377
|
+
|
|
378
|
+
Notes
|
|
379
|
+
-----
|
|
380
|
+
Environment variables in all path arguments are substituted immediately,
|
|
381
|
+
and the variables referenced are added to the calling step's `env_deps` list with `amend()`.
|
|
382
|
+
These substitutions are based on the state of `os.environ` in the calling script,
|
|
383
|
+
at the time this function is called, not when the step is executed.
|
|
384
|
+
"""
|
|
385
|
+
with subs_env_vars() as subs_env:
|
|
386
|
+
su_path_config = subs_env(path_config)
|
|
387
|
+
su_path_description = subs_env(path_description)
|
|
388
|
+
su_path_inventory = subs_env(path_inventory)
|
|
389
|
+
su_inp = [subs_env(path) for path in coerce_paths(inp)]
|
|
390
|
+
check_sync_zenodo_paths(su_path_config, su_path_description, su_path_inventory)
|
|
391
|
+
paths_main = [su_path_config, su_path_description, su_path_inventory]
|
|
392
|
+
parts = ["sd-sync-zenodo", shq(paths_main)]
|
|
393
|
+
if not check_md5:
|
|
394
|
+
parts.append("--no-check-md5")
|
|
395
|
+
if verbose:
|
|
396
|
+
parts.append("--verbose")
|
|
397
|
+
return run(
|
|
398
|
+
" ".join(parts),
|
|
399
|
+
inp=[*paths_main, *su_inp],
|
|
400
|
+
recheck=True,
|
|
401
|
+
resources=resources,
|
|
402
|
+
duration=duration,
|
|
403
|
+
)
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2024 Toon Verstraelen <Toon.Verstraelen@UGent.be>
|
|
2
|
+
# SPDX-License-Identifier: LGPL-3.0-or-later
|
|
3
|
+
"""Checks of arguments, shared by the API function and the console script.
|
|
4
|
+
|
|
5
|
+
The paths are checked without reading the files.
|
|
6
|
+
This module imports nothing beyond StepUp Core,
|
|
7
|
+
so that the arguments of `sync_zenodo()` can be checked while planning,
|
|
8
|
+
without loading the libraries needed to contact Zenodo.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from stepup.core.exceptions import PathError
|
|
12
|
+
from stepup.core.path import StrPath, check_extension, coerce_path
|
|
13
|
+
|
|
14
|
+
__all__ = ("CONFIG_FORMATS", "check_sync_zenodo_paths")
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
CONFIG_FORMATS = {".json": "JSON", ".toml": "TOML", ".yaml": "YAML", ".yml": "YAML"}
|
|
18
|
+
"""The format of a configuration file for each supported extension, in lowercase."""
|
|
19
|
+
|
|
20
|
+
DESCRIPTION_SUFFIXES = (".html", ".md")
|
|
21
|
+
"""The supported extensions of a description file, in lowercase."""
|
|
22
|
+
|
|
23
|
+
LEGACY_ZENODO_JSON = ".zenodo.json"
|
|
24
|
+
"""The metadata file that Zenodo reads when it archives a GitHub release."""
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def check_sync_zenodo_paths(
|
|
28
|
+
path_config: StrPath,
|
|
29
|
+
path_description: StrPath,
|
|
30
|
+
path_inventory: StrPath,
|
|
31
|
+
*,
|
|
32
|
+
names: tuple[str, str, str] = ("path_config", "path_description", "path_inventory"),
|
|
33
|
+
):
|
|
34
|
+
"""Check the names of the files to synchronize with Zenodo, without reading them.
|
|
35
|
+
|
|
36
|
+
The extensions are compared case-insensitively.
|
|
37
|
+
|
|
38
|
+
Parameters
|
|
39
|
+
----------
|
|
40
|
+
path_config
|
|
41
|
+
The configuration file, with an extension in `CONFIG_FORMATS`.
|
|
42
|
+
path_description
|
|
43
|
+
The description file, with an extension in `DESCRIPTION_SUFFIXES`.
|
|
44
|
+
path_inventory
|
|
45
|
+
The inventory, with the extension `.jsonl`.
|
|
46
|
+
names
|
|
47
|
+
The names of the arguments or the options that hold the three paths,
|
|
48
|
+
used in the error messages.
|
|
49
|
+
|
|
50
|
+
Raises
|
|
51
|
+
------
|
|
52
|
+
PathError
|
|
53
|
+
When `path_config` is named `.zenodo.json`
|
|
54
|
+
or does not have one of the extensions in `CONFIG_FORMATS`,
|
|
55
|
+
when `path_description` does not have one of the extensions in `DESCRIPTION_SUFFIXES`,
|
|
56
|
+
or when `path_inventory` does not have the extension `.jsonl`.
|
|
57
|
+
"""
|
|
58
|
+
path_config = coerce_path(path_config)
|
|
59
|
+
if path_config.name == LEGACY_ZENODO_JSON:
|
|
60
|
+
raise PathError(
|
|
61
|
+
f"{path_config} is not a sd-sync-zenodo configuration file. "
|
|
62
|
+
f"A file named {LEGACY_ZENODO_JSON} holds the metadata that Zenodo reads "
|
|
63
|
+
"when it archives a GitHub release, which follows a different schema. "
|
|
64
|
+
"It is documented in the GitHub integration section of "
|
|
65
|
+
"https://developers.zenodo.org/#github"
|
|
66
|
+
)
|
|
67
|
+
name_config, name_description, name_inventory = names
|
|
68
|
+
check_extension(path_config, CONFIG_FORMATS, name_config)
|
|
69
|
+
check_extension(path_description, DESCRIPTION_SUFFIXES, name_description)
|
|
70
|
+
check_extension(path_inventory, ".jsonl", name_inventory)
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2024 Toon Verstraelen <Toon.Verstraelen@UGent.be>
|
|
2
|
+
# SPDX-License-Identifier: LGPL-3.0-or-later
|
|
3
|
+
"""Check that the files listed in an inventory match their records."""
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import sys
|
|
7
|
+
from collections.abc import Sequence
|
|
8
|
+
|
|
9
|
+
from stepup.core.api import amend
|
|
10
|
+
from stepup.core.exceptions import PathError
|
|
11
|
+
from stepup.core.extapi import check_input_file, console_script
|
|
12
|
+
from stepup.core.path import Path, StrPath, check_extension
|
|
13
|
+
|
|
14
|
+
from .inventory import check_record, compute_record, open_inventory
|
|
15
|
+
|
|
16
|
+
__all__ = ("main",)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@console_script("sd-check-inventory")
|
|
20
|
+
def main(argv: Sequence[str] | None = None) -> None:
|
|
21
|
+
"""Run the `sd-check-inventory` console script."""
|
|
22
|
+
args = parse_args(argv)
|
|
23
|
+
check_input_file(args.inventory, "inventory")
|
|
24
|
+
check_inventory(args.inventory)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def parse_args(argv: Sequence[str] | None = None) -> argparse.Namespace:
|
|
28
|
+
"""Parse and check the command-line arguments of `sd-check-inventory`."""
|
|
29
|
+
parser = argparse.ArgumentParser(
|
|
30
|
+
prog="sd-check-inventory",
|
|
31
|
+
description="Check that the files listed in an inventory match their records.",
|
|
32
|
+
)
|
|
33
|
+
parser.add_argument(
|
|
34
|
+
"inventory",
|
|
35
|
+
type=Path,
|
|
36
|
+
help="An inventory file with the extension .jsonl, written by sd-make-inventory.",
|
|
37
|
+
)
|
|
38
|
+
args = parser.parse_args(argv)
|
|
39
|
+
try:
|
|
40
|
+
check_extension(args.inventory, ".jsonl", "inventory")
|
|
41
|
+
except PathError as exc:
|
|
42
|
+
parser.error(str(exc))
|
|
43
|
+
return args
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def check_inventory(path_inventory: StrPath):
|
|
47
|
+
"""Check that the files on disk match the records of an inventory.
|
|
48
|
+
|
|
49
|
+
Parameters
|
|
50
|
+
----------
|
|
51
|
+
path_inventory
|
|
52
|
+
The inventory file, with the extension `.jsonl`.
|
|
53
|
+
The paths of its records are relative to its parent directory.
|
|
54
|
+
The listed files are amended as inputs of the current step,
|
|
55
|
+
so that the check runs again when they change,
|
|
56
|
+
except for symbolic links to directories.
|
|
57
|
+
|
|
58
|
+
Raises
|
|
59
|
+
------
|
|
60
|
+
PathError
|
|
61
|
+
When `path_inventory` does not have the extension `.jsonl`.
|
|
62
|
+
InventoryError
|
|
63
|
+
When the inventory cannot be read or when a file differs from its record.
|
|
64
|
+
"""
|
|
65
|
+
path_inventory = Path(path_inventory)
|
|
66
|
+
check_extension(path_inventory, ".jsonl", "path_inventory")
|
|
67
|
+
root = path_inventory.parent
|
|
68
|
+
with open_inventory(path_inventory) as reader:
|
|
69
|
+
header = reader.header
|
|
70
|
+
refs = list(reader)
|
|
71
|
+
# Without the listed files as inputs, StepUp would only rerun this step
|
|
72
|
+
# when the inventory changes, which it does not when a file is damaged afterwards.
|
|
73
|
+
# A link to a directory is left out, because StepUp does not accept directories as inputs,
|
|
74
|
+
# but its target is still checked below.
|
|
75
|
+
paths = [(root / ref.path).normpath() for ref in refs]
|
|
76
|
+
amend(inp=[path for path in paths if not path.is_dir()])
|
|
77
|
+
for ref in refs:
|
|
78
|
+
new = compute_record(root / ref.path, root, header.hash_algo, header.mode)
|
|
79
|
+
check_record(new, ref)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
if __name__ == "__main__":
|
|
83
|
+
sys.exit(main())
|