diff --git a/leafmap/common.py b/leafmap/common.py index d9edc85a3f..6b39a39b59 100644 --- a/leafmap/common.py +++ b/leafmap/common.py @@ -2473,9 +2473,9 @@ def get_census_dict(reset=False): dict: A dictionary of Census data. """ import json - import pkg_resources + import importlib.resources - pkg_dir = os.path.dirname(pkg_resources.resource_filename("leafmap", "leafmap.py")) + pkg_dir = os.path.dirname(importlib.resources.files("leafmap") / "leafmap.py") census_data = os.path.join(pkg_dir, "data/census_data.json") if reset: @@ -6816,10 +6816,10 @@ def create_legend( str: The HTML code of the legend. """ - import pkg_resources + import importlib.resources from .legends import builtin_legends - pkg_dir = os.path.dirname(pkg_resources.resource_filename("leafmap", "leafmap.py")) + pkg_dir = os.path.dirname(importlib.resources.files("leafmap") / "leafmap.py") legend_template = os.path.join(pkg_dir, "data/template/legend_style.html") if draggable: @@ -7097,11 +7097,11 @@ def add_text_to_gif( """ import io - import pkg_resources + import importlib.resources from PIL import Image, ImageDraw, ImageFont, ImageSequence warnings.simplefilter("ignore") - pkg_dir = os.path.dirname(pkg_resources.resource_filename("leafmap", "leafmap.py")) + pkg_dir = os.path.dirname(importlib.resources.files("leafmap") / "leafmap.py") default_font = os.path.join(pkg_dir, "data/fonts/arial.ttf") in_gif = os.path.abspath(in_gif) diff --git a/leafmap/examples/__init__.py b/leafmap/examples/__init__.py index 86e21ae14b..d97efe33a2 100644 --- a/leafmap/examples/__init__.py +++ b/leafmap/examples/__init__.py @@ -1,8 +1,8 @@ import box import os -import pkg_resources +import importlib.resources -_pkg_dir = os.path.dirname(pkg_resources.resource_filename("leafmap", "leafmap.py")) +_pkg_dir = os.path.dirname(importlib.resources.files("leafmap") / "leafmap.py") _datasets_path = os.path.join(_pkg_dir, "examples/datasets.txt") _baseurl = "https://raw.githubusercontent.com/opengeos/leafmap/master/examples/data/" diff --git a/leafmap/leafmap.py b/leafmap/leafmap.py index c942b9b27a..20718c2551 100644 --- a/leafmap/leafmap.py +++ b/leafmap/leafmap.py @@ -1798,12 +1798,10 @@ def add_legend( layer_name (str, optional): Layer name of the legend to be associated with. Defaults to None. """ - import pkg_resources + import importlib.resources from IPython.display import display - pkg_dir = os.path.dirname( - pkg_resources.resource_filename("leafmap", "leafmap.py") - ) + pkg_dir = os.path.dirname(importlib.resources.files("leafmap") / "leafmap.py") legend_template = os.path.join(pkg_dir, "data/template/legend.html") if "min_width" not in kwargs.keys(): diff --git a/leafmap/map_widgets.py b/leafmap/map_widgets.py index af60ad1ddb..c9a5153bfe 100644 --- a/leafmap/map_widgets.py +++ b/leafmap/map_widgets.py @@ -204,12 +204,10 @@ def __init__( """ import os # pylint: disable=import-outside-toplevel from IPython.display import display # pylint: disable=import-outside-toplevel - import pkg_resources # pylint: disable=import-outside-toplevel + import importlib.resources # pylint: disable=import-outside-toplevel from .legends import builtin_legends # pylint: disable=import-outside-toplevel - pkg_dir = os.path.dirname( - pkg_resources.resource_filename("leafmap", "leafmap.py") - ) + pkg_dir = os.path.dirname(importlib.resources.files("leafmap") / "leafmap.py") legend_template = os.path.join(pkg_dir, "data/template/legend.html") if not os.path.exists(legend_template): diff --git a/leafmap/maplibregl.py b/leafmap/maplibregl.py index f1567e93c4..391cf808d8 100644 --- a/leafmap/maplibregl.py +++ b/leafmap/maplibregl.py @@ -2539,12 +2539,10 @@ def add_legend( Returns: None """ - import pkg_resources + import importlib.resources from .legends import builtin_legends - pkg_dir = os.path.dirname( - pkg_resources.resource_filename("leafmap", "leafmap.py") - ) + pkg_dir = os.path.dirname(importlib.resources.files("leafmap") / "leafmap.py") legend_template = os.path.join(pkg_dir, "data/template/legend.html") if not os.path.exists(legend_template): diff --git a/leafmap/pc.py b/leafmap/pc.py index caaefa3e46..96c969c945 100644 --- a/leafmap/pc.py +++ b/leafmap/pc.py @@ -77,9 +77,9 @@ def get_pc_inventory( Returns: dict: A dictionary of collections and their bands. """ - import pkg_resources + import importlib.resources - pkg_dir = os.path.dirname(pkg_resources.resource_filename("leafmap", "leafmap.py")) + pkg_dir = os.path.dirname(importlib.resources.files("leafmap") / "leafmap.py") filepath = os.path.join(pkg_dir, "data/pc_inventory.json") if refresh: diff --git a/leafmap/plotlymap.py b/leafmap/plotlymap.py index 5c358bd82e..894dd039e6 100644 --- a/leafmap/plotlymap.py +++ b/leafmap/plotlymap.py @@ -841,9 +841,9 @@ def fix_widget_error() -> None: Adopted from: https://github.com/plotly/plotly.py/issues/2570#issuecomment-738735816 """ import shutil - import pkg_resources + import importlib.resources - pkg_dir = os.path.dirname(pkg_resources.resource_filename("plotly", "plotly.py")) + pkg_dir = os.path.dirname(importlib.resources.files("plotly") / "plotly.py") basedatatypesPath = os.path.join(pkg_dir, "basedatatypes.py")