-
Notifications
You must be signed in to change notification settings - Fork 2
/
utils.py
35 lines (27 loc) · 987 Bytes
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import uuid
def get_dataset_id(input, config):
"""Generate a v5 uuid"""
# consult config for custom ID selection,
# otherwise take plain standard field
fmt = config.get("dataset_id_fmt", "{dataset_id}")
# instantiate raw ID string
raw_id = fmt.format(**input)
# now turn into UUID deterministically
return str(
uuid.uuid5(
uuid.uuid5(uuid.NAMESPACE_DNS, "datalad.org"),
raw_id,
)
)
def mint_dataset_id(ds_name, project):
"""Create a deterministic id based on a custom convention
Uses "sfb151.{project}.{ds_name}" as an input for UUID
generation. Lowercases project. If there are multiple projects,
uses the first one given.
"""
dsid_input = {
"name": ds_name,
"project": project[0].lower() if isinstance(project, list) else project.lower(),
}
dsid_config = {"dataset_id_fmt": "sfb1451.{project}.{name}"}
return get_dataset_id(dsid_input, dsid_config)