portolan-python 0.1.4__tar.gz → 0.1.6__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.
- {portolan_python-0.1.4 → portolan_python-0.1.6}/.coverage +0 -0
- {portolan_python-0.1.4 → portolan_python-0.1.6}/PKG-INFO +1 -1
- {portolan_python-0.1.4 → portolan_python-0.1.6}/docs/distribution.md +4 -4
- {portolan_python-0.1.4 → portolan_python-0.1.6}/docs/examples.md +2 -2
- {portolan_python-0.1.4 → portolan_python-0.1.6}/pyproject.toml +1 -1
- {portolan_python-0.1.4 → portolan_python-0.1.6}/src/portolan/registry.py +57 -24
- {portolan_python-0.1.4 → portolan_python-0.1.6}/tests/test_registry_api.py +116 -2
- {portolan_python-0.1.4 → portolan_python-0.1.6}/uv.lock +1 -1
- {portolan_python-0.1.4 → portolan_python-0.1.6}/.github/workflows/release.yml +0 -0
- {portolan_python-0.1.4 → portolan_python-0.1.6}/.gitignore +0 -0
- {portolan_python-0.1.4 → portolan_python-0.1.6}/Makefile +0 -0
- {portolan_python-0.1.4 → portolan_python-0.1.6}/README.md +0 -0
- {portolan_python-0.1.4 → portolan_python-0.1.6}/docs/development.md +0 -0
- {portolan_python-0.1.4 → portolan_python-0.1.6}/docs/scope.md +0 -0
- {portolan_python-0.1.4 → portolan_python-0.1.6}/src/portolan/__init__.py +0 -0
- {portolan_python-0.1.4 → portolan_python-0.1.6}/src/portolan/catalog.py +0 -0
- {portolan_python-0.1.4 → portolan_python-0.1.6}/src/portolan/py.typed +0 -0
- {portolan_python-0.1.4 → portolan_python-0.1.6}/src/portolan/validation.py +0 -0
- {portolan_python-0.1.4 → portolan_python-0.1.6}/tests/test_catalog_api.py +0 -0
|
Binary file
|
|
@@ -8,8 +8,8 @@ preferred package index for published versions.
|
|
|
8
8
|
Push a tag that matches the version in `pyproject.toml`:
|
|
9
9
|
|
|
10
10
|
```bash
|
|
11
|
-
git tag v0.1.
|
|
12
|
-
git push origin v0.1.
|
|
11
|
+
git tag v0.1.6
|
|
12
|
+
git push origin v0.1.6
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
The release workflow runs the tests, builds both distributions, checks their
|
|
@@ -25,7 +25,7 @@ Install the wheel attached to a release:
|
|
|
25
25
|
|
|
26
26
|
```bash
|
|
27
27
|
python -m pip install \
|
|
28
|
-
https://github.com/jemacchi/portolan-python/releases/download/v0.1.
|
|
28
|
+
https://github.com/jemacchi/portolan-python/releases/download/v0.1.6/portolan_python-0.1.6-py3-none-any.whl
|
|
29
29
|
```
|
|
30
30
|
|
|
31
31
|
This path needs no package index account.
|
|
@@ -35,7 +35,7 @@ This path needs no package index account.
|
|
|
35
35
|
Install a published version from PyPI with:
|
|
36
36
|
|
|
37
37
|
```bash
|
|
38
|
-
python -m pip install portolan-python==0.1.
|
|
38
|
+
python -m pip install portolan-python==0.1.6
|
|
39
39
|
```
|
|
40
40
|
|
|
41
41
|
Omit the version constraint to install the latest published version.
|
|
@@ -10,14 +10,14 @@ GitHub:
|
|
|
10
10
|
|
|
11
11
|
```bash
|
|
12
12
|
python -m pip install \
|
|
13
|
-
https://github.com/jemacchi/portolan-python/releases/download/v0.1.
|
|
13
|
+
https://github.com/jemacchi/portolan-python/releases/download/v0.1.6/portolan_python-0.1.6-py3-none-any.whl
|
|
14
14
|
```
|
|
15
15
|
|
|
16
16
|
You can also install the source at a specific tag:
|
|
17
17
|
|
|
18
18
|
```bash
|
|
19
19
|
python -m pip install \
|
|
20
|
-
"portolan-python @ git+https://github.com/jemacchi/portolan-python.git@v0.1.
|
|
20
|
+
"portolan-python @ git+https://github.com/jemacchi/portolan-python.git@v0.1.6"
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
## List collections and assets
|
|
@@ -215,32 +215,65 @@ def _write_catalog_tree(
|
|
|
215
215
|
target.parent.mkdir(parents=True, exist_ok=True)
|
|
216
216
|
if document.get("type") == "Collection":
|
|
217
217
|
document = _with_absolute_asset_hrefs(document_url, document)
|
|
218
|
+
|
|
219
|
+
links = document.get("links")
|
|
220
|
+
if isinstance(links, list):
|
|
221
|
+
rewritten_links: list[Any] = []
|
|
222
|
+
for link in links:
|
|
223
|
+
rewritten_link = link
|
|
224
|
+
if isinstance(link, dict) and isinstance(link.get("href"), str):
|
|
225
|
+
href = link["href"]
|
|
226
|
+
linked_url = urljoin(document_url, href)
|
|
227
|
+
rewritten_link = {**link, "href": linked_url}
|
|
228
|
+
if link.get("rel") in {"root", "parent"}:
|
|
229
|
+
linked_target = next(
|
|
230
|
+
(path for path, owner_url in targets.items() if owner_url == linked_url),
|
|
231
|
+
None,
|
|
232
|
+
)
|
|
233
|
+
if linked_target is not None:
|
|
234
|
+
rewritten_link = {
|
|
235
|
+
**link,
|
|
236
|
+
"href": _relative_local_href(target, linked_target),
|
|
237
|
+
}
|
|
238
|
+
if link.get("rel") == "child":
|
|
239
|
+
child_url = linked_url
|
|
240
|
+
child_target = _target_document_path(root_url, child_url, output_root)
|
|
241
|
+
owner = targets.get(child_target)
|
|
242
|
+
if owner is not None and owner != child_url:
|
|
243
|
+
raise ValueError(
|
|
244
|
+
f"Registry documents map to the same local path: {owner}, {child_url}"
|
|
245
|
+
)
|
|
246
|
+
if child_url in visited:
|
|
247
|
+
if owner == child_url:
|
|
248
|
+
rewritten_link = {
|
|
249
|
+
**link,
|
|
250
|
+
"href": _relative_local_href(target, child_target),
|
|
251
|
+
}
|
|
252
|
+
else:
|
|
253
|
+
child = fetch_json(child_url)
|
|
254
|
+
if child.get("type") in {"Catalog", "Collection"}:
|
|
255
|
+
_write_catalog_tree(
|
|
256
|
+
child_url,
|
|
257
|
+
child,
|
|
258
|
+
root_url,
|
|
259
|
+
output_root,
|
|
260
|
+
fetch_json,
|
|
261
|
+
visited,
|
|
262
|
+
targets,
|
|
263
|
+
)
|
|
264
|
+
rewritten_link = {
|
|
265
|
+
**link,
|
|
266
|
+
"href": _relative_local_href(target, child_target),
|
|
267
|
+
}
|
|
268
|
+
rewritten_links.append(rewritten_link)
|
|
269
|
+
document = {**document, "links": rewritten_links}
|
|
270
|
+
|
|
218
271
|
target.write_text(json.dumps(document, indent=2) + "\n", encoding="utf-8")
|
|
219
272
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
if not isinstance(href, str):
|
|
225
|
-
continue
|
|
226
|
-
child_url = urljoin(document_url, href)
|
|
227
|
-
if child_url in visited:
|
|
228
|
-
continue
|
|
229
|
-
child_target = _target_document_path(root_url, child_url, output_root)
|
|
230
|
-
owner = targets.get(child_target)
|
|
231
|
-
if owner is not None and owner != child_url:
|
|
232
|
-
raise ValueError(f"Registry documents map to the same local path: {owner}, {child_url}")
|
|
233
|
-
child = fetch_json(child_url)
|
|
234
|
-
if child.get("type") in {"Catalog", "Collection"}:
|
|
235
|
-
_write_catalog_tree(
|
|
236
|
-
child_url,
|
|
237
|
-
child,
|
|
238
|
-
root_url,
|
|
239
|
-
output_root,
|
|
240
|
-
fetch_json,
|
|
241
|
-
visited,
|
|
242
|
-
targets,
|
|
243
|
-
)
|
|
273
|
+
|
|
274
|
+
def _relative_local_href(parent_target: Path, child_target: Path) -> str:
|
|
275
|
+
relative_path = os.path.relpath(child_target, start=parent_target.parent)
|
|
276
|
+
return Path(relative_path).as_posix()
|
|
244
277
|
|
|
245
278
|
|
|
246
279
|
def _with_absolute_asset_hrefs(document_url: str, collection: JsonObject) -> JsonObject:
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
import json
|
|
6
|
+
from email.message import Message
|
|
6
7
|
from pathlib import Path
|
|
7
8
|
from typing import Any
|
|
8
9
|
from urllib.error import HTTPError
|
|
@@ -188,10 +189,123 @@ def test_download_registry_catalog_writes_snapshot_with_absolute_asset_hrefs(
|
|
|
188
189
|
collection = json.loads(
|
|
189
190
|
(catalog_root / "roads" / "collection.json").read_text(encoding="utf-8")
|
|
190
191
|
)
|
|
191
|
-
assert catalog["links"][0]["href"] == "
|
|
192
|
+
assert catalog["links"][0]["href"] == "roads/collection.json"
|
|
192
193
|
assert collection["assets"]["data"]["href"] == "https://example.test/demo/roads/roads.parquet"
|
|
193
194
|
|
|
194
195
|
|
|
196
|
+
def test_download_registry_catalog_rewrites_downloaded_children_to_local_hrefs(
|
|
197
|
+
tmp_path: Path,
|
|
198
|
+
) -> None:
|
|
199
|
+
root_url = "https://example.test/demo/catalog.json"
|
|
200
|
+
child_url = "https://example.test/demo/roads/collection.json"
|
|
201
|
+
item_url = "https://example.test/demo/roads/item.json"
|
|
202
|
+
responses = {
|
|
203
|
+
root_url: {
|
|
204
|
+
"type": "Catalog",
|
|
205
|
+
"id": "demo",
|
|
206
|
+
"links": [
|
|
207
|
+
{"rel": "self", "href": root_url},
|
|
208
|
+
{"rel": "child", "href": child_url},
|
|
209
|
+
{"rel": "child", "href": item_url},
|
|
210
|
+
],
|
|
211
|
+
},
|
|
212
|
+
child_url: {
|
|
213
|
+
**_collection("roads", {}),
|
|
214
|
+
"links": [{"rel": "child", "href": root_url}],
|
|
215
|
+
},
|
|
216
|
+
item_url: {"type": "Feature", "id": "road-1"},
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
catalog_root = download_registry_catalog(
|
|
220
|
+
root_url,
|
|
221
|
+
tmp_path,
|
|
222
|
+
fetch_json=lambda url: responses[url],
|
|
223
|
+
)
|
|
224
|
+
|
|
225
|
+
catalog = json.loads((catalog_root / "catalog.json").read_text(encoding="utf-8"))
|
|
226
|
+
collection = json.loads(
|
|
227
|
+
(catalog_root / "roads" / "collection.json").read_text(encoding="utf-8")
|
|
228
|
+
)
|
|
229
|
+
assert catalog["links"] == [
|
|
230
|
+
{"rel": "self", "href": root_url},
|
|
231
|
+
{"rel": "child", "href": "roads/collection.json"},
|
|
232
|
+
{"rel": "child", "href": item_url},
|
|
233
|
+
]
|
|
234
|
+
assert collection["links"] == [{"rel": "child", "href": "../catalog.json"}]
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
def test_download_registry_catalog_makes_non_downloaded_relative_links_absolute(
|
|
238
|
+
tmp_path: Path,
|
|
239
|
+
) -> None:
|
|
240
|
+
root_url = "https://example.test/demo/catalog.json"
|
|
241
|
+
collection_url = "https://example.test/demo/roads/collection.json"
|
|
242
|
+
feature_url = "https://example.test/demo/roads/features/road-1.json"
|
|
243
|
+
responses = {
|
|
244
|
+
root_url: {
|
|
245
|
+
"type": "Catalog",
|
|
246
|
+
"id": "demo",
|
|
247
|
+
"links": [{"rel": "child", "href": "./roads/collection.json"}],
|
|
248
|
+
},
|
|
249
|
+
collection_url: {
|
|
250
|
+
**_collection("roads", {}),
|
|
251
|
+
"links": [
|
|
252
|
+
{"rel": "item", "href": "./items/road-1.json"},
|
|
253
|
+
{"rel": "child", "href": "./features/road-1.json"},
|
|
254
|
+
],
|
|
255
|
+
},
|
|
256
|
+
feature_url: {"type": "Feature", "id": "road-1"},
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
catalog_root = download_registry_catalog(
|
|
260
|
+
root_url,
|
|
261
|
+
tmp_path,
|
|
262
|
+
fetch_json=lambda url: responses[url],
|
|
263
|
+
)
|
|
264
|
+
|
|
265
|
+
collection = json.loads(
|
|
266
|
+
(catalog_root / "roads" / "collection.json").read_text(encoding="utf-8")
|
|
267
|
+
)
|
|
268
|
+
assert collection["links"] == [
|
|
269
|
+
{"rel": "item", "href": "https://example.test/demo/roads/items/road-1.json"},
|
|
270
|
+
{"rel": "child", "href": feature_url},
|
|
271
|
+
]
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
def test_download_registry_catalog_keeps_downloaded_root_and_parent_links_local(
|
|
275
|
+
tmp_path: Path,
|
|
276
|
+
) -> None:
|
|
277
|
+
root_url = "https://example.test/demo/catalog.json"
|
|
278
|
+
collection_url = "https://example.test/demo/roads/collection.json"
|
|
279
|
+
responses = {
|
|
280
|
+
root_url: {
|
|
281
|
+
"type": "Catalog",
|
|
282
|
+
"id": "demo",
|
|
283
|
+
"links": [{"rel": "child", "href": "./roads/collection.json"}],
|
|
284
|
+
},
|
|
285
|
+
collection_url: {
|
|
286
|
+
**_collection("roads", {}),
|
|
287
|
+
"links": [
|
|
288
|
+
{"rel": "root", "href": root_url},
|
|
289
|
+
{"rel": "parent", "href": root_url},
|
|
290
|
+
],
|
|
291
|
+
},
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
catalog_root = download_registry_catalog(
|
|
295
|
+
root_url,
|
|
296
|
+
tmp_path,
|
|
297
|
+
fetch_json=lambda url: responses[url],
|
|
298
|
+
)
|
|
299
|
+
|
|
300
|
+
collection = json.loads(
|
|
301
|
+
(catalog_root / "roads" / "collection.json").read_text(encoding="utf-8")
|
|
302
|
+
)
|
|
303
|
+
assert collection["links"] == [
|
|
304
|
+
{"rel": "root", "href": "../catalog.json"},
|
|
305
|
+
{"rel": "parent", "href": "../catalog.json"},
|
|
306
|
+
]
|
|
307
|
+
|
|
308
|
+
|
|
195
309
|
def test_download_registry_catalog_skips_child_cycles(tmp_path: Path) -> None:
|
|
196
310
|
root_url = "https://example.test/demo/catalog.json"
|
|
197
311
|
child_url = "https://example.test/demo/roads/collection.json"
|
|
@@ -324,7 +438,7 @@ def test_download_registry_catalog_preserves_snapshot_when_child_fetch_fails(
|
|
|
324
438
|
"id": "demo",
|
|
325
439
|
"links": [{"rel": "child", "href": "./missing.json"}],
|
|
326
440
|
}
|
|
327
|
-
raise HTTPError(url, 503, "Unavailable", hdrs=
|
|
441
|
+
raise HTTPError(url, 503, "Unavailable", hdrs=Message(), fp=None)
|
|
328
442
|
|
|
329
443
|
with pytest.raises(HTTPError):
|
|
330
444
|
download_registry_catalog(root_url, tmp_path, fetch_json=fetch_json)
|
|
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
|