Skip to content

Commit

Permalink
EP-4053/#255 make sure index specs are packaged and load through pkg_…
Browse files Browse the repository at this point in the history
…resources
  • Loading branch information
soxofaan committed Nov 16, 2021
1 parent 57df192 commit f1d31da
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
3 changes: 3 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include openeo/extra/spectral_indices/resources/*.json
include openeo/extra/spectral_indices/resources/*/*.json
include openeo/extra/spectral_indices/resources/*/LICENSE*
14 changes: 7 additions & 7 deletions openeo/extra/spectral_indices/spectral_indices.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json
from pathlib import Path
import pkg_resources
from typing import Dict, List

import numpy as np
Expand Down Expand Up @@ -52,15 +52,15 @@ def _get_expression_map(cube: DataCube, x: ProcessBuilder) -> Dict[str, ProcessB

def load_indices() -> Dict[str, dict]:
"""Load set of supported spectral indices."""
# TODO: use pkg_resources here instead of direct file reading
resource_dir = Path(__file__).parent / "resources"
specs = {}

for path in [
resource_dir / "awesome-spectral-indices/spectral-indices-dict.json",
resource_dir / "extra-indices-dict.json"
"resources/awesome-spectral-indices/spectral-indices-dict.json",
"resources/extra-indices-dict.json"
]:
with path.open("r") as f:
specs.update(json.load(f)["SpectralIndices"])
with pkg_resources.resource_stream("openeo.extra.spectral_indices", path) as stream:
specs.update(json.load(stream)["SpectralIndices"])

return specs


Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
long_description_content_type="text/markdown",
url="https://github.com/Open-EO/openeo-python-client",
packages=find_packages(include=['openeo*']),
include_package_data=True,
tests_require=tests_require,
test_suite='tests',
install_requires=[
Expand Down

0 comments on commit f1d31da

Please sign in to comment.