cldfzenodo 2.2.2__tar.gz → 3.0.0__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.
- {cldfzenodo-2.2.2/src/cldfzenodo.egg-info → cldfzenodo-3.0.0}/PKG-INFO +5 -8
- {cldfzenodo-2.2.2 → cldfzenodo-3.0.0}/setup.cfg +6 -9
- cldfzenodo-3.0.0/src/cldfzenodo/__init__.py +7 -0
- {cldfzenodo-2.2.2 → cldfzenodo-3.0.0}/src/cldfzenodo/api.py +127 -92
- cldfzenodo-3.0.0/src/cldfzenodo/commands/download.py +48 -0
- cldfzenodo-3.0.0/src/cldfzenodo/record.py +324 -0
- {cldfzenodo-2.2.2 → cldfzenodo-3.0.0/src/cldfzenodo.egg-info}/PKG-INFO +5 -8
- {cldfzenodo-2.2.2 → cldfzenodo-3.0.0}/src/cldfzenodo.egg-info/SOURCES.txt +0 -3
- {cldfzenodo-2.2.2 → cldfzenodo-3.0.0}/src/cldfzenodo.egg-info/requires.txt +3 -5
- cldfzenodo-3.0.0/tests/test_cli.py +33 -0
- cldfzenodo-2.2.2/src/cldfzenodo/__init__.py +0 -37
- cldfzenodo-2.2.2/src/cldfzenodo/commands/download.py +0 -43
- cldfzenodo-2.2.2/src/cldfzenodo/oai.py +0 -8
- cldfzenodo-2.2.2/src/cldfzenodo/record.py +0 -295
- cldfzenodo-2.2.2/src/cldfzenodo/search.py +0 -8
- cldfzenodo-2.2.2/tests/test_cli.py +0 -19
- cldfzenodo-2.2.2/tests/test_legacy.py +0 -35
- {cldfzenodo-2.2.2 → cldfzenodo-3.0.0}/LICENSE +0 -0
- {cldfzenodo-2.2.2 → cldfzenodo-3.0.0}/MANIFEST.in +0 -0
- {cldfzenodo-2.2.2 → cldfzenodo-3.0.0}/README.md +0 -0
- {cldfzenodo-2.2.2 → cldfzenodo-3.0.0}/pyproject.toml +0 -0
- {cldfzenodo-2.2.2 → cldfzenodo-3.0.0}/setup.py +0 -0
- {cldfzenodo-2.2.2 → cldfzenodo-3.0.0}/src/cldfzenodo/commands/__init__.py +0 -0
- {cldfzenodo-2.2.2 → cldfzenodo-3.0.0}/src/cldfzenodo.egg-info/dependency_links.txt +0 -0
- {cldfzenodo-2.2.2 → cldfzenodo-3.0.0}/src/cldfzenodo.egg-info/entry_points.txt +0 -0
- {cldfzenodo-2.2.2 → cldfzenodo-3.0.0}/src/cldfzenodo.egg-info/not-zip-safe +0 -0
- {cldfzenodo-2.2.2 → cldfzenodo-3.0.0}/src/cldfzenodo.egg-info/top_level.txt +0 -0
- {cldfzenodo-2.2.2 → cldfzenodo-3.0.0}/tests/test_api.py +0 -0
- {cldfzenodo-2.2.2 → cldfzenodo-3.0.0}/tests/test_integration.py +0 -0
- {cldfzenodo-2.2.2 → cldfzenodo-3.0.0}/tests/test_record.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: cldfzenodo
|
|
3
|
-
Version:
|
|
3
|
+
Version: 3.0.0
|
|
4
4
|
Summary: Functionality to retrieve CLDF datasets deposited on Zenodo
|
|
5
5
|
Home-page: https://github.com/cldf/cldfzenodo
|
|
6
6
|
Author: Robert Forkel
|
|
@@ -15,7 +15,6 @@ Classifier: Intended Audience :: Science/Research
|
|
|
15
15
|
Classifier: Natural Language :: English
|
|
16
16
|
Classifier: Operating System :: OS Independent
|
|
17
17
|
Classifier: Programming Language :: Python :: 3
|
|
18
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
19
18
|
Classifier: Programming Language :: Python :: 3.9
|
|
20
19
|
Classifier: Programming Language :: Python :: 3.10
|
|
21
20
|
Classifier: Programming Language :: Python :: 3.11
|
|
@@ -25,22 +24,20 @@ Classifier: Programming Language :: Python :: 3.14
|
|
|
25
24
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
26
25
|
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
27
26
|
Classifier: License :: OSI Approved :: Apache Software License
|
|
28
|
-
Requires-Python: >=3.
|
|
27
|
+
Requires-Python: >=3.9
|
|
29
28
|
Description-Content-Type: text/markdown
|
|
30
29
|
License-File: LICENSE
|
|
31
|
-
Requires-Dist: clldutils
|
|
32
|
-
Requires-Dist: pycldf
|
|
30
|
+
Requires-Dist: clldutils>=4.0.0
|
|
31
|
+
Requires-Dist: pycldf>=2.0.0
|
|
33
32
|
Requires-Dist: nameparser
|
|
34
|
-
Requires-Dist: attrs
|
|
35
33
|
Provides-Extra: cli
|
|
36
|
-
Requires-Dist: cldfbench
|
|
34
|
+
Requires-Dist: cldfbench>=2.0.0; extra == "cli"
|
|
37
35
|
Provides-Extra: dev
|
|
38
36
|
Requires-Dist: flake8; extra == "dev"
|
|
39
37
|
Requires-Dist: wheel; extra == "dev"
|
|
40
38
|
Requires-Dist: build; extra == "dev"
|
|
41
39
|
Requires-Dist: twine; extra == "dev"
|
|
42
40
|
Provides-Extra: test
|
|
43
|
-
Requires-Dist: cldfbench; extra == "test"
|
|
44
41
|
Requires-Dist: pytest>=5; extra == "test"
|
|
45
42
|
Requires-Dist: pytest-mock; extra == "test"
|
|
46
43
|
Requires-Dist: pytest-cov; extra == "test"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[metadata]
|
|
2
2
|
name = cldfzenodo
|
|
3
|
-
version =
|
|
3
|
+
version = 3.0.0
|
|
4
4
|
author = Robert Forkel
|
|
5
5
|
author_email = dlce.rdm@eva.mpg.de
|
|
6
6
|
description = Functionality to retrieve CLDF datasets deposited on Zenodo
|
|
@@ -20,7 +20,6 @@ classifiers =
|
|
|
20
20
|
Natural Language :: English
|
|
21
21
|
Operating System :: OS Independent
|
|
22
22
|
Programming Language :: Python :: 3
|
|
23
|
-
Programming Language :: Python :: 3.8
|
|
24
23
|
Programming Language :: Python :: 3.9
|
|
25
24
|
Programming Language :: Python :: 3.10
|
|
26
25
|
Programming Language :: Python :: 3.11
|
|
@@ -36,12 +35,11 @@ zip_safe = False
|
|
|
36
35
|
packages = find:
|
|
37
36
|
package_dir =
|
|
38
37
|
= src
|
|
39
|
-
python_requires = >=3.
|
|
38
|
+
python_requires = >=3.9
|
|
40
39
|
install_requires =
|
|
41
|
-
clldutils
|
|
42
|
-
pycldf
|
|
40
|
+
clldutils>=4.0.0
|
|
41
|
+
pycldf>=2.0.0
|
|
43
42
|
nameparser
|
|
44
|
-
attrs
|
|
45
43
|
|
|
46
44
|
[options.packages.find]
|
|
47
45
|
where = src
|
|
@@ -54,14 +52,13 @@ pycldf_dataset_resolver =
|
|
|
54
52
|
|
|
55
53
|
[options.extras_require]
|
|
56
54
|
cli =
|
|
57
|
-
cldfbench
|
|
55
|
+
cldfbench>=2.0.0
|
|
58
56
|
dev =
|
|
59
57
|
flake8
|
|
60
58
|
wheel
|
|
61
59
|
build
|
|
62
60
|
twine
|
|
63
61
|
test =
|
|
64
|
-
cldfbench
|
|
65
62
|
pytest>=5
|
|
66
63
|
pytest-mock
|
|
67
64
|
pytest-cov
|
|
@@ -95,7 +92,7 @@ show_missing = true
|
|
|
95
92
|
skip_covered = true
|
|
96
93
|
|
|
97
94
|
[tox:tox]
|
|
98
|
-
envlist =
|
|
95
|
+
envlist = py39, py310, py311, py312, py313, py314
|
|
99
96
|
isolated_build = true
|
|
100
97
|
skip_missing_interpreter = true
|
|
101
98
|
|
|
@@ -1,11 +1,16 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This module provides an API to retrieve CLDF datasets deposited on Zenodo.
|
|
3
|
+
"""
|
|
1
4
|
import re
|
|
2
5
|
import json
|
|
3
6
|
import shlex
|
|
4
|
-
import
|
|
7
|
+
from typing import Optional, Union
|
|
8
|
+
import pathlib
|
|
5
9
|
import subprocess
|
|
6
10
|
import urllib.error
|
|
7
11
|
import urllib.parse
|
|
8
12
|
import urllib.request
|
|
13
|
+
from collections.abc import Generator
|
|
9
14
|
|
|
10
15
|
from pycldf import Source
|
|
11
16
|
from pycldf.ext.discovery import DatasetResolver
|
|
@@ -13,13 +18,14 @@ from clldutils.path import ensure_cmd
|
|
|
13
18
|
|
|
14
19
|
from cldfzenodo.record import Record, ZENODO_DOI_FORMAT, ZENODO_DOI_PATTERN, get_doi
|
|
15
20
|
|
|
16
|
-
__all__ = [
|
|
21
|
+
__all__ = ["API", "Api", "ZenodoResolver"]
|
|
17
22
|
|
|
18
23
|
|
|
19
|
-
def get_hits(res:
|
|
24
|
+
def get_hits(res: Union[str, dict, list]) -> list[dict]:
|
|
25
|
+
"""Extract the hits from a search result."""
|
|
20
26
|
if isinstance(res, str):
|
|
21
27
|
res = json.loads(res)
|
|
22
|
-
return res if isinstance(res, list) else res[
|
|
28
|
+
return res if isinstance(res, list) else res["hits"]["hits"]
|
|
23
29
|
|
|
24
30
|
|
|
25
31
|
def q(**kw) -> str:
|
|
@@ -28,18 +34,22 @@ def q(**kw) -> str:
|
|
|
28
34
|
|
|
29
35
|
See https://help.zenodo.org/guides/search/ for details.
|
|
30
36
|
"""
|
|
31
|
-
res = kw.pop(
|
|
37
|
+
res = kw.pop("_q", "") or ""
|
|
32
38
|
if kw:
|
|
33
|
-
res +=
|
|
39
|
+
res += "" + " ".join(f'{k}:"{v}"' for k, v in kw.items())
|
|
34
40
|
return res.strip()
|
|
35
41
|
|
|
36
42
|
|
|
37
|
-
class Results:
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
+
class Results: # pylint: disable=R0903
|
|
44
|
+
"""Object to step through Zenodo search results."""
|
|
45
|
+
|
|
46
|
+
def __init__(
|
|
47
|
+
self,
|
|
48
|
+
api: "Api",
|
|
49
|
+
allversions: Optional[bool] = False,
|
|
50
|
+
community: Optional[str] = None,
|
|
51
|
+
**params: str,
|
|
52
|
+
):
|
|
43
53
|
"""
|
|
44
54
|
:param params: URL parameters (see https://developers.zenodo.org/#records)
|
|
45
55
|
"""
|
|
@@ -47,23 +57,24 @@ class Results:
|
|
|
47
57
|
self.params = params
|
|
48
58
|
self.community = community
|
|
49
59
|
if allversions:
|
|
50
|
-
self.params[
|
|
60
|
+
self.params["allversions"] = "true"
|
|
51
61
|
self._page = 0
|
|
52
62
|
self.more = True
|
|
53
63
|
self.error = None
|
|
54
64
|
|
|
55
|
-
def next(self) ->
|
|
65
|
+
def next(self) -> list[Record]:
|
|
66
|
+
"""Return the next batch, i.e. page, of search results."""
|
|
56
67
|
self._page += 1
|
|
57
68
|
params = {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
69
|
+
"sort": "-mostrecent",
|
|
70
|
+
"page": str(self._page),
|
|
71
|
+
"size": str(self.api.page_size),
|
|
72
|
+
}
|
|
61
73
|
params.update(self.params)
|
|
62
74
|
try:
|
|
63
75
|
hits = get_hits(self.api.records(community=self.community, params=params))
|
|
64
76
|
except urllib.error.HTTPError as e: # pragma: no cover
|
|
65
77
|
# We want to be able to resume retrieval of results.
|
|
66
|
-
hits = []
|
|
67
78
|
self.error = e
|
|
68
79
|
self._page -= 1
|
|
69
80
|
raise
|
|
@@ -72,18 +83,22 @@ class Results:
|
|
|
72
83
|
|
|
73
84
|
|
|
74
85
|
class Api:
|
|
86
|
+
"""An API to search Zenodo."""
|
|
87
|
+
|
|
75
88
|
__base_url__ = "https://zenodo.org/api/"
|
|
76
89
|
__communities__ = {} # We cash community identifiers.
|
|
77
90
|
|
|
78
|
-
def __init__(self, page_size=25):
|
|
91
|
+
def __init__(self, page_size: int = 25):
|
|
79
92
|
self.page_size = page_size
|
|
80
93
|
|
|
81
|
-
def __call__(
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
94
|
+
def __call__(
|
|
95
|
+
self,
|
|
96
|
+
what: str,
|
|
97
|
+
id_: Optional[str] = None,
|
|
98
|
+
params: Optional[dict[str, str]] = None,
|
|
99
|
+
headers: Optional[dict[str, str]] = None,
|
|
100
|
+
_verbose: bool = False,
|
|
101
|
+
) -> str:
|
|
87
102
|
"""
|
|
88
103
|
Perform an API call and return the response body as str.
|
|
89
104
|
|
|
@@ -97,20 +112,25 @@ class Api:
|
|
|
97
112
|
params = params or {}
|
|
98
113
|
headers = headers or {}
|
|
99
114
|
comps = urllib.parse.urlparse(
|
|
100
|
-
self.__base_url__ +
|
|
101
|
-
|
|
115
|
+
self.__base_url__ + f"{what}{'/' + id_ if id_ else ''}"
|
|
116
|
+
)
|
|
117
|
+
url = urllib.parse.urlunparse(
|
|
118
|
+
list(comps[:3]) + ["", urllib.parse.urlencode(params), ""]
|
|
119
|
+
)
|
|
102
120
|
req = urllib.request.Request(url)
|
|
103
121
|
for k, v in headers.items():
|
|
104
122
|
req.add_header(k, v)
|
|
105
123
|
if _verbose: # pragma: no cover
|
|
106
124
|
print(url)
|
|
107
|
-
return urllib.request.urlopen(req).read().decode(
|
|
108
|
-
|
|
109
|
-
def records(
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
125
|
+
return urllib.request.urlopen(req).read().decode("utf8")
|
|
126
|
+
|
|
127
|
+
def records(
|
|
128
|
+
self,
|
|
129
|
+
id_: Optional[str] = None,
|
|
130
|
+
community: Optional[str] = None,
|
|
131
|
+
params: Optional[dict[str, str]] = None,
|
|
132
|
+
headers: Optional[dict[str, str]] = None,
|
|
133
|
+
) -> str:
|
|
114
134
|
"""
|
|
115
135
|
Perfom an API call to the records resource (possibly limited to one community).
|
|
116
136
|
|
|
@@ -121,31 +141,35 @@ class Api:
|
|
|
121
141
|
:param headers: HTTP request headers.
|
|
122
142
|
:return: Body of the response as text.
|
|
123
143
|
"""
|
|
124
|
-
what =
|
|
144
|
+
what = ""
|
|
125
145
|
if community:
|
|
126
146
|
if community not in self.__communities__:
|
|
127
147
|
self.__communities__[community] = json.loads(
|
|
128
|
-
self(
|
|
129
|
-
|
|
130
|
-
|
|
148
|
+
self("communities", community)
|
|
149
|
+
)["id"]
|
|
150
|
+
what = f"communities/{self.__communities__[community]}/"
|
|
151
|
+
what += "records"
|
|
131
152
|
return self(what, id_=id_, params=params, headers=headers)
|
|
132
153
|
|
|
133
|
-
def iter_versions(self, conceptdoi: str) ->
|
|
154
|
+
def iter_versions(self, conceptdoi: str) -> Generator[Record, None, None]:
|
|
134
155
|
"""
|
|
135
156
|
Retrieve all versions recorded for a concept DOI.
|
|
136
157
|
"""
|
|
137
158
|
yield from self.iter_records(conceptdoi=get_doi(conceptdoi), allversions=True)
|
|
138
159
|
|
|
139
160
|
@staticmethod
|
|
140
|
-
def _first_record(res):
|
|
161
|
+
def _first_record(res) -> Optional[Record]:
|
|
141
162
|
hits = get_hits(res)
|
|
142
163
|
if hits:
|
|
143
164
|
return Record.from_dict(hits[0])
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
165
|
+
return None # pragma: no cover
|
|
166
|
+
|
|
167
|
+
def get_record(
|
|
168
|
+
self,
|
|
169
|
+
doi: Optional[str] = None,
|
|
170
|
+
conceptdoi: Optional[str] = None,
|
|
171
|
+
version: Optional[str] = None,
|
|
172
|
+
) -> Optional[Record]:
|
|
149
173
|
"""
|
|
150
174
|
Retrieve a record specified by Zenodo DOI, given as URL or plain.
|
|
151
175
|
|
|
@@ -159,21 +183,27 @@ class Api:
|
|
|
159
183
|
if doi:
|
|
160
184
|
doi = get_doi(doi)
|
|
161
185
|
assert not conceptdoi
|
|
162
|
-
return self._first_record(
|
|
186
|
+
return self._first_record(
|
|
187
|
+
self.records(params={"allversions": "true", "q": q(doi=doi)})
|
|
188
|
+
)
|
|
163
189
|
assert conceptdoi
|
|
164
190
|
conceptdoi = get_doi(conceptdoi)
|
|
165
191
|
if not version:
|
|
166
|
-
return self._first_record(
|
|
192
|
+
return self._first_record(
|
|
193
|
+
self.records(params={"q": q(conceptdoi=conceptdoi)})
|
|
194
|
+
)
|
|
167
195
|
for rec in self.iter_records(conceptdoi=conceptdoi, allversions=True):
|
|
168
|
-
if rec.version.lstrip(
|
|
196
|
+
if rec.version.lstrip("v") == version.lstrip("v"):
|
|
169
197
|
return rec
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
198
|
+
return None
|
|
199
|
+
|
|
200
|
+
def iter_records(
|
|
201
|
+
self,
|
|
202
|
+
community: Optional[str] = None,
|
|
203
|
+
keyword: Optional[str] = None,
|
|
204
|
+
allversions: Optional[bool] = False,
|
|
205
|
+
**kw,
|
|
206
|
+
) -> Generator[Record, None, Optional[Results]]:
|
|
177
207
|
"""
|
|
178
208
|
Retrieve records matching various search criteria.
|
|
179
209
|
|
|
@@ -185,25 +215,18 @@ class Api:
|
|
|
185
215
|
:return: A generator of records.
|
|
186
216
|
"""
|
|
187
217
|
if keyword:
|
|
188
|
-
kw[
|
|
218
|
+
kw["keywords"] = keyword
|
|
189
219
|
res = Results(self, allversions=allversions, community=community, q=q(**kw))
|
|
190
220
|
yield from res.next()
|
|
191
221
|
while res.more:
|
|
192
222
|
yield from res.next() # pragma: no cover
|
|
193
223
|
if res.error:
|
|
194
224
|
return res # pragma: no cover
|
|
225
|
+
return None
|
|
195
226
|
|
|
196
227
|
def get_github_release_info(
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
tag: typing.Optional[str] = None,
|
|
200
|
-
bibid: typing.Optional[str] = None
|
|
201
|
-
) -> typing.Tuple[
|
|
202
|
-
typing.Union[str, None],
|
|
203
|
-
typing.Union[str, None],
|
|
204
|
-
typing.Union[str, None],
|
|
205
|
-
typing.Union[Source, None]
|
|
206
|
-
]:
|
|
228
|
+
self, repos: str, tag: Optional[str] = None, bibid: Optional[str] = None
|
|
229
|
+
) -> tuple[Optional[str], Optional[str], Optional[str], Optional[Source]]:
|
|
207
230
|
"""
|
|
208
231
|
Get information about a GitHub repository release that has been archived with Zenodo.
|
|
209
232
|
|
|
@@ -215,45 +238,54 @@ class Api:
|
|
|
215
238
|
:param bibid: Optional identifier to use for the BibTeX record.
|
|
216
239
|
:return: A quadruple (tag, DOI, APA citation, BibTeX record)
|
|
217
240
|
"""
|
|
241
|
+
|
|
218
242
|
def gh(args):
|
|
219
|
-
return subprocess.check_output(
|
|
243
|
+
return subprocess.check_output(
|
|
244
|
+
[ensure_cmd("gh")] + shlex.split(args)
|
|
245
|
+
).decode("utf8")
|
|
220
246
|
|
|
221
|
-
version_pattern = re.compile(r
|
|
222
|
-
doi_pattern = re.compile(r
|
|
247
|
+
version_pattern = re.compile(r"(?P<tag>v[0-9]+\.[0-9]+(\.[0-9]+)?)")
|
|
248
|
+
doi_pattern = re.compile(r"https://doi\.org/(?P<doi>10\.5281/zenodo\.[0-9]+)")
|
|
223
249
|
|
|
224
250
|
if not tag:
|
|
225
|
-
latest = gh(
|
|
251
|
+
latest = gh(f"release list -L 1 -R {repos}")
|
|
226
252
|
if not latest:
|
|
227
253
|
return None, None, None, None # pragma: no cover
|
|
228
254
|
match = version_pattern.search(latest)
|
|
229
255
|
assert match, latest
|
|
230
|
-
tag = match.group(
|
|
256
|
+
tag = match.group("tag")
|
|
231
257
|
|
|
232
|
-
info = gh(
|
|
258
|
+
info = gh(f"release view {tag} -R {repos}")
|
|
233
259
|
match = None
|
|
234
260
|
for match in doi_pattern.finditer(info):
|
|
235
261
|
pass
|
|
236
262
|
if match:
|
|
237
|
-
doi = match.group(
|
|
263
|
+
doi = match.group("doi")
|
|
238
264
|
if doi:
|
|
239
265
|
cit = self.records(
|
|
240
|
-
id_=ZENODO_DOI_PATTERN.match(doi).group(
|
|
241
|
-
params=
|
|
242
|
-
headers=
|
|
266
|
+
id_=ZENODO_DOI_PATTERN.match(doi).group("recid"),
|
|
267
|
+
params={"style": "apa"},
|
|
268
|
+
headers={"Accept": "text/x-bibliography"},
|
|
269
|
+
).strip()
|
|
243
270
|
bib = self.records(
|
|
244
|
-
id_=ZENODO_DOI_PATTERN.match(doi).group(
|
|
245
|
-
params=
|
|
246
|
-
headers=
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
271
|
+
id_=ZENODO_DOI_PATTERN.match(doi).group("recid"),
|
|
272
|
+
params={"style": "bibtex"},
|
|
273
|
+
headers={"Accept": "text/x-bibliography"},
|
|
274
|
+
).strip()
|
|
275
|
+
bib = Source.from_bibtex(
|
|
276
|
+
re.sub(
|
|
277
|
+
r", (?P<field>[a-zA-Z]+)=",
|
|
278
|
+
lambda m: f",\n {m.group('field')} = ",
|
|
279
|
+
bib,
|
|
280
|
+
),
|
|
281
|
+
_check_id=False,
|
|
282
|
+
)
|
|
283
|
+
bib.id = bibid or repos.replace("/", "_")
|
|
284
|
+
for field in ["abstractNote", "month"]:
|
|
253
285
|
if field in bib:
|
|
254
286
|
del bib[field]
|
|
255
|
-
bib[
|
|
256
|
-
bib[
|
|
287
|
+
bib["edition"] = tag
|
|
288
|
+
bib["type"] = "Data set"
|
|
257
289
|
return tag, doi, cit, bib
|
|
258
290
|
return tag, None, None, None # pragma: no cover
|
|
259
291
|
|
|
@@ -262,16 +294,19 @@ class Api:
|
|
|
262
294
|
API = Api()
|
|
263
295
|
|
|
264
296
|
|
|
265
|
-
class ZenodoResolver(DatasetResolver):
|
|
266
|
-
|
|
297
|
+
class ZenodoResolver(DatasetResolver): # pylint: disable=R0903
|
|
298
|
+
"""Resolve location and download CLDF datasets deposited on Zenodo."""
|
|
299
|
+
|
|
300
|
+
def __call__(self, loc, download_dir) -> Optional[pathlib.Path]:
|
|
267
301
|
doi = None
|
|
268
302
|
m = ZENODO_DOI_PATTERN.search(loc)
|
|
269
303
|
if m:
|
|
270
|
-
doi = loc[m.start():m.end()]
|
|
304
|
+
doi = loc[m.start() : m.end()] # noqa: E203
|
|
271
305
|
else:
|
|
272
|
-
m = re.search(r
|
|
306
|
+
m = re.search(r"zenodo\.org/record(s)?/(?P<number>[0-9]+)", loc)
|
|
273
307
|
if m:
|
|
274
|
-
doi = ZENODO_DOI_FORMAT.format(m.group(
|
|
308
|
+
doi = ZENODO_DOI_FORMAT.format(m.group("number"))
|
|
275
309
|
if doi:
|
|
276
310
|
rec = API.get_record(doi=doi) or API.get_record(conceptdoi=doi)
|
|
277
311
|
return rec.download(download_dir)
|
|
312
|
+
return None # pragma: no cover
|
|
@@ -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
|