canonical / charms.reactive

Framework for developing charms and relations using the reactive pattern
Apache License 2.0
22 stars 34 forks source link

ModuleNotFoundError: No module named 'pkg_resources' #263

Open hloeung opened 3 months ago

hloeung commented 3 months ago

Hi,

I'm seeing this in charms.reactive v1.5.3:

_______________________________________________ ERROR collecting tests/unit/test_ubuntu_repository_cache.py _______________________________________________
ImportError while importing test module '/tmp/tmpfiles-hloeung/tmp/ubuntu-repository-cache/tests/unit/test_ubuntu_repository_cache.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/lib/python3.12/importlib/__init__.py:90: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
tests/unit/test_ubuntu_repository_cache.py:19: in <module>
    from reactive import ubuntu_repository_cache  # NOQA: E402
reactive/ubuntu_repository_cache.py:15: in <module>
    from charms import reactive
.tox/unit/lib/python3.12/site-packages/charms/reactive/__init__.py:21: in <module>
    from .relations import *  # noqa
.tox/unit/lib/python3.12/site-packages/charms/reactive/relations.py:32: in <module>
    from pkg_resources import iter_entry_points
E   ModuleNotFoundError: No module named 'pkg_resources'

I think this is related to the recent PR - https://github.com/canonical/charms.reactive/pull/260

- try:
-     from importlib.metadata import entry_points
- except ImportError:
-     from pkg_resources import iter_entry_points
+ from pkg_resources import iter_entry_points

Isn't pkg_resources meant to be deprecated? https://setuptools.pypa.io/en/latest/pkg_resources.html says:

Attention

Use of pkg_resources is deprecated in favor of importlib.resources, importlib.metadata and their backports (importlib_resources, importlib_metadata). Some useful APIs are also provided by packaging (e.g. requirements and version parsing). Users should refrain from new usage of pkg_resources and should work to port to importlib-based solutions.