Skip to content

Commit

Permalink
Remove pkg_resources (#960)
Browse files Browse the repository at this point in the history
  • Loading branch information
giswqs authored Nov 3, 2024
1 parent dd03739 commit 87ef97d
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 24 deletions.
12 changes: 6 additions & 6 deletions leafmap/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions leafmap/examples/__init__.py
Original file line number Diff line number Diff line change
@@ -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/"

Expand Down
6 changes: 2 additions & 4 deletions leafmap/leafmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
6 changes: 2 additions & 4 deletions leafmap/map_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 2 additions & 4 deletions leafmap/maplibregl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions leafmap/pc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions leafmap/plotlymap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down

0 comments on commit 87ef97d

Please sign in to comment.