Skip to content

Commit

Permalink
Issue #653 fix paths no longer supporting context manager protocol in…
Browse files Browse the repository at this point in the history
… python 3.13
  • Loading branch information
soxofaan committed Oct 31, 2024
1 parent 2c81333 commit 83876eb
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions openeo/extra/spectral_indices/spectral_indices.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ def load_indices() -> Dict[str, dict]:
# and provide an alternative mechanism to work with custom indices
"resources/extra-indices-dict.json",
]:
with importlib_resources.files("openeo.extra.spectral_indices") / path as resource_path:
data = json.loads(resource_path.read_text(encoding="utf8"))
overwrites = set(specs.keys()).intersection(data["SpectralIndices"].keys())
if overwrites:
raise RuntimeError(f"Duplicate spectral indices: {overwrites} from {path}")
specs.update(data["SpectralIndices"])
resource_path = importlib_resources.files("openeo.extra.spectral_indices") / path
data = json.loads(resource_path.read_text(encoding="utf8"))
overwrites = set(specs.keys()).intersection(data["SpectralIndices"].keys())
if overwrites:
raise RuntimeError(f"Duplicate spectral indices: {overwrites} from {path}")
specs.update(data["SpectralIndices"])

return specs

Expand All @@ -39,10 +39,10 @@ def load_indices() -> Dict[str, dict]:
def load_constants() -> Dict[str, float]:
"""Load constants defined by Awesome Spectral Indices."""
# TODO: encapsulate all this json loading in a single Awesome Spectral Indices registry class?
with importlib_resources.files(
"openeo.extra.spectral_indices"
) / "resources/awesome-spectral-indices/constants.json" as resource_path:
data = json.loads(resource_path.read_text(encoding="utf8"))
resource_path = (
importlib_resources.files("openeo.extra.spectral_indices") / "resources/awesome-spectral-indices/constants.json"
)
data = json.loads(resource_path.read_text(encoding="utf8"))

return {k: v["default"] for k, v in data.items() if isinstance(v["default"], (int, float))}

Expand All @@ -51,10 +51,10 @@ def load_constants() -> Dict[str, float]:
def _load_bands() -> Dict[str, dict]:
"""Load band name mapping defined by Awesome Spectral Indices."""
# TODO: encapsulate all this json loading in a single Awesome Spectral Indices registry class?
with importlib_resources.files(
"openeo.extra.spectral_indices"
) / "resources/awesome-spectral-indices/bands.json" as resource_path:
data = json.loads(resource_path.read_text(encoding="utf8"))
resource_path = (
importlib_resources.files("openeo.extra.spectral_indices") / "resources/awesome-spectral-indices/bands.json"
)
data = json.loads(resource_path.read_text(encoding="utf8"))
return data


Expand Down

0 comments on commit 83876eb

Please sign in to comment.