Skip to content

Commit

Permalink
Remove pkg_resources
Browse files Browse the repository at this point in the history
  • Loading branch information
giswqs committed Feb 2, 2025
1 parent c4de2a1 commit f6f5831
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 35 deletions.
26 changes: 8 additions & 18 deletions geemap/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import urllib.request
import warnings
import zipfile
import importlib.resources

import ee
import ipywidgets as widgets
Expand Down Expand Up @@ -3454,12 +3455,11 @@ def create_colorbar(
import decimal

# import io
import pkg_resources
from colour import Color
from PIL import Image, ImageDraw, ImageFont

warnings.simplefilter("ignore")
pkg_dir = os.path.dirname(pkg_resources.resource_filename("geemap", "geemap.py"))
pkg_dir = str(importlib.resources.files("geemap").joinpath("geemap.py").parent)

if out_file is None:
filename = "colorbar_" + random_string() + ".png"
Expand Down Expand Up @@ -4120,11 +4120,9 @@ def ee_api_to_csv(outfile=None, timeout=300, proxies=None):
timeout (int, optional): Timeout in seconds. Defaults to 300.
proxies (dict, optional): Proxy settings. Defaults to None.
"""
import pkg_resources

from bs4 import BeautifulSoup

pkg_dir = os.path.dirname(pkg_resources.resource_filename("geemap", "geemap.py"))
pkg_dir = str(importlib.resources.files("geemap").joinpath("geemap.py").parent)
data_dir = os.path.join(pkg_dir, "data")
template_dir = os.path.join(data_dir, "template")
csv_file = os.path.join(template_dir, "ee_api_docs.csv")
Expand Down Expand Up @@ -4240,9 +4238,7 @@ def read_api_csv():
"""
import copy

import pkg_resources

pkg_dir = os.path.dirname(pkg_resources.resource_filename("geemap", "geemap.py"))
pkg_dir = str(importlib.resources.files("geemap").joinpath("geemap.py").parent)
data_dir = os.path.join(pkg_dir, "data")
template_dir = os.path.join(data_dir, "template")
csv_file = os.path.join(template_dir, "ee_api_docs.csv")
Expand Down Expand Up @@ -5129,9 +5125,8 @@ def vis_to_qml(ee_class_table, out_qml):
ee_class_table (str): An Earth Engine class table with triple quotes.
out_qml (str): File path to the output QGIS Layer Style (.qml).
"""
import pkg_resources

pkg_dir = os.path.dirname(pkg_resources.resource_filename("geemap", "geemap.py"))
pkg_dir = str(importlib.resources.files("geemap").joinpath("geemap.py").parent)
data_dir = os.path.join(pkg_dir, "data")
template_dir = os.path.join(data_dir, "template")
qml_template = os.path.join(template_dir, "NLCD.qml")
Expand Down Expand Up @@ -5178,9 +5173,7 @@ def create_nlcd_qml(out_qml):
Args:
out_qml (str): File path to the output qml.
"""
import pkg_resources

pkg_dir = os.path.dirname(pkg_resources.resource_filename("geemap", "geemap.py"))
pkg_dir = str(importlib.resources.files("geemap").joinpath("geemap.py").parent)
data_dir = os.path.join(pkg_dir, "data")
template_dir = os.path.join(data_dir, "template")
qml_template = os.path.join(template_dir, "NLCD.qml")
Expand Down Expand Up @@ -10012,9 +10005,7 @@ def get_census_dict(reset=False):
Returns:
dict: A dictionary of Census data.
"""
import pkg_resources

pkg_dir = os.path.dirname(pkg_resources.resource_filename("geemap", "geemap.py"))
pkg_dir = str(importlib.resources.files("geemap").joinpath("geemap.py").parent)
census_data = os.path.join(pkg_dir, "data/census_data.json")

if reset:
Expand Down Expand Up @@ -13729,10 +13720,9 @@ def create_legend(
str: The HTML code of the legend.
"""

import pkg_resources
from .legends import builtin_legends

pkg_dir = os.path.dirname(pkg_resources.resource_filename("geemap", "geemap.py"))
pkg_dir = str(importlib.resources.files("geemap").joinpath("geemap.py").parent)
legend_template = os.path.join(pkg_dir, "data/template/legend_style.html")

if draggable:
Expand Down
4 changes: 2 additions & 2 deletions geemap/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from pathlib import Path

import ipywidgets as widgets
import pkg_resources
import importlib.resources
from box import Box
from IPython.display import display

Expand All @@ -25,7 +25,7 @@ def get_data_csv() -> str:
Returns:
str: File path to the CSV file.
"""
pkg_dir = os.path.dirname(pkg_resources.resource_filename("geemap", "geemap.py"))
pkg_dir = str(importlib.resources.files("geemap").joinpath("geemap.py").parent)
template_dir = os.path.join(pkg_dir, "data/template")
data_csv = os.path.join(template_dir, "ee_data_catalog.csv")
return data_csv
Expand Down
4 changes: 2 additions & 2 deletions geemap/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("geemap", "geemap.py"))
_pkg_dir = str(importlib.resources.files("geemap").joinpath("geemap.py").parent)
_datasets_path = os.path.join(_pkg_dir, "examples/datasets.txt")
_baseurl = (
"https://raw.githubusercontent.com/gee-community/geemap/master/examples/data/"
Expand Down
2 changes: 0 additions & 2 deletions geemap/legends.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,8 +493,6 @@ def ee_table_to_legend(in_table, out_file):
in_table (str): The input file path (*.txt) to the Earth Engine color table.
out_file (str): The output file path (*.txt) to the legend dictionary.
"""
# pkg_dir = os.path.dirname(pkg_resources.resource_filename("geemap", "geemap.py"))
# ee_legend_table = os.path.join(pkg_dir, "data/template/ee_legend_table.txt")

if not os.path.exists(in_table):
print("The class table does not exist.")
Expand Down
6 changes: 3 additions & 3 deletions geemap/map_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1437,10 +1437,10 @@ def _select_dataset(self, dataset_title):

def get_ee_example(self, asset_id):
try:
import pkg_resources
import importlib.resources

pkg_dir = os.path.dirname(
pkg_resources.resource_filename("geemap", "geemap.py")
pkg_dir = str(
importlib.resources.files("geemap").joinpath("geemap.py").parent
)
with open(os.path.join(pkg_dir, "data/gee_f.json"), encoding="utf-8") as f:
functions = json.load(f)
Expand Down
6 changes: 2 additions & 4 deletions geemap/maplibregl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2468,12 +2468,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("geemap", "geemap.py")
)
pkg_dir = str(importlib.resources.files("geemap").joinpath("geemap.py").parent)
legend_template = os.path.join(pkg_dir, "data/template/legend.html")

if not os.path.exists(legend_template):
Expand Down
5 changes: 3 additions & 2 deletions geemap/timelapse.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,11 +412,12 @@ def add_text_to_gif(
# import io
import warnings

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("geemap", "geemap.py"))

pkg_dir = str(importlib.resources.files("geemap").joinpath("geemap.py").parent)
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 geemap/toolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -1574,9 +1574,9 @@ def set_properties(_, geometry):

def get_tools_dict():
import pandas as pd
import pkg_resources
import importlib.resources

pkg_dir = os.path.dirname(pkg_resources.resource_filename("geemap", "geemap.py"))
pkg_dir = str(importlib.resources.files("geemap").joinpath("geemap.py").parent)
toolbox_csv = os.path.join(pkg_dir, "data/template/toolbox.csv")

df = pd.read_csv(toolbox_csv).set_index("index")
Expand Down

0 comments on commit f6f5831

Please sign in to comment.