tools icon indicating copy to clipboard operation
tools copied to clipboard

use importlib instead of pkg_resources

Open fabianegli opened this issue 3 years ago • 6 comments

Description of feature

__init___.py uses _pkg_resources.get_distribution("nf_core").version but from Python 3.8 on it is recommended to use from importlib.metadata import version; version('nf_core') instead. Once support for Python 3.7 is dropped, this should be changed.

fabianegli avatar Oct 29 '22 12:10 fabianegli

I could not find any instances of _pkg_resources in the nf-core/tools repo. Could this have been resolved already @fabianegli?

lukbut avatar Oct 18 '23 10:10 lukbut

Should be here: https://github.com/nf-core/tools/blob/9ab896c140ee3fde816d250f3d8353aee5547d78/nf_core/download.py#L24

silverslott avatar Oct 18 '23 10:10 silverslott

Hey @sofiahag thanks - it looks like this is a different instance to the one mentioned in the ticket. I assume that if the instances mentioned in this ticket have been removed already, we can remove this instance that you mentioned without breaking Python 3.7 compatibility (if this is still required). Are the supported Python versions documented anywhere, please?

lukbut avatar Oct 18 '23 10:10 lukbut

I searched through the repo and it looks like Python > 3.8 is supported now

lukbut avatar Oct 18 '23 10:10 lukbut

Yes, We dropped support for Python 3.7 at the last hackathon.

fabianegli avatar Oct 18 '23 12:10 fabianegli

If anyone wants to take care of it, this is the warning which triggered the issue:

[...]/tools/nf_core/download.py:24: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
    from pkg_resources import parse_version as VersionParser

One option to handling it would be to use the version parsing provided by packaging but it would probably need some small code changes besides just the replacement of function that parses the string, but

from packaging import version
version.parse("2.3.1").release

could be close enough for the sorting here:

https://github.com/nf-core/tools/blob/9ab896c140ee3fde816d250f3d8353aee5547d78/nf_core/download.py#L1526-L1532

fabianegli avatar Dec 05 '23 17:12 fabianegli