Replace pkg_resources with importlib_metadata
Hi,
first of all, thanks for this great library. I just ran into this warning all the time about pkg_resources being deprecated when in favour of importlib.metadata.
In this pull request I replaces pas_resources with importlib_metadata: https://docs.python.org/3/library/importlib.metadata.html , this is a back port for Importlib.metadata which is only in the standard library since python 3.8. By explicitly using importlib_metadata, older versions of python 3 are also still supported by NCLS. An alternative would be for NCLS to stop supporting python versions older than 3.8 and use the importlib.metadata from the standard library.
I'll have a look at this tomorrow, thanks :D
I'm getting an error that might be fixed by this PR:
...
File "/usr/local/lib/python3.8/dist-packages/TFEA/rank.py", line 1370, in meta_profile_bg
from ncls import NCLS
File "/usr/local/lib/python3.8/dist-packages/ncls/__init__.py", line 2, in <module>
import pkg_resources
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3254, in <module>
def _initialize_master_working_set():
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3237, in _call_aside
f(*args, **kwargs)
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3266, in _initialize_master_working_set
working_set = WorkingSet._build_master()
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 575, in _build_master
ws = cls()
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 568, in __init__
self.add_entry(entry)
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 624, in add_entry
for dist in find_distributions(entry, True):
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 1970, in find_distributions
importer = get_importer(path_item)
File "/usr/lib/python3.8/pkgutil.py", line 419, in get_importer
importer = path_hook(path_item)
File "<frozen importlib._bootstrap_external>", line 1594, in path_hook_for_FileFinder
File "<frozen importlib._bootstrap_external>", line 1469, in __init__
File "<frozen importlib._bootstrap_external>", line 177, in _path_isabs
AttributeError: 'PosixPath' object has no attribute 'startswith'
have you guys seen that before? and do you know if there's a workaround?
Hi @sstrong99 ,
sorry for replying late on this. The problem you are having is not caused by NCLS, but by a bug in python: https://bugs.python.org/issue44061 . I think making a fresh and new python environment might solve your problem.
I think this PR might also solve the problem (but somewhat as a side effect).
Same issues for python 3.12.
Hello,
Thanks for the great library. I am wondering if this PR will be merged in the near future? Thanks.
pkg_resources would raise a deprecated at python 3.13:
python3.13/site-packages/ncls/init.py:2: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81. import pkg_resources
Working on it now.