Use importlib.resources instead of __file__
adalke opened this issue · comments
mmpdb uses __file__
to get the *.sql
files. This prevents mmpdb from being installed as a wheel/zipfile.
I've switched to importlib.resources
, which is the modern way to get resources like this.
The importlib.resources
module was added in Python 3.7, which means this change drops Python 3.6 support!
This should not be a problem. Python 3.6 came out nearly 5 years ago, and its support period ends 2021-12, which is next month.
If it is a problem, then there are a couple of solutions. 1) use pkg_resources, 2) use the resources back-port.
The mapping from (package_name, resource_name) -> content is in the setup.cfg:
[options.package_data]
mmpdblib = schema.sql, create_index.sql, drop_index.sql, fragment_schema.sql
and loaded like this:
_schema_template = importlib.resources.read_text("mmpdblib", "schema.sql")
Implemented in 3.0 development branch