cldfzenodo 3.3.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.
- cldfzenodo/__init__.py +7 -0
- cldfzenodo/api.py +310 -0
- cldfzenodo/commands/__init__.py +0 -0
- cldfzenodo/commands/download.py +48 -0
- cldfzenodo/commands/upload.py +61 -0
- cldfzenodo/record.py +338 -0
- cldfzenodo-3.3.0.dist-info/METADATA +175 -0
- cldfzenodo-3.3.0.dist-info/RECORD +12 -0
- cldfzenodo-3.3.0.dist-info/WHEEL +5 -0
- cldfzenodo-3.3.0.dist-info/entry_points.txt +5 -0
- cldfzenodo-3.3.0.dist-info/licenses/LICENSE +201 -0
- cldfzenodo-3.3.0.dist-info/top_level.txt +1 -0
cldfzenodo/__init__.py
ADDED
cldfzenodo/api.py
ADDED
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This module provides an API to retrieve CLDF datasets deposited on Zenodo.
|
|
3
|
+
"""
|
|
4
|
+
import re
|
|
5
|
+
import json
|
|
6
|
+
import shlex
|
|
7
|
+
import pathlib
|
|
8
|
+
import subprocess
|
|
9
|
+
import urllib.error
|
|
10
|
+
import urllib.parse
|
|
11
|
+
import urllib.request
|
|
12
|
+
from collections.abc import Generator
|
|
13
|
+
|
|
14
|
+
from pycldf import Source
|
|
15
|
+
from pycldf.ext.discovery import DatasetResolver
|
|
16
|
+
from clldutils.path import ensure_cmd
|
|
17
|
+
|
|
18
|
+
from cldfzenodo.record import Record, ZENODO_DOI_FORMAT, ZENODO_DOI_PATTERN, get_doi
|
|
19
|
+
|
|
20
|
+
__all__ = ["API", "Api", "ZenodoResolver"]
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def get_hits(res: str | dict | list) -> list[dict]:
|
|
24
|
+
"""Extract the hits from a search result."""
|
|
25
|
+
if isinstance(res, str):
|
|
26
|
+
res = json.loads(res)
|
|
27
|
+
return res if isinstance(res, list) else res["hits"]["hits"]
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def q(**kw) -> str:
|
|
31
|
+
"""
|
|
32
|
+
Put together a Zenodo search query from the data in `kw`.
|
|
33
|
+
|
|
34
|
+
See https://help.zenodo.org/guides/search/ for details.
|
|
35
|
+
"""
|
|
36
|
+
res = kw.pop("_q", "") or ""
|
|
37
|
+
if kw:
|
|
38
|
+
res += "" + " ".join(f'{k}:"{v}"' for k, v in kw.items())
|
|
39
|
+
return res.strip()
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class Results: # pylint: disable=R0903
|
|
43
|
+
"""Object to step through Zenodo search results."""
|
|
44
|
+
|
|
45
|
+
def __init__(
|
|
46
|
+
self,
|
|
47
|
+
api: "Api",
|
|
48
|
+
allversions: bool = False,
|
|
49
|
+
community: str | None = None,
|
|
50
|
+
**params: str):
|
|
51
|
+
"""
|
|
52
|
+
:param params: URL parameters (see https://developers.zenodo.org/#records)
|
|
53
|
+
"""
|
|
54
|
+
self.api = api
|
|
55
|
+
self.params = params
|
|
56
|
+
self.community = community
|
|
57
|
+
if allversions:
|
|
58
|
+
self.params["allversions"] = "true"
|
|
59
|
+
self._page = 0
|
|
60
|
+
self.more = True
|
|
61
|
+
self.error = None
|
|
62
|
+
|
|
63
|
+
def next(self) -> list[Record]:
|
|
64
|
+
"""Return the next batch, i.e. page, of search results."""
|
|
65
|
+
self._page += 1
|
|
66
|
+
params = {
|
|
67
|
+
"sort": "-mostrecent",
|
|
68
|
+
"page": str(self._page),
|
|
69
|
+
"size": str(self.api.page_size),
|
|
70
|
+
}
|
|
71
|
+
params.update(self.params)
|
|
72
|
+
try:
|
|
73
|
+
hits = get_hits(self.api.records(community=self.community, params=params))
|
|
74
|
+
except urllib.error.HTTPError as e: # pragma: no cover
|
|
75
|
+
# We want to be able to resume retrieval of results.
|
|
76
|
+
self.error = e
|
|
77
|
+
self._page -= 1
|
|
78
|
+
raise
|
|
79
|
+
self.more = len(hits) >= self.api.page_size
|
|
80
|
+
return [Record.from_dict(r) for r in hits]
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
class Api:
|
|
84
|
+
"""An API to search Zenodo."""
|
|
85
|
+
|
|
86
|
+
__base_url__ = "https://zenodo.org/api/"
|
|
87
|
+
__communities__ = {} # We cash community identifiers.
|
|
88
|
+
|
|
89
|
+
def __init__(self, page_size: int = 25):
|
|
90
|
+
self.page_size = page_size
|
|
91
|
+
|
|
92
|
+
def __call__(
|
|
93
|
+
self,
|
|
94
|
+
what: str,
|
|
95
|
+
id_: str | None = None,
|
|
96
|
+
params: dict[str, str] | None = None,
|
|
97
|
+
headers: dict[str, str] | None = None,
|
|
98
|
+
_verbose: bool = False,
|
|
99
|
+
) -> str:
|
|
100
|
+
"""
|
|
101
|
+
Perform an API call and return the response body as str.
|
|
102
|
+
|
|
103
|
+
:param what: Name of the API resource, e.g. "records".
|
|
104
|
+
:param id_: Optional identifier of a resource instance.
|
|
105
|
+
:param params: URL query parameters.
|
|
106
|
+
:param headers: HTTP request headers.
|
|
107
|
+
:param _verbose:
|
|
108
|
+
:return: Body of the response as text.
|
|
109
|
+
"""
|
|
110
|
+
params = params or {}
|
|
111
|
+
headers = headers or {}
|
|
112
|
+
comps = urllib.parse.urlparse(
|
|
113
|
+
self.__base_url__ + f"{what}{'/' + id_ if id_ else ''}"
|
|
114
|
+
)
|
|
115
|
+
url = urllib.parse.urlunparse(
|
|
116
|
+
list(comps[:3]) + ["", urllib.parse.urlencode(params), ""]
|
|
117
|
+
)
|
|
118
|
+
req = urllib.request.Request(url)
|
|
119
|
+
for k, v in headers.items():
|
|
120
|
+
req.add_header(k, v)
|
|
121
|
+
if _verbose: # pragma: no cover
|
|
122
|
+
print(url)
|
|
123
|
+
return urllib.request.urlopen(req).read().decode("utf8")
|
|
124
|
+
|
|
125
|
+
def records(
|
|
126
|
+
self,
|
|
127
|
+
id_: str | None = None,
|
|
128
|
+
community: str | None = None,
|
|
129
|
+
params: dict[str, str] | None = None,
|
|
130
|
+
headers: dict[str, str] | None = None,
|
|
131
|
+
) -> str:
|
|
132
|
+
"""
|
|
133
|
+
Perfom an API call to the records resource (possibly limited to one community).
|
|
134
|
+
|
|
135
|
+
:param id_: Optional record identifier.
|
|
136
|
+
:param community: Zenodo community identifier. If specified, only records in this community\
|
|
137
|
+
are considered.
|
|
138
|
+
:param params: URL query parameters.
|
|
139
|
+
:param headers: HTTP request headers.
|
|
140
|
+
:return: Body of the response as text.
|
|
141
|
+
"""
|
|
142
|
+
what = ""
|
|
143
|
+
if community:
|
|
144
|
+
if community not in self.__communities__:
|
|
145
|
+
self.__communities__[community] = json.loads(
|
|
146
|
+
self("communities", community)
|
|
147
|
+
)["id"]
|
|
148
|
+
what = f"communities/{self.__communities__[community]}/"
|
|
149
|
+
what += "records"
|
|
150
|
+
return self(what, id_=id_, params=params, headers=headers)
|
|
151
|
+
|
|
152
|
+
def iter_versions(self, conceptdoi: str) -> Generator[Record, None, None]:
|
|
153
|
+
"""
|
|
154
|
+
Retrieve all versions recorded for a concept DOI.
|
|
155
|
+
"""
|
|
156
|
+
yield from self.iter_records(conceptdoi=get_doi(conceptdoi), allversions=True)
|
|
157
|
+
|
|
158
|
+
@staticmethod
|
|
159
|
+
def _first_record(res) -> Record | None:
|
|
160
|
+
hits = get_hits(res)
|
|
161
|
+
if hits:
|
|
162
|
+
return Record.from_dict(hits[0])
|
|
163
|
+
return None # pragma: no cover
|
|
164
|
+
|
|
165
|
+
def get_record(
|
|
166
|
+
self,
|
|
167
|
+
doi: str | None = None,
|
|
168
|
+
conceptdoi: str | None = None,
|
|
169
|
+
version: str | None = None,
|
|
170
|
+
) -> Record | None:
|
|
171
|
+
"""
|
|
172
|
+
Retrieve a record specified by Zenodo DOI, given as URL or plain.
|
|
173
|
+
|
|
174
|
+
:param doi: A Zenodo DOI or URL identifying a record (i.e. no concept DOI).
|
|
175
|
+
:param conceptdoi: A Zenodo concept DOI. If no `version` is passed, the latest matching \
|
|
176
|
+
record will be returned.
|
|
177
|
+
:param version: A version tag, used to choose a particular record when only a concept doi \
|
|
178
|
+
is passed.
|
|
179
|
+
:return: A `Record` instance, if one is found, else `None`.
|
|
180
|
+
"""
|
|
181
|
+
if doi:
|
|
182
|
+
doi = get_doi(doi)
|
|
183
|
+
assert not conceptdoi
|
|
184
|
+
return self._first_record(
|
|
185
|
+
self.records(params={"allversions": "true", "q": q(doi=doi)})
|
|
186
|
+
)
|
|
187
|
+
assert conceptdoi
|
|
188
|
+
conceptdoi = get_doi(conceptdoi)
|
|
189
|
+
if not version:
|
|
190
|
+
return self._first_record(
|
|
191
|
+
self.records(params={"q": q(conceptdoi=conceptdoi)})
|
|
192
|
+
)
|
|
193
|
+
for rec in self.iter_records(conceptdoi=conceptdoi, allversions=True):
|
|
194
|
+
if rec.version.lstrip("v") == version.lstrip("v"):
|
|
195
|
+
return rec
|
|
196
|
+
return None
|
|
197
|
+
|
|
198
|
+
def iter_records(
|
|
199
|
+
self,
|
|
200
|
+
community: str | None = None,
|
|
201
|
+
keyword: str | None = None,
|
|
202
|
+
allversions: bool = False,
|
|
203
|
+
**kw,
|
|
204
|
+
) -> Generator[Record, None, Results | None]:
|
|
205
|
+
"""
|
|
206
|
+
Retrieve records matching various search criteria.
|
|
207
|
+
|
|
208
|
+
:param community: A Zenodo community identifier.
|
|
209
|
+
:param keyword: A keyword associated with relevant records.
|
|
210
|
+
:param allversions: A flag signaling whether only the latest version of each record is \
|
|
211
|
+
retrieved (the default) or all.
|
|
212
|
+
:param kw: Additional search terms according to the Zenodo search query language.
|
|
213
|
+
:return: A generator of records.
|
|
214
|
+
"""
|
|
215
|
+
if keyword:
|
|
216
|
+
kw["keywords"] = keyword
|
|
217
|
+
res = Results(self, allversions=allversions, community=community, q=q(**kw))
|
|
218
|
+
yield from res.next()
|
|
219
|
+
while res.more:
|
|
220
|
+
yield from res.next() # pragma: no cover
|
|
221
|
+
if res.error:
|
|
222
|
+
return res # pragma: no cover
|
|
223
|
+
return None
|
|
224
|
+
|
|
225
|
+
def get_github_release_info(
|
|
226
|
+
self, repos: str, tag: str | None = None, bibid: str | None = None
|
|
227
|
+
) -> tuple[str | None, str | None, str | None, Source | None]:
|
|
228
|
+
"""
|
|
229
|
+
Get information about a GitHub repository release that has been archived with Zenodo.
|
|
230
|
+
|
|
231
|
+
We assume, that the DOI of the upload on Zenodo has been added to the release description
|
|
232
|
+
on GitHub.
|
|
233
|
+
|
|
234
|
+
:param repos: GitHub repository specifier in the form `org/repo`.
|
|
235
|
+
:param tag: Optional version tag.
|
|
236
|
+
:param bibid: Optional identifier to use for the BibTeX record.
|
|
237
|
+
:return: A quadruple (tag, DOI, APA citation, BibTeX record)
|
|
238
|
+
"""
|
|
239
|
+
|
|
240
|
+
def gh(args):
|
|
241
|
+
return subprocess.check_output(
|
|
242
|
+
[ensure_cmd("gh")] + shlex.split(args)
|
|
243
|
+
).decode("utf8")
|
|
244
|
+
|
|
245
|
+
version_pattern = re.compile(r"(?P<tag>v[0-9]+\.[0-9]+(\.[0-9]+)?)")
|
|
246
|
+
doi_pattern = re.compile(r"https://doi\.org/(?P<doi>10\.5281/zenodo\.[0-9]+)")
|
|
247
|
+
|
|
248
|
+
if not tag:
|
|
249
|
+
latest = gh(f"release list -L 1 -R {repos}")
|
|
250
|
+
if not latest:
|
|
251
|
+
return None, None, None, None # pragma: no cover
|
|
252
|
+
match = version_pattern.search(latest)
|
|
253
|
+
assert match, latest
|
|
254
|
+
tag = match.group("tag")
|
|
255
|
+
|
|
256
|
+
info = gh(f"release view {tag} -R {repos}")
|
|
257
|
+
match = None
|
|
258
|
+
for match in doi_pattern.finditer(info):
|
|
259
|
+
pass
|
|
260
|
+
if match:
|
|
261
|
+
doi = match.group("doi")
|
|
262
|
+
if doi:
|
|
263
|
+
cit = self.records(
|
|
264
|
+
id_=ZENODO_DOI_PATTERN.match(doi).group("recid"),
|
|
265
|
+
params={"style": "apa"},
|
|
266
|
+
headers={"Accept": "text/x-bibliography"},
|
|
267
|
+
).strip()
|
|
268
|
+
bib = self.records(
|
|
269
|
+
id_=ZENODO_DOI_PATTERN.match(doi).group("recid"),
|
|
270
|
+
params={"style": "bibtex"},
|
|
271
|
+
headers={"Accept": "text/x-bibliography"},
|
|
272
|
+
).strip()
|
|
273
|
+
bib = Source.from_bibtex(
|
|
274
|
+
re.sub(
|
|
275
|
+
r", (?P<field>[a-zA-Z]+)=",
|
|
276
|
+
lambda m: f",\n {m.group('field')} = ",
|
|
277
|
+
bib,
|
|
278
|
+
),
|
|
279
|
+
_check_id=False,
|
|
280
|
+
)
|
|
281
|
+
bib.id = bibid or repos.replace("/", "_")
|
|
282
|
+
for field in ["abstractNote", "month"]:
|
|
283
|
+
if field in bib:
|
|
284
|
+
del bib[field]
|
|
285
|
+
bib["edition"] = tag
|
|
286
|
+
bib["type"] = "Data set"
|
|
287
|
+
return tag, doi, cit, bib
|
|
288
|
+
return tag, None, None, None # pragma: no cover
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
# Since an Api instance does some caching, we provide one instance as module global.
|
|
292
|
+
API = Api()
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
class ZenodoResolver(DatasetResolver): # pylint: disable=R0903
|
|
296
|
+
"""Resolve location and download CLDF datasets deposited on Zenodo."""
|
|
297
|
+
|
|
298
|
+
def __call__(self, loc, download_dir) -> pathlib.Path | None:
|
|
299
|
+
doi = None
|
|
300
|
+
m = ZENODO_DOI_PATTERN.search(loc)
|
|
301
|
+
if m:
|
|
302
|
+
doi = loc[m.start() : m.end()] # noqa: E203
|
|
303
|
+
else:
|
|
304
|
+
m = re.search(r"zenodo\.org/record(s)?/(?P<number>[0-9]+)", loc)
|
|
305
|
+
if m:
|
|
306
|
+
doi = ZENODO_DOI_FORMAT.format(m.group("number"))
|
|
307
|
+
if doi:
|
|
308
|
+
rec = API.get_record(doi=doi) or API.get_record(conceptdoi=doi)
|
|
309
|
+
return rec.download(download_dir)
|
|
310
|
+
return None # pragma: no cover
|
|
File without changes
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Download a CLDF dataset from Zenodo
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import pathlib
|
|
6
|
+
|
|
7
|
+
from clldutils.clilib import PathType
|
|
8
|
+
|
|
9
|
+
from cldfzenodo.api import API
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def register(parser): # pylint: disable=C0116
|
|
13
|
+
parser.add_argument(
|
|
14
|
+
"doi", help="DOI of the dataset, starting with 10.5281, Zenodo's DOI prefix."
|
|
15
|
+
)
|
|
16
|
+
parser.add_argument(
|
|
17
|
+
"--directory",
|
|
18
|
+
help="Output directory (will be created if it does not exist).",
|
|
19
|
+
type=PathType(type="dir", must_exist=False),
|
|
20
|
+
default=pathlib.Path("."),
|
|
21
|
+
)
|
|
22
|
+
parser.add_argument(
|
|
23
|
+
"--version-tag",
|
|
24
|
+
help="If DOI is a concept DOI (see https://help.zenodo.org/#versioning), a version tag "
|
|
25
|
+
"can be specified to select a particular version of the dataset (rather than the "
|
|
26
|
+
"latest one).",
|
|
27
|
+
default=None,
|
|
28
|
+
)
|
|
29
|
+
parser.add_argument(
|
|
30
|
+
"--full-deposit",
|
|
31
|
+
action="store_true",
|
|
32
|
+
default=False,
|
|
33
|
+
help="Download all files of the deposit (rather than just the CLDF dataset).",
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def run(args): # pylint: disable=C0116
|
|
38
|
+
if args.version_tag:
|
|
39
|
+
rec = API.get_record(conceptdoi=args.doi, version=args.version_tag)
|
|
40
|
+
else:
|
|
41
|
+
rec = API.get_record(doi=args.doi)
|
|
42
|
+
if not rec:
|
|
43
|
+
raise ValueError("No record found") # pragma: no cover
|
|
44
|
+
if args.full_deposit:
|
|
45
|
+
rec.download(args.directory)
|
|
46
|
+
else:
|
|
47
|
+
rec.download_dataset(args.directory)
|
|
48
|
+
return 0
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Upload files for a Zenodo deposit.
|
|
3
|
+
|
|
4
|
+
While the GitHub-Zenodo integration is useful for CLDF datasets, it is not practical for large
|
|
5
|
+
amounts of media files. In such cases, media files can be put into a separate Zenodo deposit and
|
|
6
|
+
linked to the CLDF dataset using MediaTable's "Download_URL and Path_In_Zip" mechanism.
|
|
7
|
+
|
|
8
|
+
This command helps in this scenario as follows:
|
|
9
|
+
1. Create a new deposit on Zenodo (using a user account for which an ACCESS TOKEN with suitable
|
|
10
|
+
scope is available.)
|
|
11
|
+
2. Package the media files into zip files in one directory.
|
|
12
|
+
3. Run this command passing
|
|
13
|
+
- the directory containing the zip files
|
|
14
|
+
- the (7-digit) deposit ID
|
|
15
|
+
- the ACCESS TOKEN
|
|
16
|
+
"""
|
|
17
|
+
import os
|
|
18
|
+
import json
|
|
19
|
+
|
|
20
|
+
import requests
|
|
21
|
+
from clldutils.clilib import PathType
|
|
22
|
+
|
|
23
|
+
from cldfzenodo.api import API
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def register(parser): # pylint: disable=C0116
|
|
27
|
+
parser.add_argument(
|
|
28
|
+
'deposit_id',
|
|
29
|
+
help='7-digit ID of the deposit',
|
|
30
|
+
)
|
|
31
|
+
parser.add_argument(
|
|
32
|
+
'upload_dir',
|
|
33
|
+
type=PathType(type='dir'),
|
|
34
|
+
help='Directory holding the files to upload',
|
|
35
|
+
)
|
|
36
|
+
parser.add_argument(
|
|
37
|
+
'access_token',
|
|
38
|
+
help="Name of the environment variable holding the Zenodo ACCESS TOKEN for the requests.",
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def run(args): # pylint: disable=C0116
|
|
43
|
+
r = API(
|
|
44
|
+
'deposit/depositions',
|
|
45
|
+
id_=args.deposit_id,
|
|
46
|
+
params={'access_token': os.environ.get(args.access_token)},
|
|
47
|
+
headers={"Content-Type": "application/json"})
|
|
48
|
+
bucket_url = json.loads(r)['links']['bucket']
|
|
49
|
+
|
|
50
|
+
for p in args.upload_dir.iterdir():
|
|
51
|
+
if p.is_file():
|
|
52
|
+
r = requests.put(
|
|
53
|
+
f'{bucket_url}/{p.name}',
|
|
54
|
+
data=p.open('rb'),
|
|
55
|
+
headers={
|
|
56
|
+
"Accept": "application/json",
|
|
57
|
+
"Authorization": f"Bearer {os.environ.get(args.access_token)}",
|
|
58
|
+
"Content-Type": "application/octet-stream"},
|
|
59
|
+
timeout=3600,
|
|
60
|
+
)
|
|
61
|
+
args.log.info('%s\tHTTP %s', p.name, r.status_code)
|
cldfzenodo/record.py
ADDED
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Zenodo deposit record, as described by the DCAT metadata.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import io
|
|
6
|
+
import re
|
|
7
|
+
import json
|
|
8
|
+
import shutil
|
|
9
|
+
import logging
|
|
10
|
+
from typing import Any, TYPE_CHECKING, Self
|
|
11
|
+
import pathlib
|
|
12
|
+
import zipfile
|
|
13
|
+
import tempfile
|
|
14
|
+
import dataclasses
|
|
15
|
+
import urllib.parse
|
|
16
|
+
import urllib.request
|
|
17
|
+
import warnings
|
|
18
|
+
from collections.abc import Callable
|
|
19
|
+
|
|
20
|
+
import nameparser
|
|
21
|
+
from pycldf import iter_datasets, Source, Dataset
|
|
22
|
+
|
|
23
|
+
if TYPE_CHECKING:
|
|
24
|
+
from cldfzenodo import Api # pragma: no cover
|
|
25
|
+
|
|
26
|
+
__all__ = [
|
|
27
|
+
"Record",
|
|
28
|
+
"GithubRepos",
|
|
29
|
+
"ZENODO_DOI_FORMAT",
|
|
30
|
+
"ZENODO_DOI_PATTERN",
|
|
31
|
+
"get_doi",
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
ZENODO_DOI_PATTERN = re.compile(r"10\.5281/zenodo\.(?P<recid>[0-9]+)")
|
|
35
|
+
DOI_PATTERN = re.compile(r"10\.[0-9.]+/[^/]+")
|
|
36
|
+
ZENODO_DOI_FORMAT = "10.5281/zenodo.{}"
|
|
37
|
+
NS = dict( # pylint: disable=R1735
|
|
38
|
+
rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#",
|
|
39
|
+
adms="http://www.w3.org/ns/adms#",
|
|
40
|
+
dc="http://purl.org/dc/elements/1.1/",
|
|
41
|
+
dct="http://purl.org/dc/terms/",
|
|
42
|
+
citedcat="https://w3id.org/citedcat-ap/",
|
|
43
|
+
dctype="http://purl.org/dc/dcmitype/",
|
|
44
|
+
dcat="http://www.w3.org/ns/dcat#",
|
|
45
|
+
duv="http://www.w3.org/ns/duv#",
|
|
46
|
+
foaf="http://xmlns.com/foaf/0.1/",
|
|
47
|
+
frapo="http://purl.org/cerif/frapo/",
|
|
48
|
+
geo="http://www.w3.org/2003/01/geo/wgs84_pos#",
|
|
49
|
+
gsp="http://www.opengis.net/ont/geosparql#",
|
|
50
|
+
locn="http://www.w3.org/ns/locn#",
|
|
51
|
+
org="http://www.w3.org/ns/org#",
|
|
52
|
+
owl="http://www.w3.org/2002/07/owl#",
|
|
53
|
+
prov="http://www.w3.org/ns/prov#",
|
|
54
|
+
rdfs="http://www.w3.org/2000/01/rdf-schema#",
|
|
55
|
+
schema="http://schema.org/",
|
|
56
|
+
skos="http://www.w3.org/2004/02/skos/core#",
|
|
57
|
+
vcard="http://www.w3.org/2006/vcard/ns#",
|
|
58
|
+
wdrs="http://www.w3.org/2007/05/powder-s#",
|
|
59
|
+
)
|
|
60
|
+
HTTP_OK = 200
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
@dataclasses.dataclass
|
|
64
|
+
class GithubRepos:
|
|
65
|
+
"""
|
|
66
|
+
Zenodo deposits via the GitHub-Zenodo bridge carry enough metadata to retrieve the source
|
|
67
|
+
repository. This info is particularly interesting for us, because we prefer downloading
|
|
68
|
+
releases from GitHub over Zenodo, due to Zenodo's rate-limiting.
|
|
69
|
+
|
|
70
|
+
:ivar str org: GitHub organization name of the repository
|
|
71
|
+
:ivar str name: repository name
|
|
72
|
+
:ivar str tag: release tag of the version of the repository that was deposited on Zenodo
|
|
73
|
+
"""
|
|
74
|
+
|
|
75
|
+
org: str
|
|
76
|
+
name: str
|
|
77
|
+
tag: str = None
|
|
78
|
+
|
|
79
|
+
@classmethod
|
|
80
|
+
def from_url(cls, url: str) -> Self | None:
|
|
81
|
+
"""Instantiate a GithubRepos from a GitHub URL."""
|
|
82
|
+
url = urllib.parse.urlparse(url)
|
|
83
|
+
if url.netloc == "github.com":
|
|
84
|
+
path = url.path.split("/")
|
|
85
|
+
return cls(
|
|
86
|
+
org=path[1],
|
|
87
|
+
name=path[2],
|
|
88
|
+
tag=path[4] if len(path) > 4 and path[3] == "tree" else None, # noqa: PLR2004
|
|
89
|
+
)
|
|
90
|
+
return None
|
|
91
|
+
|
|
92
|
+
@property
|
|
93
|
+
def clone_url(self) -> str:
|
|
94
|
+
"""
|
|
95
|
+
:return: A URL suitable for passing to `git clone`.
|
|
96
|
+
"""
|
|
97
|
+
return f"https://github.com/{self.org}/{self.name}.git"
|
|
98
|
+
|
|
99
|
+
@property
|
|
100
|
+
def release_url(self) -> str | None:
|
|
101
|
+
"""
|
|
102
|
+
:return: The URL of a zipped release on GitHub.
|
|
103
|
+
"""
|
|
104
|
+
if self.tag:
|
|
105
|
+
return f"https://github.com/{self.org}/{self.name}/archive/refs/tags/{self.tag}.zip"
|
|
106
|
+
return None # pragma: no cover
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def get_doi(doi_or_url: str) -> str:
|
|
110
|
+
"""
|
|
111
|
+
|
|
112
|
+
.. code-block:: python
|
|
113
|
+
|
|
114
|
+
>>> get_doi('10.5281/zenodo.5173799')
|
|
115
|
+
'10.5281/zenodo.5173799'
|
|
116
|
+
>>> get_doi("https://doi.org/10.5281/zenodo.5173799")
|
|
117
|
+
'10.5281/zenodo.5173799'
|
|
118
|
+
>>> get_doi("https://zenodo.org/doi/10.5281/zenodo.5173799")
|
|
119
|
+
'10.5281/zenodo.5173799'
|
|
120
|
+
>>> get_doi("https://zenodo.org/record/5173799")
|
|
121
|
+
'10.5281/zenodo.5173799'
|
|
122
|
+
>>> get_doi("https://zenodo.org/records/5173799")
|
|
123
|
+
'10.5281/zenodo.5173799'
|
|
124
|
+
"""
|
|
125
|
+
url, doi = urllib.parse.urlparse(doi_or_url), None
|
|
126
|
+
if not url.netloc:
|
|
127
|
+
doi = url.path
|
|
128
|
+
elif url.netloc == "zenodo.org":
|
|
129
|
+
if url.path.startswith("/doi/"):
|
|
130
|
+
doi = url.path.replace("/doi/", "")
|
|
131
|
+
else:
|
|
132
|
+
doi = ZENODO_DOI_FORMAT.format(url.path.split("/")[-1])
|
|
133
|
+
elif url.netloc == "doi.org":
|
|
134
|
+
doi = url.path[1:]
|
|
135
|
+
else:
|
|
136
|
+
raise ValueError("Unknown DOI format")
|
|
137
|
+
if not (ZENODO_DOI_PATTERN.fullmatch(doi) or DOI_PATTERN.fullmatch(doi)):
|
|
138
|
+
raise ValueError(f'Not a DOI: "{doi}"')
|
|
139
|
+
return doi
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
@dataclasses.dataclass
|
|
143
|
+
class Record: # pylint: disable=too-many-instance-attributes
|
|
144
|
+
"""
|
|
145
|
+
Metadata of a Zenodo deposit
|
|
146
|
+
|
|
147
|
+
:ivar doi: The DOI of the record.
|
|
148
|
+
:ivar title: The title of the record.
|
|
149
|
+
:ivar typing.List[str] creators: List of names of the creators of the record.
|
|
150
|
+
"""
|
|
151
|
+
|
|
152
|
+
doi: str
|
|
153
|
+
title: str
|
|
154
|
+
creators: list[str] = dataclasses.field(default_factory=list)
|
|
155
|
+
year: str | None = None
|
|
156
|
+
license: str | None = None
|
|
157
|
+
download_urls: list[str] = dataclasses.field(default_factory=list)
|
|
158
|
+
keywords: list[str] = dataclasses.field(default_factory=list)
|
|
159
|
+
communities: list[str] = dataclasses.field(default_factory=list)
|
|
160
|
+
github_repos: str | None = None
|
|
161
|
+
closed_access: bool = False
|
|
162
|
+
version: str | None = None
|
|
163
|
+
concept_doi: str | None = None
|
|
164
|
+
metadata: dict[str, Any] = dataclasses.field(default_factory=dict)
|
|
165
|
+
|
|
166
|
+
def __post_init__(self):
|
|
167
|
+
self.doi = get_doi(self.doi)
|
|
168
|
+
assert DOI_PATTERN.match(self.doi)
|
|
169
|
+
|
|
170
|
+
formatted = []
|
|
171
|
+
for name in self.creators:
|
|
172
|
+
name = nameparser.parse(name) # noqa: PLW2901
|
|
173
|
+
first = name.given
|
|
174
|
+
if name.middle:
|
|
175
|
+
first += " " + name.middle
|
|
176
|
+
formatted.append(f"{name.family}, {first}")
|
|
177
|
+
self.creators = formatted
|
|
178
|
+
|
|
179
|
+
self.communities = [i for i in self.communities if i]
|
|
180
|
+
assert isinstance(self.closed_access, bool)
|
|
181
|
+
if not self.download_url:
|
|
182
|
+
assert self.closed_access, self.doi
|
|
183
|
+
|
|
184
|
+
@property
|
|
185
|
+
def download_url(self) -> str | None:
|
|
186
|
+
"""The first download URL specified for the record."""
|
|
187
|
+
return self.download_urls[0] if self.download_urls else None
|
|
188
|
+
|
|
189
|
+
@property
|
|
190
|
+
def id(self) -> str:
|
|
191
|
+
"""
|
|
192
|
+
:return: The Zenodo recid.
|
|
193
|
+
"""
|
|
194
|
+
return self.doi.replace("10.5281/zenodo.", "")
|
|
195
|
+
|
|
196
|
+
@property
|
|
197
|
+
def version_tag(self) -> str | None: # pragma: no cover
|
|
198
|
+
"""The closest thing to a version tag, found for the record."""
|
|
199
|
+
return self.version or (self.github_repos.tag if self.github_repos else None)
|
|
200
|
+
|
|
201
|
+
@classmethod
|
|
202
|
+
def from_dict(cls, d: dict[str, Any]) -> Self:
|
|
203
|
+
"""Instantiate a record from the JSON metadata delivered by the Zenodo API."""
|
|
204
|
+
kw = dict( # pylint: disable=R1735
|
|
205
|
+
doi=d["doi"],
|
|
206
|
+
title=d["metadata"]["title"],
|
|
207
|
+
keywords=d["metadata"].get("keywords"),
|
|
208
|
+
communities=[
|
|
209
|
+
dd.get("identifier", dd.get("id"))
|
|
210
|
+
for dd in d["metadata"].get("communities", [])
|
|
211
|
+
],
|
|
212
|
+
closed_access=d["metadata"]["access_right"] in {"closed", "restricted"},
|
|
213
|
+
creators=[c["name"] for c in d["metadata"]["creators"]],
|
|
214
|
+
year=d["metadata"]["publication_date"].split("-")[0],
|
|
215
|
+
version=d["metadata"].get("version"),
|
|
216
|
+
concept_doi=d.get(
|
|
217
|
+
"conceptdoi"
|
|
218
|
+
), # There are old records with "concept_rec_id" ...
|
|
219
|
+
# FIXME: # pylint: disable=fixme
|
|
220
|
+
# Check Zenodo API periodically to see whether URLs are correct now.
|
|
221
|
+
download_urls=[
|
|
222
|
+
f["links"]["self"].replace("/api/", "/") for f in d.get("files")
|
|
223
|
+
],
|
|
224
|
+
metadata=d["metadata"],
|
|
225
|
+
)
|
|
226
|
+
if "license" in d["metadata"]:
|
|
227
|
+
lic = d["metadata"]["license"]
|
|
228
|
+
kw["license"] = lic if isinstance(lic, str) else lic.get("identifier", lic.get("id"))
|
|
229
|
+
for ri in d["metadata"].get("related_identifiers", []):
|
|
230
|
+
if ri["relation"] == "isSupplementTo":
|
|
231
|
+
gh = GithubRepos.from_url(ri["identifier"])
|
|
232
|
+
if gh:
|
|
233
|
+
if gh.tag == d["metadata"].get("version"):
|
|
234
|
+
kw["github_repos"] = gh
|
|
235
|
+
else:
|
|
236
|
+
warnings.warn(
|
|
237
|
+
f'Related GitHub release with different version: {gh.tag} vs. '
|
|
238
|
+
f'{d["metadata"].get("version")}')
|
|
239
|
+
return cls(**kw)
|
|
240
|
+
|
|
241
|
+
@staticmethod
|
|
242
|
+
def _download(url, dest, log=None):
|
|
243
|
+
urlpath = pathlib.Path(urllib.parse.urlparse(url).path)
|
|
244
|
+
with urllib.request.urlopen(url) as res:
|
|
245
|
+
if res.code == HTTP_OK:
|
|
246
|
+
if log:
|
|
247
|
+
log.info("Downloading %s", url)
|
|
248
|
+
if urlpath.suffix == ".zip":
|
|
249
|
+
with zipfile.ZipFile(io.BytesIO(res.read())) as zipf:
|
|
250
|
+
zipf.extractall(path=dest)
|
|
251
|
+
else:
|
|
252
|
+
dest.joinpath(urlpath.name).write_bytes(res.read())
|
|
253
|
+
|
|
254
|
+
def download(
|
|
255
|
+
self,
|
|
256
|
+
dest: str | pathlib.Path,
|
|
257
|
+
log: logging.Logger | None = None,
|
|
258
|
+
unwrap: bool = True,
|
|
259
|
+
prefer_github: bool = True,
|
|
260
|
+
) -> pathlib.Path:
|
|
261
|
+
"""
|
|
262
|
+
Download the zipped file-content of the record to `dest`.
|
|
263
|
+
|
|
264
|
+
:param dest:
|
|
265
|
+
:param log:
|
|
266
|
+
:return: The directory containing the unzipped files of the record.
|
|
267
|
+
"""
|
|
268
|
+
dest = pathlib.Path(dest)
|
|
269
|
+
is_empty = not dest.exists() or (len(list(dest.iterdir())) == 0)
|
|
270
|
+
if not dest.exists():
|
|
271
|
+
dest.mkdir()
|
|
272
|
+
if not self.download_urls:
|
|
273
|
+
raise ValueError("No downloadable resources") # pragma: no cover
|
|
274
|
+
# Preferentially download from github to not run into Zenodo's rate limit.
|
|
275
|
+
if prefer_github and self.github_repos and self.github_repos.release_url:
|
|
276
|
+
print(self.github_repos.release_url)
|
|
277
|
+
self._download(self.github_repos.release_url, dest, log=log)
|
|
278
|
+
else:
|
|
279
|
+
for url in self.download_urls:
|
|
280
|
+
if url.endswith("/content"):
|
|
281
|
+
url = url[: -len("/content")] # pragma: no cover # noqa: PLW2901
|
|
282
|
+
self._download(url, dest, log=log)
|
|
283
|
+
inner = list(dest.iterdir())
|
|
284
|
+
if unwrap and is_empty and len(inner) == 1 and inner[0].is_dir():
|
|
285
|
+
# Move the content of the inner-directory to dest:
|
|
286
|
+
for p in inner[0].iterdir():
|
|
287
|
+
shutil.move(str(p), str(dest))
|
|
288
|
+
inner[0].rmdir()
|
|
289
|
+
# Write Zenodo metadata to a file:
|
|
290
|
+
dest.joinpath('.zenodo_metadata.json').write_text(json.dumps(self.metadata, indent=2))
|
|
291
|
+
return dest
|
|
292
|
+
|
|
293
|
+
def download_dataset(
|
|
294
|
+
self,
|
|
295
|
+
dest: str | pathlib.Path,
|
|
296
|
+
condition: Callable[[Dataset], bool] | None = None,
|
|
297
|
+
mdname: str | None = None,
|
|
298
|
+
log: logging.Logger | None = None,
|
|
299
|
+
) -> Dataset | None:
|
|
300
|
+
"""Download a particular CLDF dataset contained in the Zenodo deposit."""
|
|
301
|
+
with tempfile.TemporaryDirectory() as tmpdirname:
|
|
302
|
+
for ds in iter_datasets(self.download(tmpdirname, log=log)):
|
|
303
|
+
if (condition is None) or condition(ds):
|
|
304
|
+
return Dataset.from_metadata(ds.copy(dest, mdname=mdname))
|
|
305
|
+
return None # pragma: no cover
|
|
306
|
+
|
|
307
|
+
def get_bibtex(self, bibid: str | None = None) -> str:
|
|
308
|
+
"""Compose a BibTeX item from the metadata of the record."""
|
|
309
|
+
src = Source(
|
|
310
|
+
"misc",
|
|
311
|
+
bibid or self.doi.split("/")[-1].replace(".", "-"),
|
|
312
|
+
author=" and ".join(self.creators),
|
|
313
|
+
title=self.title,
|
|
314
|
+
keywords=", ".join(self.keywords),
|
|
315
|
+
publisher="Zenodo",
|
|
316
|
+
year=self.year,
|
|
317
|
+
edition=self.version,
|
|
318
|
+
doi=self.doi,
|
|
319
|
+
type="Data set",
|
|
320
|
+
url=f"https://doi.org/{self.doi}",
|
|
321
|
+
)
|
|
322
|
+
if self.license:
|
|
323
|
+
src["copyright"] = self.license
|
|
324
|
+
return src.bibtex()
|
|
325
|
+
|
|
326
|
+
@property
|
|
327
|
+
def bibtex(self) -> str:
|
|
328
|
+
"""BibTeX-formatted metadata for the record."""
|
|
329
|
+
return self.get_bibtex()
|
|
330
|
+
|
|
331
|
+
def get_citation(self, api: 'Api') -> str:
|
|
332
|
+
"""
|
|
333
|
+
Get a formatted citation for the record.
|
|
334
|
+
|
|
335
|
+
curl -H "Accept:text/x-bibliography" "https://zenodo.org/api/records/7079637?style=apa
|
|
336
|
+
"""
|
|
337
|
+
return api.records(
|
|
338
|
+
id_=self.id, params={'style': "apa"}, headers={'Accept': "text/x-bibliography"}).strip()
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cldfzenodo
|
|
3
|
+
Version: 3.3.0
|
|
4
|
+
Summary: Functionality to retrieve CLDF datasets deposited on Zenodo.
|
|
5
|
+
Author-email: Robert Forkel <dlce.rdm@eva.mpg.de>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/cldf/cldfzenodo
|
|
8
|
+
Keywords: zenodo,cldf,clld
|
|
9
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Natural Language :: English
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
19
|
+
Requires-Python: >=3.11
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: clldutils
|
|
23
|
+
Requires-Dist: pycldf
|
|
24
|
+
Requires-Dist: nameparser>=2.0
|
|
25
|
+
Requires-Dist: requests
|
|
26
|
+
Provides-Extra: cli
|
|
27
|
+
Requires-Dist: cldfbench; extra == "cli"
|
|
28
|
+
Provides-Extra: dev
|
|
29
|
+
Requires-Dist: ruff; extra == "dev"
|
|
30
|
+
Requires-Dist: wheel; extra == "dev"
|
|
31
|
+
Requires-Dist: build; extra == "dev"
|
|
32
|
+
Requires-Dist: twine; extra == "dev"
|
|
33
|
+
Provides-Extra: test
|
|
34
|
+
Requires-Dist: pytest>=5; extra == "test"
|
|
35
|
+
Requires-Dist: pytest-mock; extra == "test"
|
|
36
|
+
Requires-Dist: pytest-cov; extra == "test"
|
|
37
|
+
Requires-Dist: coverage>=4.2; extra == "test"
|
|
38
|
+
Dynamic: license-file
|
|
39
|
+
|
|
40
|
+
# cldfzenodo
|
|
41
|
+
|
|
42
|
+
[](https://github.com/cldf/cldfzenodo/actions?query=workflow%3Atests)
|
|
43
|
+
[](https://pypi.org/project/cldfzenodo)
|
|
44
|
+
|
|
45
|
+
`cldfzenodo` provides programmatic access to CLDF data deposited on [Zenodo](https://zenodo.org).
|
|
46
|
+
|
|
47
|
+
**NOTE:** The Zenodo upgrade from October 13, 2023 introduced quite a few changes in various parts
|
|
48
|
+
of the system. Thus, `cldfzenodo` before version 2.0 cannot be used anymore. `cldfzenodo` is meant
|
|
49
|
+
to be backwards compatible, i.e. provides the same Python API as `cldfzenodo` 1.x - but may issue
|
|
50
|
+
deprecation warnings.
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
## Install
|
|
54
|
+
|
|
55
|
+
```shell
|
|
56
|
+
pip install cldfzenodo
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
## `pycldf` dataset resolver
|
|
61
|
+
|
|
62
|
+
`cldfzenodo` registers (upon installation) a [`pycldf` dataset resolver](https://pycldf.readthedocs.io/en/latest/ext_discovery.html)
|
|
63
|
+
for dataset locators of the form `https://doi.org/10.5281/zenodo.[0-9]+` and `https://zenodo.org/record/[0-9]+`.
|
|
64
|
+
Thus, after installation you should be able to retrieve `pycldf.Dataset` instances running
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
>>> from pycldf.ext.discovery import get_dataset
|
|
68
|
+
>>> import pathlib
|
|
69
|
+
>>> pathlib.Path('wacl').mkdir()
|
|
70
|
+
>>> ds = get_dataset('https://doi.org/10.5281/zenodo.7322688', pathlib.Path('wacl'))
|
|
71
|
+
>>> ds.properties['dc:title']
|
|
72
|
+
'World Atlas of Classifier Languages'
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
## CLI
|
|
77
|
+
|
|
78
|
+
`cldfzenodo` provides a subcommand to be run from [cldfbench](https://github.com/cldf/cldfbench).
|
|
79
|
+
To make use of this command, you have to install `cldfbench`, which can be done via
|
|
80
|
+
```shell
|
|
81
|
+
pip install cldfzenodo[cli]
|
|
82
|
+
```
|
|
83
|
+
Then you can download CLDF datasets from Zenodo, using the DOI for identification. E.g.
|
|
84
|
+
```shell
|
|
85
|
+
cldfbench zenodo.download 10.5281/zenodo.4683137 --directory wals-2020.1/
|
|
86
|
+
```
|
|
87
|
+
will download WALS Online as CLDF dataset into `wals-2020.1`:
|
|
88
|
+
```shell
|
|
89
|
+
$ tree wals-2020.1/
|
|
90
|
+
wals-2020.1/
|
|
91
|
+
├── areas.csv
|
|
92
|
+
├── chapters.csv
|
|
93
|
+
├── codes.csv
|
|
94
|
+
├── contributors.csv
|
|
95
|
+
├── countries.csv
|
|
96
|
+
├── examples.csv
|
|
97
|
+
├── language_names.csv
|
|
98
|
+
├── languages.csv
|
|
99
|
+
├── parameters.csv
|
|
100
|
+
├── sources.bib
|
|
101
|
+
├── StructureDataset-metadata.json
|
|
102
|
+
└── values.csv
|
|
103
|
+
|
|
104
|
+
0 directories, 12 files
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
## API
|
|
109
|
+
|
|
110
|
+
Metadata and data of (potential) CLDF datasets deposited on Zenodo is accessed via `cldfzenodo.Record`
|
|
111
|
+
objects. Such objects can be obtained in various ways:
|
|
112
|
+
- Via DOI:
|
|
113
|
+
```python
|
|
114
|
+
>>> from cldfzenodo import API
|
|
115
|
+
>>> rec = API.get_record(doi='10.5281/zenodo.4762034')
|
|
116
|
+
>>> rec.title
|
|
117
|
+
'glottolog/glottolog: Glottolog database 4.4 as CLDF'
|
|
118
|
+
```
|
|
119
|
+
- Via [concept DOI](https://help.zenodo.org/#versioning) and version tag:
|
|
120
|
+
```python
|
|
121
|
+
>>> from cldfzenodo import API
|
|
122
|
+
>>> rec = API.get_record(conceptdoi='10.5281/zenodo.3260727', version='4.5')
|
|
123
|
+
>>> rec.title
|
|
124
|
+
'glottolog/glottolog: Glottolog database 4.5 as CLDF'
|
|
125
|
+
```
|
|
126
|
+
- From deposits grouped into a Zenodo community:
|
|
127
|
+
```python
|
|
128
|
+
>>> from cldfzenodo import API
|
|
129
|
+
>>> for rec in API.iter_records(community='dictionaria'):
|
|
130
|
+
... print(rec.title)
|
|
131
|
+
... break
|
|
132
|
+
...
|
|
133
|
+
dictionaria/iquito: Iquito dictionary
|
|
134
|
+
```
|
|
135
|
+
- From search results using keywords:
|
|
136
|
+
```python
|
|
137
|
+
>>> from cldfzenodo import API
|
|
138
|
+
>>> for rec in API.iter_records(keyword='cldf:Wordlist'):
|
|
139
|
+
... print(rec.title)
|
|
140
|
+
... break
|
|
141
|
+
...
|
|
142
|
+
CLDF dataset accompanying Zariquiey et al.'s "Evolution of Body-Part Terminology in Pano" from 2022
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
`cldfzenodo.Record` objects provide sufficient metadata to allow identification and data access:
|
|
146
|
+
```python
|
|
147
|
+
>>> from cldfzenodo import API
|
|
148
|
+
>>> print(API.get_record(doi='10.5281/zenodo.4762034').bibtex)
|
|
149
|
+
@misc{zenodo-4762034,
|
|
150
|
+
author = {Hammarström, Harald and Forkel, Robert and Haspelmath, Martin and Bank, Sebastian},
|
|
151
|
+
title = {glottolog/glottolog: Glottolog database 4.4 as CLDF},
|
|
152
|
+
keywords = {cldf:StructureDataset, linguistics},
|
|
153
|
+
publisher = {Zenodo},
|
|
154
|
+
year = {2021},
|
|
155
|
+
doi = {10.5281/zenodo.4762034},
|
|
156
|
+
url = {https://doi.org/10.5281/zenodo.4762034},
|
|
157
|
+
copyright = {Creative Commons Attribution 4.0}
|
|
158
|
+
}
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
One can download the full deposit (and access - possible multiple - CLDF datasets):
|
|
162
|
+
```python
|
|
163
|
+
from pycldf import iter_datasets
|
|
164
|
+
|
|
165
|
+
API.get_record(doi='...').download('my_directory')
|
|
166
|
+
for cldf in iter_datasets('my_directory'):
|
|
167
|
+
pass
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
But often, only the "pure" CLDF data is of interest - and not the additional metadata and curation
|
|
171
|
+
context, e.g. of [cldfbench](https://github.com/cldf/cldfbench)-curated datasets. This can be done
|
|
172
|
+
via
|
|
173
|
+
```python
|
|
174
|
+
cldf = API.get_record(doi='...').download_dataset('my_directory')
|
|
175
|
+
```
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
cldfzenodo/__init__.py,sha256=mXOoTDvLVDe37EvdKGH4G5adTPeZeF3JwVOY5XbkhBU,196
|
|
2
|
+
cldfzenodo/api.py,sha256=MDsRY0-NKoxoAlQ-4DY6bz1EtCo0OZB5vwGEQc6xf60,10918
|
|
3
|
+
cldfzenodo/record.py,sha256=oIFIGEBTDxlelFSDxxk05VpCftoyxQ_LJjCQOYRPhD8,12283
|
|
4
|
+
cldfzenodo/commands/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
cldfzenodo/commands/download.py,sha256=c20jzqnkz5NQTJEyGeQOWP-erfbfItIPA2iQ2-fxXcQ,1405
|
|
6
|
+
cldfzenodo/commands/upload.py,sha256=_VKzdU38Ehj3fkneAk80nrNU_iy4auqGCrNzDLYTyws,2018
|
|
7
|
+
cldfzenodo-3.3.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
8
|
+
cldfzenodo-3.3.0.dist-info/METADATA,sha256=1rQULrWnG9VWpxoxor5Ri5EXZr6o_PRDFPch3MtYDtw,5971
|
|
9
|
+
cldfzenodo-3.3.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
10
|
+
cldfzenodo-3.3.0.dist-info/entry_points.txt,sha256=29Y6mUD2yyWdrbbYaZqrmoOYrsf96h8wNaXKW12ULT4,116
|
|
11
|
+
cldfzenodo-3.3.0.dist-info/top_level.txt,sha256=cZitaA6V2Ks0hCHl9kixgB5nNKEXuerpnD7NXtnYSEI,11
|
|
12
|
+
cldfzenodo-3.3.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
cldfzenodo
|