stepup.data.api
Application programming interface for StepUp Data.
make_inventory(dest, *, paths=(), include=(), include_info_inp=(), include_info_out=(), exclude=(), hash_algorithm='md5', mode=False, optional=False, resources=None, duration=None)
¶
Create an inventory file, in JSON Lines format with suffix .jsonl.
The format and the selection of the files are explained in the documentation of StepUp Data, under “Inventory Files”. All paths and patterns are relative to the working directory of the step.
Parameters:
-
dest(StrPath) –The inventory file to write, with suffix
.jsonl. -
paths(StrPath | Collection[StrPath], default:()) –Files to include in the inventory, in the given order. They are never interpreted as patterns.
-
include(str | Collection[str], default:()) –Patterns of files to include, which must match static files. An entry without wildcards is a literal path, which may also be the output of another step. The included files come after
paths, sorted. A pattern that matches no files is an error. -
include_info_inp(StrPath | Collection[StrPath], default:()) –Step info files, whose
inporoutpaths, respectively, are included, e.g. written bydump_step_info()in StepUp Core. The step info files are inputs of the step, and may be built by other steps. The included files come afterpaths, sorted together with those ofinclude. -
include_info_out(StrPath | Collection[StrPath], default:()) –Step info files, whose
inporoutpaths, respectively, are included, e.g. written bydump_step_info()in StepUp Core. The step info files are inputs of the step, and may be built by other steps. The included files come afterpaths, sorted together with those ofinclude. -
exclude(str | Collection[str], default:()) –Patterns or literal paths of files to leave out, matched against the names of the files selected by the other arguments.
-
hash_algorithm(str | None, default:'md5') –The name of the
hashlibalgorithm for the digests of the files. The default,md5, is the one that Zenodo reports. Usesha256when deliberate tampering with the files must be detected. WithNone, no digests are recorded and the contents of the files are not read, which saves time for large datasets, but then changes that keep the size of a file are not detected, and the inventory cannot be used bysync_zenodo(). -
mode(bool, default:False) –When True, the permission bits of the files are recorded and checked. Files have no permission bits on Windows, where the recorded modes depend on the read-only attribute and the file names.
-
optional(bool, default:False) –If
True, the step is only executed when needed by other steps. -
resources(dict[str, int] | str | None, default:None) –Named resources required to run this step, e.g.
{"gpu": 1}. Seestepup.core.api.step()for details. -
duration(float | None, default:None) –An initial estimate of the step’s wall time in seconds. See
stepup.core.api.step()for details.
Returns:
-
step_info–Holds relevant information of the step, useful for defining follow-up steps.
Source code in stepup/data/api.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
sync_zenodo(path_config, path_description, path_inventory, *, check_md5=False, verbose=False, resources=None, duration=None)
¶
Synchronize data with a draft dataset on Zenodo.
The step runs at every start of StepUp, after every change of its inputs,
and in watch mode after the R key or stepup rebuild --recheck,
as a step with recheck=True in StepUp Core.
It contacts Zenodo only when the STEPUP_DATA_ZENODO_TOKEN environment variable is set
and StepUp does not run offline.
Parameters:
-
path_config(StrPath) –The configuration file for the Zenodo upload, in YAML, JSON or TOML format.
-
path_description(StrPath) –A Markdown (
.md) or HTML (.html) file with the description of the dataset. Markdown is converted to HTML before it is sent to Zenodo. -
path_inventory(StrPath) –The inventory of the files to upload, usually written by
make_inventory()with the default hash algorithm, MD5. The paths in the inventory are relative to its parent directory. Zenodo does not support directory layouts or symbolic links, so all files must be regular files with different names. At most 100 files can be uploaded to a single record. The first file is selected for preview on Zenodo. -
check_md5(bool, default:False) –When True, the MD5 checksums of the local files are computed again and compared to those in the inventory before anything is uploaded. This suits an inventory that is not built in the same workflow. An inventory built by
make_inventory()is always up to date, so the check is then redundant. -
verbose(bool, default:False) –Set to True to print Zenodo API requests and responses to the standard output.
-
resources(dict[str, int] | str | None, default:None) –Named resources required to run this step, e.g.
{"zenodo": 1}. Seestepup.core.api.step()for details. -
duration(float | None, default:None) –An initial estimate of the step’s wall time in seconds. See
stepup.core.api.step()for details.
Returns:
-
step_info–Holds relevant information of the step, useful for defining follow-up steps.
Source code in stepup/data/api.py
zip_inventory(path_inventory, dest=None, *, optional=False, resources=None, duration=None)
¶
Create a ZIP file with all files listed in an inventory, after checking them.
Parameters:
-
path_inventory(StrPath) –An inventory file with suffix
.jsonl, created withmake_inventory()or with the command-line scriptsd-make-inventory. The files are stored in the ZIP file under the paths of their records, which must therefore be inside the directory of the inventory. They are also amended as inputs of the step, so the ZIP file is rebuilt when they change, even when the inventory does not. The inventory itself is not added to the ZIP file. Keep the inventory next to the ZIP file to check the unpacked files withsd-check-inventory. -
dest(StrPath | None, default:None) –Output destination:
None, a directory with a trailing slash, or a file. WhenNone, the ZIP file is written next to the inventory, with suffix.zip. In a directory, the ZIP file has the name of the inventory, with suffix.zip. A file must have suffix.zip. -
optional(bool, default:False) –If
True, the step is only executed when needed by other steps. -
resources(dict[str, int] | str | None, default:None) –Named resources required to run this step, e.g.
{"gpu": 1}. Seestepup.core.api.step()for details. -
duration(float | None, default:None) –An initial estimate of the step’s wall time in seconds. See
stepup.core.api.step()for details.
Returns:
-
step_info–Holds relevant information of the step, useful for defining follow-up steps.