rdkit / mmpdb

A package to identify matched molecular pairs and use them to predict property changes.
Other
197 stars 55 forks source link

Use importlib.resources instead of __file__ #42

Closed adalke closed 2 years ago

adalke commented 2 years ago

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")
adalke commented 2 years ago

Implemented in 3.0 development branch