ohi-sdk 0.17.1__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.
- ohi_sdk-0.17.1/LICENSE +201 -0
- ohi_sdk-0.17.1/PKG-INFO +32 -0
- ohi_sdk-0.17.1/README.md +17 -0
- ohi_sdk-0.17.1/pyproject.toml +21 -0
- ohi_sdk-0.17.1/src/ohi/__init__.py +20 -0
- ohi_sdk-0.17.1/src/ohi/catalog-config.schema.json +35 -0
- ohi_sdk-0.17.1/src/ohi/catalog.py +175 -0
- ohi_sdk-0.17.1/src/ohi/generated.py +133 -0
- ohi_sdk-0.17.1/src/ohi/generated_config.py +35 -0
- ohi_sdk-0.17.1/src/ohi/generated_error.py +62 -0
- ohi_sdk-0.17.1/src/ohi/generated_lock.py +73 -0
- ohi_sdk-0.17.1/src/ohi/generated_lock_error.py +52 -0
- ohi_sdk-0.17.1/src/ohi/generated_search.py +133 -0
- ohi_sdk-0.17.1/src/ohi/generated_search_request.py +45 -0
- ohi_sdk-0.17.1/src/ohi/lock.py +142 -0
- ohi_sdk-0.17.1/src/ohi/lock.schema.json +111 -0
- ohi_sdk-0.17.1/src/ohi/package.schema.json +225 -0
- ohi_sdk-0.17.1/src/ohi/publication.py +39 -0
- ohi_sdk-0.17.1/src/ohi/search-request.schema.json +63 -0
- ohi_sdk-0.17.1/src/ohi/search.schema.json +203 -0
- ohi_sdk-0.17.1/tests/test_catalog.py +437 -0
- ohi_sdk-0.17.1/tests/test_lock.py +377 -0
- ohi_sdk-0.17.1/tests/test_publication.py +281 -0
ohi_sdk-0.17.1/LICENSE
ADDED
|
@@ -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 2026 NeverBlink sp. z o.o.
|
|
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.
|
ohi_sdk-0.17.1/PKG-INFO
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: ohi-sdk
|
|
3
|
+
Version: 0.17.1
|
|
4
|
+
Summary: Ohi catalog search, publication inspection and artifact retrieval.
|
|
5
|
+
Project-URL: Documentation, https://github.com/NeverBlink-OSS/linkml-scala/blob/main/ohi/README.md
|
|
6
|
+
Project-URL: Source, https://github.com/NeverBlink-OSS/linkml-scala
|
|
7
|
+
Project-URL: Issues, https://github.com/NeverBlink-OSS/linkml-scala/issues
|
|
8
|
+
Author: NeverBlink
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Requires-Python: >=3.10
|
|
12
|
+
Requires-Dist: jsonschema[format-nongpl]<5,>=4.26
|
|
13
|
+
Requires-Dist: pydantic<3,>=2.12
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
|
|
16
|
+
# Ohi SDK
|
|
17
|
+
|
|
18
|
+
The Ohi SDK lets Python and TypeScript applications search publications, inspect metadata, download selected files and save supplied file selections.
|
|
19
|
+
|
|
20
|
+
Install on Python 3.10 or later:
|
|
21
|
+
|
|
22
|
+
```sh
|
|
23
|
+
python -m pip install ohi-sdk
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Install for Node 22 or later, or a browser application:
|
|
27
|
+
|
|
28
|
+
```sh
|
|
29
|
+
npm install @neverblink/ohi
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
See the [SDK guide](https://github.com/NeverBlink-OSS/linkml-scala/blob/main/ohi/README.md) for usage, browser requirements and API behavior.
|
ohi_sdk-0.17.1/README.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Ohi SDK
|
|
2
|
+
|
|
3
|
+
The Ohi SDK lets Python and TypeScript applications search publications, inspect metadata, download selected files and save supplied file selections.
|
|
4
|
+
|
|
5
|
+
Install on Python 3.10 or later:
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
python -m pip install ohi-sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Install for Node 22 or later, or a browser application:
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npm install @neverblink/ohi
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
See the [SDK guide](https://github.com/NeverBlink-OSS/linkml-scala/blob/main/ohi/README.md) for usage, browser requirements and API behavior.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.27"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
readme = "README.md"
|
|
7
|
+
name = "ohi-sdk"
|
|
8
|
+
version = "0.17.1"
|
|
9
|
+
description = "Ohi catalog search, publication inspection and artifact retrieval."
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = "Apache-2.0"
|
|
12
|
+
authors = [{ name = "NeverBlink" }]
|
|
13
|
+
dependencies = ["pydantic>=2.12,<3", "jsonschema[format-nongpl]>=4.26,<5"]
|
|
14
|
+
|
|
15
|
+
[project.urls]
|
|
16
|
+
Documentation = "https://github.com/NeverBlink-OSS/linkml-scala/blob/main/ohi/README.md"
|
|
17
|
+
Source = "https://github.com/NeverBlink-OSS/linkml-scala"
|
|
18
|
+
Issues = "https://github.com/NeverBlink-OSS/linkml-scala/issues"
|
|
19
|
+
|
|
20
|
+
[tool.hatch.build.targets.wheel]
|
|
21
|
+
packages = ["src/ohi"]
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"""Ohi catalog operations, publication metadata and supplied file locks."""
|
|
2
|
+
|
|
3
|
+
from .catalog import CatalogClient, CatalogException
|
|
4
|
+
from .generated import Artifact, ArtifactOrigin, Dependency, Format, Publication
|
|
5
|
+
from .generated_config import CatalogConfig
|
|
6
|
+
from .generated_error import CatalogError, CatalogErrorCode, CatalogOperation
|
|
7
|
+
from .generated_lock import ArtifactSelection, Lock, LockedFile
|
|
8
|
+
from .generated_lock_error import LockError, LockErrorCode, LockOperation
|
|
9
|
+
from .generated_search import FacetCount, FacetValueCount, SearchHit, SearchResult
|
|
10
|
+
from .generated_search_request import SearchRequest
|
|
11
|
+
from .publication import decode_publication
|
|
12
|
+
from .lock import LockException, decode_lock, encode_lock, read_lock, write_lock
|
|
13
|
+
|
|
14
|
+
__all__ = [
|
|
15
|
+
"Artifact", "ArtifactOrigin", "ArtifactSelection", "CatalogClient", "CatalogConfig", "CatalogError",
|
|
16
|
+
"CatalogErrorCode", "CatalogException", "CatalogOperation", "Dependency", "FacetCount",
|
|
17
|
+
"FacetValueCount", "Format", "Lock", "LockedFile", "LockError", "LockErrorCode", "LockException",
|
|
18
|
+
"LockOperation", "Publication", "SearchHit", "SearchRequest", "SearchResult", "decode_publication",
|
|
19
|
+
"decode_lock", "encode_lock", "read_lock", "write_lock",
|
|
20
|
+
]
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://ohi.neverblink.eu/contracts/catalog-config",
|
|
4
|
+
"$ref": "#/$defs/CatalogConfig",
|
|
5
|
+
"$defs": {
|
|
6
|
+
"CatalogConfig": {
|
|
7
|
+
"title": "CatalogConfig",
|
|
8
|
+
"type": "object",
|
|
9
|
+
"properties": {
|
|
10
|
+
"search_url": {
|
|
11
|
+
"title": "search_url",
|
|
12
|
+
"description": "Complete HTTP search endpoint, including its collection path. Omit both search_url and query_by to use https://api.ohi.dev/search/collections/packages/documents/search. Supply both to select another catalog.",
|
|
13
|
+
"type": "string",
|
|
14
|
+
"format": "iri"
|
|
15
|
+
},
|
|
16
|
+
"query_by": {
|
|
17
|
+
"title": "query_by",
|
|
18
|
+
"description": "Comma-separated indexed fields used for text search. Omit both query_by and search_url to use title,name,description,namespace at ohi.dev. Supply both to select another catalog.",
|
|
19
|
+
"type": "string",
|
|
20
|
+
"pattern": "^[\\s\\S]*\\S"
|
|
21
|
+
},
|
|
22
|
+
"timeout_ms": {
|
|
23
|
+
"title": "timeout_ms",
|
|
24
|
+
"description": "Positive native request timeout in milliseconds. Omitted means 30000.",
|
|
25
|
+
"type": "integer",
|
|
26
|
+
"minimum": 1,
|
|
27
|
+
"maximum": 2147483647
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"additionalProperties": false
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"title": "Catalog connection settings",
|
|
34
|
+
"description": "Search endpoint and request timeout settings for a catalog client."
|
|
35
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
"""Retrieve one catalog page, publication or file through native HTTP."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from http.client import HTTPException
|
|
5
|
+
from importlib.resources import files
|
|
6
|
+
from urllib.error import HTTPError, URLError
|
|
7
|
+
from urllib.parse import urlencode, urlsplit
|
|
8
|
+
from urllib.request import HTTPRedirectHandler, Request, build_opener
|
|
9
|
+
|
|
10
|
+
from jsonschema import Draft202012Validator, FormatError, ValidationError
|
|
11
|
+
|
|
12
|
+
from .generated import Publication
|
|
13
|
+
from .generated_config import CatalogConfig
|
|
14
|
+
from .generated_error import CatalogError
|
|
15
|
+
from .generated_search import SearchResult
|
|
16
|
+
from .generated_search_request import SearchRequest
|
|
17
|
+
from .publication import decode_publication
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
_validators = {
|
|
21
|
+
name: Draft202012Validator(
|
|
22
|
+
json.loads(files(__package__).joinpath(f"{name}.schema.json").read_text(encoding="utf-8")),
|
|
23
|
+
format_checker=Draft202012Validator.FORMAT_CHECKER,
|
|
24
|
+
)
|
|
25
|
+
for name in ("catalog-config", "search-request", "search")
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class CatalogException(Exception):
|
|
30
|
+
"""Catalog failure with a generated, serializable error record."""
|
|
31
|
+
|
|
32
|
+
def __init__(self, error: CatalogError):
|
|
33
|
+
self.error = error
|
|
34
|
+
super().__init__(error.message)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _failure(code, operation, message, url: str | None = None, status=None, response_json=None):
|
|
38
|
+
return CatalogException(CatalogError(
|
|
39
|
+
code=code, operation=operation, message=message,
|
|
40
|
+
url=url, status=status, response_json=response_json,
|
|
41
|
+
))
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _validate_url(url: str, operation, search=False):
|
|
45
|
+
try:
|
|
46
|
+
Draft202012Validator.FORMAT_CHECKER.check(url, "uri")
|
|
47
|
+
parsed = urlsplit(url)
|
|
48
|
+
if parsed.scheme not in ("http", "https") or not parsed.hostname:
|
|
49
|
+
raise ValueError("URL must be absolute HTTP(S) with a host")
|
|
50
|
+
if parsed.username is not None or parsed.password is not None:
|
|
51
|
+
raise ValueError("URL must not contain credentials")
|
|
52
|
+
parsed.port
|
|
53
|
+
if search and ("?" in url or "#" in url):
|
|
54
|
+
raise ValueError("search_url must not contain a query or fragment")
|
|
55
|
+
except (ValueError, FormatError) as error:
|
|
56
|
+
raise _failure("INVALID_INPUT", operation, str(error), url) from error
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def _decode_search(text, page, per_page):
|
|
60
|
+
data = json.loads(text)
|
|
61
|
+
try:
|
|
62
|
+
if not isinstance(data, dict) or "grouped_hits" in data:
|
|
63
|
+
raise ValueError("search response must be an ungrouped object")
|
|
64
|
+
if not isinstance(data["hits"], list):
|
|
65
|
+
raise ValueError("search response requires a hits array")
|
|
66
|
+
hits = [hit["document"] for hit in data["hits"]]
|
|
67
|
+
result = {
|
|
68
|
+
"hits": hits, "total": data["found"], "page": data["page"],
|
|
69
|
+
"per_page": data["request_params"]["per_page"],
|
|
70
|
+
"search_cutoff": data["search_cutoff"],
|
|
71
|
+
}
|
|
72
|
+
if "facet_counts" in data:
|
|
73
|
+
result["facet_counts"] = data["facet_counts"]
|
|
74
|
+
_validators["search"].validate(result)
|
|
75
|
+
except (KeyError, TypeError, ValidationError) as error:
|
|
76
|
+
raise ValueError(f"invalid search response: {error}") from error
|
|
77
|
+
if result["page"] != page or result["per_page"] != per_page:
|
|
78
|
+
raise ValueError("response pagination differs from the requested page")
|
|
79
|
+
if len(hits) > per_page:
|
|
80
|
+
raise ValueError("response contains more hits than per_page")
|
|
81
|
+
# JSON Schema accepts integers such as 8.0, while generated fields use StrictInt.
|
|
82
|
+
for field in ("total", "page", "per_page"):
|
|
83
|
+
result[field] = int(result[field])
|
|
84
|
+
for facet in result.get("facet_counts", []):
|
|
85
|
+
for value in facet["counts"]:
|
|
86
|
+
value["count"] = int(value["count"])
|
|
87
|
+
return SearchResult.model_validate(result, extra="ignore")
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
class _NoRedirect(HTTPRedirectHandler):
|
|
91
|
+
def redirect_request(self, req, fp, code, msg, headers, newurl):
|
|
92
|
+
return None
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
class CatalogClient:
|
|
96
|
+
"""Synchronous HTTP operations. Omitting both search settings selects ohi.dev."""
|
|
97
|
+
|
|
98
|
+
def __init__(self, config: CatalogConfig | None = None):
|
|
99
|
+
config = CatalogConfig() if config is None else config
|
|
100
|
+
url = config.search_url
|
|
101
|
+
try:
|
|
102
|
+
data = config.model_dump(warnings=False)
|
|
103
|
+
_validators["catalog-config"].validate(data)
|
|
104
|
+
if ("search_url" in data) != ("query_by" in data):
|
|
105
|
+
raise ValueError("search_url and query_by must be supplied together")
|
|
106
|
+
except (ValueError, ValidationError) as error:
|
|
107
|
+
raise _failure("INVALID_INPUT", "CONFIGURE", str(error), url) from error
|
|
108
|
+
if url is not None:
|
|
109
|
+
_validate_url(url, "CONFIGURE", search=True)
|
|
110
|
+
self._search_url = (url if url is not None else
|
|
111
|
+
"https://api.ohi.dev/search/collections/packages/documents/search")
|
|
112
|
+
self._query_by = data.get("query_by", "title,name,description,namespace")
|
|
113
|
+
self._timeout = data.get("timeout_ms", 30000) / 1000
|
|
114
|
+
self._opener = build_opener(_NoRedirect())
|
|
115
|
+
|
|
116
|
+
def search(self, request: SearchRequest) -> SearchResult:
|
|
117
|
+
url = self._search_url
|
|
118
|
+
try:
|
|
119
|
+
params = request.model_dump(warnings=False)
|
|
120
|
+
_validators["search-request"].validate(params)
|
|
121
|
+
except (ValueError, ValidationError) as error:
|
|
122
|
+
raise _failure("INVALID_INPUT", "SEARCH", str(error), url) from error
|
|
123
|
+
params["page"] = int(params.get("page", 1))
|
|
124
|
+
params["per_page"] = int(params.get("per_page", 10))
|
|
125
|
+
if "max_facet_values" in params:
|
|
126
|
+
params["max_facet_values"] = int(params["max_facet_values"])
|
|
127
|
+
params["query_by"] = self._query_by
|
|
128
|
+
body = self._get(url + "?" + urlencode(params), "SEARCH", url)
|
|
129
|
+
try:
|
|
130
|
+
return _decode_search(body.decode("utf-8"), params["page"], params["per_page"])
|
|
131
|
+
except ValueError as error:
|
|
132
|
+
raise _failure("INVALID_RESPONSE", "SEARCH", str(error), url, 200) from error
|
|
133
|
+
|
|
134
|
+
def inspect(self, base_url: str) -> Publication:
|
|
135
|
+
_validate_url(base_url, "INSPECT")
|
|
136
|
+
body = self._get(base_url, "INSPECT", base_url)
|
|
137
|
+
try:
|
|
138
|
+
return decode_publication(body.decode("utf-8"))
|
|
139
|
+
except ValueError as error:
|
|
140
|
+
raise _failure("INVALID_RESPONSE", "INSPECT", str(error), base_url, 200) from error
|
|
141
|
+
|
|
142
|
+
def get(self, url: str) -> bytes:
|
|
143
|
+
_validate_url(url, "GET")
|
|
144
|
+
return self._get(url, "GET", url)
|
|
145
|
+
|
|
146
|
+
def _get(self, url, operation, error_url):
|
|
147
|
+
status = None
|
|
148
|
+
try:
|
|
149
|
+
try:
|
|
150
|
+
response = self._opener.open(
|
|
151
|
+
Request(url, headers={"Accept-Encoding": "identity"}), timeout=self._timeout,
|
|
152
|
+
)
|
|
153
|
+
except HTTPError as error:
|
|
154
|
+
response = error
|
|
155
|
+
with response:
|
|
156
|
+
status = response.status
|
|
157
|
+
if status != 200:
|
|
158
|
+
response_json = None
|
|
159
|
+
try:
|
|
160
|
+
value = json.loads(response.read().decode("utf-8"))
|
|
161
|
+
if isinstance(value, dict):
|
|
162
|
+
response_json = value
|
|
163
|
+
except (OSError, HTTPException, ValueError):
|
|
164
|
+
pass # The known HTTP status takes precedence over body failures.
|
|
165
|
+
raise _failure("HTTP_ERROR", operation, f"HTTP status {status}",
|
|
166
|
+
error_url, status, response_json)
|
|
167
|
+
body = response.read()
|
|
168
|
+
if response.headers.get("Content-Encoding", "identity").strip().lower() != "identity":
|
|
169
|
+
raise _failure("INVALID_RESPONSE", operation, "unsupported HTTP content encoding",
|
|
170
|
+
error_url, status)
|
|
171
|
+
return body
|
|
172
|
+
except (OSError, HTTPException) as error:
|
|
173
|
+
reason = error.reason if isinstance(error, URLError) else error
|
|
174
|
+
code = "TIMEOUT" if isinstance(reason, TimeoutError) else "CONNECTION_ERROR"
|
|
175
|
+
raise _failure(code, operation, str(error), error_url, status) from error
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# Generated by LinkML-Scala from https://ohi.neverblink.eu/contracts/package
|
|
2
|
+
# DO NOT EDIT.
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import re
|
|
6
|
+
from datetime import datetime
|
|
7
|
+
from enum import Enum
|
|
8
|
+
from typing import Annotated, Any
|
|
9
|
+
|
|
10
|
+
from pydantic import BaseModel, BeforeValidator, ConfigDict, Field, StrictInt, model_serializer
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class LinkMLModel(BaseModel):
|
|
14
|
+
"""Base of the generated classes. Loads and dumps the JSON form of the data, as
|
|
15
|
+
described by the JSON Schema generated from the same LinkML model."""
|
|
16
|
+
|
|
17
|
+
model_config = ConfigDict(
|
|
18
|
+
extra="forbid",
|
|
19
|
+
protected_namespaces=(),
|
|
20
|
+
regex_engine="python-re",
|
|
21
|
+
serialize_by_alias=True,
|
|
22
|
+
validate_assignment=True,
|
|
23
|
+
validate_by_name=True,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
@model_serializer(mode="wrap")
|
|
27
|
+
def _skip_none(self, handler: Any) -> Any:
|
|
28
|
+
# Skip the fields without a value, rather than writing null
|
|
29
|
+
return {k: v for k, v in handler(self).items() if v is not None}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _iso(pattern: str) -> Any:
|
|
33
|
+
"""Accept a date or time only as ISO 8601 text, as JSON Schema does."""
|
|
34
|
+
regex = re.compile(pattern)
|
|
35
|
+
|
|
36
|
+
def check(value: Any) -> Any:
|
|
37
|
+
if isinstance(value, (int, float)) or isinstance(value, str) and not regex.match(value):
|
|
38
|
+
raise ValueError("expected ISO 8601 text")
|
|
39
|
+
return value
|
|
40
|
+
|
|
41
|
+
return BeforeValidator(check)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
JsonDateTime = Annotated[datetime, _iso(r"^\d{4}-\d{2}-\d{2}[Tt ]")]
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class ArtifactOrigin(str, Enum):
|
|
48
|
+
"""Origin of published artifact content."""
|
|
49
|
+
|
|
50
|
+
UPSTREAM = "UPSTREAM"
|
|
51
|
+
"""File bytes preserved from the upstream publisher."""
|
|
52
|
+
GENERATED = "GENERATED"
|
|
53
|
+
"""File produced from source ontology content by conversion, import rewriting or other transformations."""
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class Format(str, Enum):
|
|
57
|
+
"""A combination of ontology language and syntax."""
|
|
58
|
+
|
|
59
|
+
owl_turtle = "owl-turtle"
|
|
60
|
+
"""OWL in Turtle syntax."""
|
|
61
|
+
owl_rdfxml = "owl-rdfxml"
|
|
62
|
+
"""OWL in RDF/XML syntax."""
|
|
63
|
+
rdfs_turtle = "rdfs-turtle"
|
|
64
|
+
"""RDFS in Turtle syntax."""
|
|
65
|
+
linkml_yaml = "linkml-yaml"
|
|
66
|
+
"""LinkML in YAML syntax."""
|
|
67
|
+
ossie_yaml = "ossie-yaml"
|
|
68
|
+
"""Apache Ossie in YAML syntax."""
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
class Artifact(LinkMLModel):
|
|
72
|
+
"""Ontology content in a declared format, with explicitly identified entry files."""
|
|
73
|
+
|
|
74
|
+
model_config = ConfigDict(extra="allow")
|
|
75
|
+
|
|
76
|
+
format: Format
|
|
77
|
+
"""Ontology language and syntax of the artifact."""
|
|
78
|
+
origin: ArtifactOrigin
|
|
79
|
+
"""Origin of the artifact content."""
|
|
80
|
+
roots: list[str] = Field(min_length=1)
|
|
81
|
+
"""Permanent absolute URLs of the entry files from which this artifact's ontology is loaded."""
|
|
82
|
+
sha256: Annotated[str, Field(pattern=r"^[0-9a-f]{64}(?![\s\S])")]
|
|
83
|
+
"""SHA-256 of the final immutable file bytes, before HTTP content encoding, as exactly 64 lowercase hexadecimal characters."""
|
|
84
|
+
size_bytes: Annotated[StrictInt, Field(ge=0)]
|
|
85
|
+
"""Byte length of the final immutable artifact file, before HTTP content encoding. Measured from the same bytes as sha256."""
|
|
86
|
+
url: str
|
|
87
|
+
"""Permanent absolute download URL of an immutable ontology file."""
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
class Dependency(LinkMLModel):
|
|
91
|
+
"""A reference to an exact immutable publication required by this publication."""
|
|
92
|
+
|
|
93
|
+
model_config = ConfigDict(extra="allow")
|
|
94
|
+
|
|
95
|
+
base_url: str
|
|
96
|
+
"""Permanent absolute URL identifying one exact immutable publication. GET this exact URL returns its publication JSON. Do not append a filename."""
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
class Publication(LinkMLModel):
|
|
100
|
+
"""One immutable release of one ontology, including its metadata, artifacts and dependencies. Package, publication and release refer to the same entity."""
|
|
101
|
+
|
|
102
|
+
model_config = ConfigDict(extra="allow")
|
|
103
|
+
|
|
104
|
+
artifacts: list[Artifact] = Field(min_length=1)
|
|
105
|
+
"""Available artifacts of this ontology. Each artifact URL occurs once. Multiple artifacts may share a format."""
|
|
106
|
+
base_url: str
|
|
107
|
+
"""Permanent absolute URL identifying one exact immutable publication. GET this exact URL returns its publication JSON. Do not append a filename."""
|
|
108
|
+
dependencies: list[Dependency]
|
|
109
|
+
"""Complete set of direct and indirect runtime dependency publications, excluding this publication. Each base_url occurs once. An empty list means this publication has no runtime dependencies."""
|
|
110
|
+
description: Annotated[str, Field(pattern=r"^[\s\S]*\S")]
|
|
111
|
+
"""Short description of the ontology's domain and intended use."""
|
|
112
|
+
keywords: list[str]
|
|
113
|
+
"""Keywords describing the ontology's subject. An empty list means no keywords are provided."""
|
|
114
|
+
licenses: list[Annotated[str, Field(pattern=r"^[\s\S]*\S")]]
|
|
115
|
+
"""Reported license names or standard identifiers such as Apache-2.0. Empty means no information supplied. The list specifies neither AND nor OR combination semantics."""
|
|
116
|
+
name: Annotated[str, Field(pattern=r"^[\s\S]*\S")]
|
|
117
|
+
"""Short catalog identifier, qualified by namespace. The namespace/name pair identifies the same ontology across releases. URLs must not be derived from this identifier."""
|
|
118
|
+
namespace: Annotated[str, Field(pattern=r"^[\s\S]*\S")]
|
|
119
|
+
"""Namespace qualifying the ontology name, such as w3c in w3c/prov-o."""
|
|
120
|
+
namespace_iri: str | None = None
|
|
121
|
+
"""Optional preferred primary RDF term namespace. Preserve the complete value including any trailing delimiter. Not the catalog namespace and not necessarily the ontology IRI."""
|
|
122
|
+
preferred_prefix: Annotated[str, Field(pattern=r"^[^\s:]+(?![\s\S])")] | None = None
|
|
123
|
+
"""Optional abbreviation for namespace_iri, without whitespace or a colon. Requires namespace_iri. This constraint does not certify prefix syntax for every ontology language."""
|
|
124
|
+
published_at: JsonDateTime
|
|
125
|
+
"""First successful Hub publication time for this immutable release. Backend emits UTC date-time text with Z. Consumers accept timezone-bearing RFC 3339 text. Fixed for the lifetime of this publication. Not an upstream release date."""
|
|
126
|
+
publisher: Annotated[str, Field(pattern=r"^[\s\S]*\S")]
|
|
127
|
+
"""Name of the upstream person or organization responsible for publishing the ontology. Not inferred from catalog namespace."""
|
|
128
|
+
schema_version: Annotated[StrictInt, Field(ge=2, le=2)]
|
|
129
|
+
"""Metadata contract revision, independent of the ontology's version."""
|
|
130
|
+
title: Annotated[str, Field(pattern=r"^[\s\S]*\S")]
|
|
131
|
+
"""Display title of the ontology."""
|
|
132
|
+
version: Annotated[str, Field(pattern=r"^[\s\S]*\S")]
|
|
133
|
+
"""Complete publication version label, including amendments."""
|