Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use .files() methods from importlib.resources to find the package directory #379

Merged
merged 3 commits into from
Apr 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions rio_tiler/colormap.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@
)

try:
import importlib.resources as pkg_resources
from importlib.resources import files as resources_files # type: ignore
except ImportError:
# Try backported to PY<37 `importlib_resources`.
import importlib_resources as pkg_resources # type: ignore
# Try backported to PY<39 `importlib_resources`.
from importlib_resources import files as resources_files # type: ignore


EMPTY_COLORMAP: Dict = {i: [0, 0, 0, 0] for i in range(256)}

with pkg_resources.path(__package__, "cmap_data") as p:
DEFAULT_CMAPS_FILES = {f.stem: str(f) for f in p.glob("*.npy")}
DEFAULT_CMAPS_FILES = {
f.stem: str(f) for f in (resources_files(__package__) / "cmap_data").glob("*.npy")
}

USER_CMAPS_DIR = os.environ.get("COLORMAP_DIRECTORY", None)
if USER_CMAPS_DIR:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"rasterio>=1.1.7",
"requests",
"rio-color",
"importlib_resources;python_version<'3.7'",
"importlib_resources>=1.1.0;python_version<'3.9'",
]

extra_reqs = {
Expand Down