PyLinks 0.0.0.dev40__tar.gz → 0.0.0.dev42__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.
- {pylinks-0.0.0.dev40 → pylinks-0.0.0.dev42}/PKG-INFO +3 -3
- {pylinks-0.0.0.dev40 → pylinks-0.0.0.dev42}/pyproject.toml +3 -3
- {pylinks-0.0.0.dev40 → pylinks-0.0.0.dev42}/src/PyLinks.egg-info/PKG-INFO +3 -3
- {pylinks-0.0.0.dev40 → pylinks-0.0.0.dev42}/src/PyLinks.egg-info/SOURCES.txt +1 -0
- pylinks-0.0.0.dev42/src/PyLinks.egg-info/requires.txt +3 -0
- {pylinks-0.0.0.dev40 → pylinks-0.0.0.dev42}/src/pylinks/api/__init__.py +5 -0
- {pylinks-0.0.0.dev40 → pylinks-0.0.0.dev42}/src/pylinks/api/github.py +7 -0
- pylinks-0.0.0.dev42/src/pylinks/api/zenodo.py +147 -0
- {pylinks-0.0.0.dev40 → pylinks-0.0.0.dev42}/src/pylinks/media_type.py +4 -0
- pylinks-0.0.0.dev40/src/PyLinks.egg-info/requires.txt +0 -3
- {pylinks-0.0.0.dev40 → pylinks-0.0.0.dev42}/README.md +0 -0
- {pylinks-0.0.0.dev40 → pylinks-0.0.0.dev42}/setup.cfg +0 -0
- {pylinks-0.0.0.dev40 → pylinks-0.0.0.dev42}/src/PyLinks.egg-info/dependency_links.txt +0 -0
- {pylinks-0.0.0.dev40 → pylinks-0.0.0.dev42}/src/PyLinks.egg-info/not-zip-safe +0 -0
- {pylinks-0.0.0.dev40 → pylinks-0.0.0.dev42}/src/PyLinks.egg-info/top_level.txt +0 -0
- {pylinks-0.0.0.dev40 → pylinks-0.0.0.dev42}/src/pylinks/__init__.py +0 -0
- {pylinks-0.0.0.dev40 → pylinks-0.0.0.dev42}/src/pylinks/_settings.py +0 -0
- {pylinks-0.0.0.dev40 → pylinks-0.0.0.dev42}/src/pylinks/api/doi.py +0 -0
- {pylinks-0.0.0.dev40 → pylinks-0.0.0.dev42}/src/pylinks/api/orcid.py +0 -0
- {pylinks-0.0.0.dev40 → pylinks-0.0.0.dev42}/src/pylinks/exception/__init__.py +0 -0
- {pylinks-0.0.0.dev40 → pylinks-0.0.0.dev42}/src/pylinks/exception/api.py +0 -0
- {pylinks-0.0.0.dev40 → pylinks-0.0.0.dev42}/src/pylinks/exception/base.py +0 -0
- {pylinks-0.0.0.dev40 → pylinks-0.0.0.dev42}/src/pylinks/exception/media_type.py +0 -0
- {pylinks-0.0.0.dev40 → pylinks-0.0.0.dev42}/src/pylinks/exception/uri.py +0 -0
- {pylinks-0.0.0.dev40 → pylinks-0.0.0.dev42}/src/pylinks/http.py +0 -0
- {pylinks-0.0.0.dev40 → pylinks-0.0.0.dev42}/src/pylinks/site/__init__.py +0 -0
- {pylinks-0.0.0.dev40 → pylinks-0.0.0.dev42}/src/pylinks/site/binder.py +0 -0
- {pylinks-0.0.0.dev40 → pylinks-0.0.0.dev42}/src/pylinks/site/conda.py +0 -0
- {pylinks-0.0.0.dev40 → pylinks-0.0.0.dev42}/src/pylinks/site/github.py +0 -0
- {pylinks-0.0.0.dev40 → pylinks-0.0.0.dev42}/src/pylinks/site/lib_io.py +0 -0
- {pylinks-0.0.0.dev40 → pylinks-0.0.0.dev42}/src/pylinks/site/pypi.py +0 -0
- {pylinks-0.0.0.dev40 → pylinks-0.0.0.dev42}/src/pylinks/site/readthedocs.py +0 -0
- {pylinks-0.0.0.dev40 → pylinks-0.0.0.dev42}/src/pylinks/string.py +0 -0
- {pylinks-0.0.0.dev40 → pylinks-0.0.0.dev42}/src/pylinks/uri/__init__.py +0 -0
- {pylinks-0.0.0.dev40 → pylinks-0.0.0.dev42}/src/pylinks/uri/data.py +0 -0
- {pylinks-0.0.0.dev40 → pylinks-0.0.0.dev42}/src/pylinks/url.py +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: PyLinks
|
|
3
|
-
Version: 0.0.0.
|
|
3
|
+
Version: 0.0.0.dev42
|
|
4
4
|
Requires-Python: >=3.10
|
|
5
5
|
Requires-Dist: requests<3,>=2.31.0
|
|
6
|
-
Requires-Dist: ExceptionMan==0.0.0.
|
|
7
|
-
Requires-Dist: MDit==0.0.0.
|
|
6
|
+
Requires-Dist: ExceptionMan==0.0.0.dev29
|
|
7
|
+
Requires-Dist: MDit==0.0.0.dev29
|
|
@@ -17,12 +17,12 @@ namespaces = true
|
|
|
17
17
|
# ----------------------------------------- Project Metadata -------------------------------------
|
|
18
18
|
#
|
|
19
19
|
[project]
|
|
20
|
-
version = "0.0.0.
|
|
20
|
+
version = "0.0.0.dev42"
|
|
21
21
|
name = "PyLinks"
|
|
22
22
|
dependencies = [
|
|
23
23
|
"requests >= 2.31.0, < 3",
|
|
24
|
-
"ExceptionMan == 0.0.0.
|
|
25
|
-
"MDit == 0.0.0.
|
|
24
|
+
"ExceptionMan == 0.0.0.dev29",
|
|
25
|
+
"MDit == 0.0.0.dev29",
|
|
26
26
|
]
|
|
27
27
|
requires-python = ">=3.10"
|
|
28
28
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: PyLinks
|
|
3
|
-
Version: 0.0.0.
|
|
3
|
+
Version: 0.0.0.dev42
|
|
4
4
|
Requires-Python: >=3.10
|
|
5
5
|
Requires-Dist: requests<3,>=2.31.0
|
|
6
|
-
Requires-Dist: ExceptionMan==0.0.0.
|
|
7
|
-
Requires-Dist: MDit==0.0.0.
|
|
6
|
+
Requires-Dist: ExceptionMan==0.0.0.dev29
|
|
7
|
+
Requires-Dist: MDit==0.0.0.dev29
|
|
@@ -3,6 +3,7 @@ from typing import Optional
|
|
|
3
3
|
from pylinks.api.doi import DOI
|
|
4
4
|
from pylinks.api.github import GitHub
|
|
5
5
|
from pylinks.api.orcid import Orcid
|
|
6
|
+
from pylinks.api.zenodo import Zenodo
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
def doi(doi: str) -> DOI:
|
|
@@ -15,3 +16,7 @@ def github(token: Optional[str] = None) -> GitHub:
|
|
|
15
16
|
|
|
16
17
|
def orcid(orcid_id: str) -> Orcid:
|
|
17
18
|
return Orcid(orcid_id=orcid_id)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def zenodo(token: str, sandbox: bool = False) -> Zenodo:
|
|
22
|
+
return Zenodo(token=token, sandbox=sandbox)
|
|
@@ -9,6 +9,13 @@ import pylinks as _pylinks
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
class GitHub:
|
|
12
|
+
"""GitHub API
|
|
13
|
+
|
|
14
|
+
References
|
|
15
|
+
----------
|
|
16
|
+
- [OpenAPI Description](https://github.com/github/rest-api-description)
|
|
17
|
+
- [GraphQL API Documentation](https://docs.github.com/en/graphql)
|
|
18
|
+
"""
|
|
12
19
|
|
|
13
20
|
def __init__(self, token: Optional[str] = None):
|
|
14
21
|
self._endpoint = {
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
from __future__ import annotations as _annotations
|
|
2
|
+
|
|
3
|
+
from typing import TYPE_CHECKING as _TYPE_CHECKING
|
|
4
|
+
from pathlib import Path as _Path
|
|
5
|
+
import pylinks as _pylinks
|
|
6
|
+
|
|
7
|
+
if _TYPE_CHECKING:
|
|
8
|
+
from typing import Literal
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class Zenodo:
|
|
12
|
+
"""Zenodo API.
|
|
13
|
+
|
|
14
|
+
References
|
|
15
|
+
----------
|
|
16
|
+
- [API Manual](https://developers.zenodo.org/)
|
|
17
|
+
- [Main Repository](https://github.com/zenodo/zenodo)
|
|
18
|
+
"""
|
|
19
|
+
def __init__(self, token: str, sandbox: bool = False):
|
|
20
|
+
self._sandbox = sandbox
|
|
21
|
+
self._url = _pylinks.url.create("https://zenodo.org/api")
|
|
22
|
+
self._url_sandbox = _pylinks.url.create("https://sandbox.zenodo.org/api")
|
|
23
|
+
self._headers = {"Authorization": token}
|
|
24
|
+
return
|
|
25
|
+
|
|
26
|
+
def rest_query(
|
|
27
|
+
self,
|
|
28
|
+
query: str,
|
|
29
|
+
verb: Literal["GET", "POST", "PUT", "PATCH", "OPTIONS", "DELETE"] = "GET",
|
|
30
|
+
data = None,
|
|
31
|
+
json = None,
|
|
32
|
+
content_type: str | None = "application/json",
|
|
33
|
+
sandbox: bool | None = None,
|
|
34
|
+
) -> dict | list:
|
|
35
|
+
sandbox = sandbox if sandbox is not None else self._sandbox
|
|
36
|
+
base_url = self._url_sandbox if sandbox else self._url
|
|
37
|
+
content_header = {"Content-Type": content_type} if content_type else {}
|
|
38
|
+
return _pylinks.http.request(
|
|
39
|
+
url=base_url / query,
|
|
40
|
+
verb=verb,
|
|
41
|
+
data=data,
|
|
42
|
+
json=json,
|
|
43
|
+
headers=self._headers | content_header,
|
|
44
|
+
response_type="json", # All responses are JSON (https://developers.zenodo.org/#responses)
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
def deposition_create(
|
|
48
|
+
self,
|
|
49
|
+
metadata: dict | None = None,
|
|
50
|
+
sandbox: bool | None = None,
|
|
51
|
+
) -> dict:
|
|
52
|
+
"""Create a new deposition.
|
|
53
|
+
|
|
54
|
+
Returns
|
|
55
|
+
-------
|
|
56
|
+
|
|
57
|
+
Example response:
|
|
58
|
+
:::{code-block} json
|
|
59
|
+
|
|
60
|
+
{
|
|
61
|
+
"conceptrecid": "542200",
|
|
62
|
+
"created": "2020-05-19T11:58:41.606998+00:00",
|
|
63
|
+
"files": [],
|
|
64
|
+
"id": 542201,
|
|
65
|
+
"links": {
|
|
66
|
+
"bucket": "https://zenodo.org/api/files/568377dd-daf8-4235-85e1-a56011ad454b",
|
|
67
|
+
"discard": "https://zenodo.org/api/deposit/depositions/542201/actions/discard",
|
|
68
|
+
"edit": "https://zenodo.org/api/deposit/depositions/542201/actions/edit",
|
|
69
|
+
"files": "https://zenodo.org/api/deposit/depositions/542201/files",
|
|
70
|
+
"html": "https://zenodo.org/deposit/542201",
|
|
71
|
+
"latest_draft": "https://zenodo.org/api/deposit/depositions/542201",
|
|
72
|
+
"latest_draft_html": "https://zenodo.org/deposit/542201",
|
|
73
|
+
"publish": "https://zenodo.org/api/deposit/depositions/542201/actions/publish",
|
|
74
|
+
"self": "https://zenodo.org/api/deposit/depositions/542201"
|
|
75
|
+
},
|
|
76
|
+
"metadata": {
|
|
77
|
+
"prereserve_doi": {
|
|
78
|
+
"doi": "10.5072/zenodo.542201",
|
|
79
|
+
"recid": 542201
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
"modified": "2020-05-19T11:58:41.607012+00:00",
|
|
83
|
+
"owner": 12345,
|
|
84
|
+
"record_id": 542201,
|
|
85
|
+
"state": "unsubmitted",
|
|
86
|
+
"submitted": false,
|
|
87
|
+
"title": ""
|
|
88
|
+
}
|
|
89
|
+
:::
|
|
90
|
+
"""
|
|
91
|
+
return self.rest_query(
|
|
92
|
+
query="deposit/depositions",
|
|
93
|
+
verb="POST",
|
|
94
|
+
json=metadata or {},
|
|
95
|
+
sandbox=sandbox,
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
def deposition_publish(self, deposition_id: str) -> dict:
|
|
99
|
+
"""Publish a deposition."""
|
|
100
|
+
return self.rest_query(
|
|
101
|
+
query=f"deposit/depositions/{deposition_id}/actions/publish",
|
|
102
|
+
verb="POST",
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
def file_create(
|
|
106
|
+
self,
|
|
107
|
+
bucket_url: str | _pylinks.url.URL,
|
|
108
|
+
filepath: str | _Path,
|
|
109
|
+
upload_path: str | None = None,
|
|
110
|
+
) -> dict:
|
|
111
|
+
"""Upload a file to a Zenodo bucket.
|
|
112
|
+
|
|
113
|
+
Returns
|
|
114
|
+
-------
|
|
115
|
+
|
|
116
|
+
Example response:
|
|
117
|
+
:::{code-block} json
|
|
118
|
+
|
|
119
|
+
{
|
|
120
|
+
"key": "my-file.zip",
|
|
121
|
+
"mimetype": "application/zip",
|
|
122
|
+
"checksum": "md5:2942bfabb3d05332b66eb128e0842cff",
|
|
123
|
+
"version_id": "38a724d3-40f1-4b27-b236-ed2e43200f85",
|
|
124
|
+
"size": 13264,
|
|
125
|
+
"created": "2020-02-26T14:20:53.805734+00:00",
|
|
126
|
+
"updated": "2020-02-26T14:20:53.811817+00:00",
|
|
127
|
+
"links": {
|
|
128
|
+
"self": "https://zenodo.org/api/files/44cc40bc-50fd-4107-b347-00838c79f4c1/dummy_example.pdf",
|
|
129
|
+
"version": "https://zenodo.org/api/files/44cc40bc-50fd-4107-b347-00838c79f4c1/dummy_example.pdf?versionId=38a724d3-40f1-4b27-b236-ed2e43200f85",
|
|
130
|
+
"uploads": "https://zenodo.org/api/files/44cc40bc-50fd-4107-b347-00838c79f4c1/dummy_example.pdf?uploads"
|
|
131
|
+
},
|
|
132
|
+
"is_head": true,
|
|
133
|
+
"delete_marker": false
|
|
134
|
+
}
|
|
135
|
+
:::
|
|
136
|
+
"""
|
|
137
|
+
if not isinstance(bucket_url, _pylinks.url.URL):
|
|
138
|
+
bucket_url = _pylinks.url.create(bucket_url)
|
|
139
|
+
filepath = _Path(filepath)
|
|
140
|
+
upload_path = upload_path or filepath.name
|
|
141
|
+
with open(filepath, "rb") as file:
|
|
142
|
+
return self.rest_query(
|
|
143
|
+
query=bucket_url / upload_path,
|
|
144
|
+
verb="PUT",
|
|
145
|
+
data=file,
|
|
146
|
+
content_type=None,
|
|
147
|
+
)
|
|
@@ -109,3 +109,7 @@ def guess_from_uri(uri: str) -> MediaType:
|
|
|
109
109
|
if mimetype is None:
|
|
110
110
|
raise _exception.media_type.PyLinksMediaTypeGuessError(uri)
|
|
111
111
|
return parse(mimetype)
|
|
112
|
+
|
|
113
|
+
# TODO: Add function to guess from file
|
|
114
|
+
# Refs:
|
|
115
|
+
# - https://pypi.org/project/python-magic/
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|