From 9b84f347e6833d037706c133d34ab64d7ed7998b Mon Sep 17 00:00:00 2001 From: Rambaud Pierrick <12rambau@users.noreply.github.com> Date: Tue, 10 Dec 2024 09:21:06 +0000 Subject: [PATCH] fix: drop use of deprecated module pkg_resources --- ee_extra/Apps/utils.py | 6 ++---- ee_extra/ImageCollection/core.py | 1 - ee_extra/JavaScript/install.py | 8 +++----- ee_extra/STAC/core.py | 1 - ee_extra/STAC/utils.py | 1 - ee_extra/Spectral/utils.py | 10 ++++------ ee_extra/utils.py | 12 ++++-------- 7 files changed, 13 insertions(+), 26 deletions(-) diff --git a/ee_extra/Apps/utils.py b/ee_extra/Apps/utils.py index 7728439..e949b16 100644 --- a/ee_extra/Apps/utils.py +++ b/ee_extra/Apps/utils.py @@ -6,7 +6,6 @@ from typing import Optional, Union import ee -import pkg_resources from ee_extra.utils import _load_JSON @@ -19,9 +18,8 @@ def _get_apps(online: bool) -> dict: Apps. """ if online: - with urllib.request.urlopen( - "https://raw.githubusercontent.com/samapriya/ee-appshot/main/app_urls.json" - ) as url: + url = "https://raw.githubusercontent.com/samapriya/ee-appshot/main/app_urls.json" + with urllib.request.urlopen(url) as url: apps = json.loads(url.read().decode()) else: apps = _load_JSON("ee-appshot.json") diff --git a/ee_extra/ImageCollection/core.py b/ee_extra/ImageCollection/core.py index 3963eae..a6e6e87 100644 --- a/ee_extra/ImageCollection/core.py +++ b/ee_extra/ImageCollection/core.py @@ -5,7 +5,6 @@ from typing import Optional, Union import ee -import pkg_resources from ee_extra.STAC.utils import _get_platform_STAC diff --git a/ee_extra/JavaScript/install.py b/ee_extra/JavaScript/install.py index 540a0a2..4df86fc 100644 --- a/ee_extra/JavaScript/install.py +++ b/ee_extra/JavaScript/install.py @@ -5,8 +5,7 @@ import pathlib import re import urllib.request - -import pkg_resources +from pathlib import Path def _convert_path_to_ee_sources(path: str) -> str: @@ -32,9 +31,8 @@ def _get_ee_sources_path() -> str: Returns: The ee-sources folder path. """ - ee_extra_py_file = pkg_resources.resource_filename("ee_extra", "ee_extra.py") - pkgdir = pathlib.Path(ee_extra_py_file).parent - return pkgdir.joinpath("ee-sources").as_posix() + pkgdir = Path(__file__).parents[1] + return (pkgdir / "ee-sources").as_posix() def _convert_path_to_ee_extra(path: str) -> str: diff --git a/ee_extra/STAC/core.py b/ee_extra/STAC/core.py index d4d1d05..8c03475 100644 --- a/ee_extra/STAC/core.py +++ b/ee_extra/STAC/core.py @@ -6,7 +6,6 @@ from typing import Optional, Union import ee -import pkg_resources from ee_extra.STAC.utils import _get_platform_STAC from ee_extra.utils import _load_JSON diff --git a/ee_extra/STAC/utils.py b/ee_extra/STAC/utils.py index eac3538..a8ab2d8 100644 --- a/ee_extra/STAC/utils.py +++ b/ee_extra/STAC/utils.py @@ -5,7 +5,6 @@ from typing import Optional, Union import ee -import pkg_resources from ee_extra.utils import _load_JSON diff --git a/ee_extra/Spectral/utils.py b/ee_extra/Spectral/utils.py index bfe1760..9761d42 100644 --- a/ee_extra/Spectral/utils.py +++ b/ee_extra/Spectral/utils.py @@ -6,7 +6,6 @@ from typing import Optional, Union, Tuple, Dict import ee -import pkg_resources from ee_extra.STAC.utils import _get_platform_STAC from ee_extra.utils import _load_JSON @@ -242,9 +241,8 @@ def _get_indices(online: bool) -> dict: Indices. """ if online: - with urllib.request.urlopen( - "https://raw.githubusercontent.com/awesome-spectral-indices/awesome-spectral-indices/main/output/spectral-indices-dict.json" - ) as url: + url = "https://raw.githubusercontent.com/awesome-spectral-indices/awesome-spectral-indices/main/output/spectral-indices-dict.json" + with urllib.request.urlopen(url) as url: indices = json.loads(url.read().decode()) else: indices = _load_JSON("spectral-indices-dict.json") @@ -425,8 +423,8 @@ def _get_tc_coefficients(platform: str) -> dict: "TCW": (0.2254, 0.3681, 0.2250, -0.6053, -0.6298) } - # Zhai et al. 2022 coefficients were included for L8 TOA over the Baig - # et al. 2014 coefficients for consistency with the L8 SR coefficients, + # Zhai et al. 2022 coefficients were included for L8 TOA over the Baig + # et al. 2014 coefficients for consistency with the L8 SR coefficients, # which were not calculated by Baig et al. LANDSAT8_TOA = { "bands": ("B3", "B4", "B5", "B6", "B7"), diff --git a/ee_extra/utils.py b/ee_extra/utils.py index e0fb6e1..ce31e86 100644 --- a/ee_extra/utils.py +++ b/ee_extra/utils.py @@ -1,10 +1,9 @@ import difflib import json -import os from typing import Any, Optional, List, Sequence +from pathlib import Path import ee -import pkg_resources def _load_JSON(x: Optional[str] = "ee-catalog-ids.json") -> Any: @@ -16,12 +15,9 @@ def _load_JSON(x: Optional[str] = "ee-catalog-ids.json") -> Any: Returns: JSON file. """ - eeExtraDir = os.path.dirname( - pkg_resources.resource_filename("ee_extra", "ee_extra.py") - ) - dataPath = os.path.join(eeExtraDir, "data/" + x) - f = open(dataPath) - data = json.load(f) + eeExtraDir = Path(__file__).parent + dataPath = eeExtraDir / "data" / x + data = json.loads(dataPath.read_text()) return data