Skip to content

Commit

Permalink
Use importlib_resources for full Python 3.x compat
Browse files Browse the repository at this point in the history
  • Loading branch information
chuckwondo committed Mar 19, 2024
1 parent 86ca437 commit ad69960
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 24 deletions.
23 changes: 6 additions & 17 deletions earthaccess/formatters.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,17 @@
import importlib.resources
import sys
from typing import Any, List
from uuid import uuid4

STATIC_FILES = ["iso_bootstrap4.0.0min.css", "styles.css"]

import importlib_resources

def read_text(
package: str,
resource: str,
encoding: str = "utf-8",
errors: str = "strict",
) -> str:
if sys.version_info < (3, 11):
# importlib.resources.read_text was deprecated in Python 3.11
# see https://docs.python.org/3/library/importlib.resources.html#importlib.resources.read_text
return importlib.resources.read_text(package, resource, encoding, errors)
# Deprecation of importlib.resources.read_text recommends the following instead
return importlib.resources.files(package).joinpath(resource).read_text(encoding)
STATIC_FILES = ["iso_bootstrap4.0.0min.css", "styles.css"]


def _load_static_files() -> List[str]:
"""Load styles"""
return [read_text("earthaccess.css", fname, "utf8") for fname in STATIC_FILES]
return [
importlib_resources.files("earthaccess.css").joinpath(fname).read_text("utf8")
for fname in STATIC_FILES
]


def _repr_collection_html() -> str:
Expand Down
14 changes: 7 additions & 7 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ multimethod = ">=1.8"
python-dateutil = ">=2.8.2"
kerchunk = { version = ">=0.1.2", optional = true }
dask = { version = ">=2022.1.0", optional = true }
importlib-resources = "^6.3.2"

[tool.poetry.extras]
kerchunk = ["kerchunk", "dask"]
Expand Down

0 comments on commit ad69960

Please sign in to comment.