hashberg-io / multiformats

Python implementation of multiformat protocols.
https://multiformats.readthedocs.io
MIT License
22 stars 6 forks source link

Use `files()` to open *-table JSONs (importlib deprecated `open_text`) #11

Closed cardoso-neto closed 9 months ago

cardoso-neto commented 1 year ago

I'm using python 3.11 and I'm getting these a lot:

> multiformats_config/multicodec.py:80:
>> with importlib_resources.open_text("multiformats_config", "multicodec-table.json", encoding="utf8") as _table_f:
> multiformats_config/multibase.py:53
>> with importlib_resources.open_text("multiformats_config", "multibase-table.json", encoding="utf8") as _table_f:
DeprecationWarning:
    open_text is deprecated. Use files() instead.
    Refer to https://importlib-resources.readthedocs.io/en/latest/using.html#migrating-from-legacy for migration advice.

And since I'm here, let me state that this is the best implementation of the multiformats protocol I've seen and it is only thanks to this package that I was able to get multiformats adopted where I work.

cardoso-neto commented 1 year ago

Fix could look like this for multibase.py:

    pkg_dir = importlib_resources.files("multiformats_config")
    # then either joinpath
    with pkg_dir.joinpath("multibase-table.json").open(encoding="utf8") as _table_f:
    # or slash operator
    with (pkg_dir / "multibase-table.json").open(encoding="utf8") as _table_f:
sg495 commented 1 year ago

Thanks for spotting this! (and for the compliment 😊). We've only recently moved to 3.11 ourselves, and this library hasn't yet been migrated. We'll get to it shortly 👍.