iotile / iotile/coretools

Consider migrating to importlib_resources for finding data file in packages

Open
#644 0 comments 0 reactions 0 assignees View on GitHub
iotile-build type:enhancement
Dominant language
Python
Stars
14
Forks
7
PR merge metrics
No merged PRs in 30d

Description

As we move to consolidating all `entry_point` related code into `ComponentRegistry.load_extensions`, there are some places, most notably in `iotile-build` where we also explicitly load data files using `pkg_resources.resource_filename`. This method does not have a direct, non-hacky analog that we could embed into `ComponentRegistry` and is just as slow as the rest of `pkg_resources`, potentially negating the speed benefits of #472, which the `load_extensions` refactor is designed to allow.

So, we need an alternative to `pkg_resources.resource_filename` and it looks like `importlib_resources` is the best alternative. It is a backport of stdlib functionality introduced in Python 3.7 to 2.7 and 3.4+:
https://importlib-resources.readthedocs.io/en/latest/using.html

It has analog methods for most of what we need from `pkg_resources` in terms of file loading.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.