Skip to content

Commit 45fca4e

Browse files
pjonssonomad
authored andcommitted
Use function from datacube
The parse_doc_stream function has been integrated into datacube with the 1.9.9 release.
1 parent 090d790 commit 45fca4e

File tree

4 files changed

+4
-36
lines changed

4 files changed

+4
-36
lines changed

apps/dc_tools/odc/apps/dc_tools/_docs.py

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
"""These should probably be in datacube library."""
22

3-
import json
43
import sys
54
from typing import Sequence, Union
65
from uuid import UUID, uuid5
76

87
from datacube.index.hl import Doc2Dataset
9-
from datacube.utils.documents import parse_yaml
8+
from datacube.utils.documents import parse_doc_stream
109

1110
# Some random UUID to be ODC namespace
1211
ODC_NS = UUID("6f34c6f4-13d6-43c0-8e4e-42b6c13203af")
@@ -73,37 +72,6 @@ def from_metadata_stream(metadata_stream, index, **kwargs):
7372
yield (None, f"Error: {uri}, {err}")
7473

7574

76-
def parse_doc_stream(doc_stream, on_error=None, transform=None):
77-
"""
78-
Replace doc bytes/strings with parsed dicts.
79-
80-
Stream[(uri, bytes)] -> Stream[(uri, dict)]
81-
82-
83-
:param doc_stream: sequence of (uri, doc: bytes|string)
84-
:param on_error: Callback uri, doc -> None
85-
:param transform: dict -> dict if supplied also apply further transform on parsed document
86-
87-
On output doc is replaced with python dict parsed from yaml, or with None
88-
if parsing/transform error occurred.
89-
"""
90-
for uri, doc in doc_stream:
91-
try:
92-
if uri.endswith(".json"):
93-
metadata = json.loads(doc)
94-
else:
95-
metadata = parse_yaml(doc)
96-
97-
if transform is not None:
98-
metadata = transform(metadata)
99-
except Exception: # pylint: disable=broad-except
100-
if on_error is not None:
101-
on_error(uri, doc)
102-
metadata = None
103-
104-
yield uri, metadata
105-
106-
10775
def from_yaml_doc_stream(doc_stream, index, logger=None, transform=None, **kwargs):
10876
"""
10977
Stream of yaml documents to a stream of Dataset results.

apps/dc_tools/odc/apps/dc_tools/s3_to_dc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
from datacube import Datacube
1414
from datacube.index.hl import Doc2Dataset
1515
from datacube.ui.click import environment_option, pass_config
16+
from datacube.utils.documents import parse_doc_stream
1617
from odc.aio import S3Fetcher, s3_find_glob
17-
from odc.apps.dc_tools._docs import parse_doc_stream
1818
from odc.apps.dc_tools.utils import (
1919
IndexingException,
2020
SkippedException,

apps/dc_tools/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ authors = [
77
]
88
dependencies = [
99
"click",
10-
"datacube>=1.9.6",
10+
"datacube>=1.9.9",
1111
"datadog",
1212
"eodatasets3>=1.9",
1313
"fsspec",

tests/test-env.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ dependencies:
1010
- python=3.12
1111

1212
# Datacube
13-
- datacube>=1.9.0
13+
- datacube>=1.9.9
1414
- sqlalchemy>=2.0
1515

1616
# odc.ui

0 commit comments

Comments
 (0)