From 4e9ac28ea8a523054db32e8c07b230ead30c3dba Mon Sep 17 00:00:00 2001 From: Wu-Jung Lee Date: Sat, 22 Feb 2025 14:38:04 +0800 Subject: [PATCH] Replace `pkg_resources.resource_string` with `importlib.resources.files` [all tests ci] (#1468) * replace pkg_resources with importlib.resources * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * remove unused pkg_resources import * update __name__ to __package__ and use read_text * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * remove unused pkg_resources again * update whats new --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- docs/source/whats-new.md | 1 + echopype/echodata/widgets/widgets.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/source/whats-new.md b/docs/source/whats-new.md index a1d23a3e6..06df6e6b5 100644 --- a/docs/source/whats-new.md +++ b/docs/source/whats-new.md @@ -19,6 +19,7 @@ This release includes the critical migration to use the new `xr.DataTree` functi ## Bug and warning fixes * Assemble AD2CP timestamp with nanosecond precision by @leewujung in /~https://github.com/OSOceanAcoustics/echopype/pull/1436 * Use `import_resources.files` instead of the legacy `open_text` by @leewujung in /~https://github.com/OSOceanAcoustics/echopype/pull/1434 +* Replace `pkg_resources.resource_string` with `importlib.resources.files` by @leewujung in /~https://github.com/OSOceanAcoustics/echopype/pull/1468 * Fix invalid `\d` warning by using raw string by @leewujung in /~https://github.com/OSOceanAcoustics/echopype/pull/1448 * Check if there exist any swap files before cleaning them up by @ctuguinay in /~https://github.com/OSOceanAcoustics/echopype/pull/1451 * Remove `__setattr__` from EchoData by @leewujung in /~https://github.com/OSOceanAcoustics/echopype/pull/1457 diff --git a/echopype/echodata/widgets/widgets.py b/echopype/echodata/widgets/widgets.py index 08e7d4360..3e1696222 100644 --- a/echopype/echodata/widgets/widgets.py +++ b/echopype/echodata/widgets/widgets.py @@ -1,9 +1,9 @@ import datetime import html from functools import lru_cache +from importlib.resources import files from pathlib import Path -import pkg_resources from jinja2 import Environment, FileSystemLoader, Template from jinja2.exceptions import TemplateNotFound @@ -36,7 +36,7 @@ def _load_static_files(): """Lazily load the resource files into memory the first time they are needed. Clone from xarray.core.formatted_html_template. """ - return [pkg_resources.resource_string(__name__, fname).decode("utf8") for fname in STATIC_FILES] + return [files(__package__).joinpath(fname).read_text(encoding="utf8") for fname in STATIC_FILES] def get_environment() -> Environment: