Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use importlib instead of pkg_resources when possible #74

Closed

Conversation

grigaut
Copy link

@grigaut grigaut commented May 3, 2023

Use of pkg_resources triggers DeprecationWarning and according to https://setuptools.pypa.io/en/latest/pkg_resources.html, pkg_resources should be replaced by importlib.

Minimal steps to reproduce warning:

  • Install pytest
  • create a file (let's say 'test.py') with :
    import cdsapi
  • run pytest test.py

Pytest should raise following warning:
warnings.warn("pkg_resources is deprecated as an API", DeprecationWarning)

Use of pkg_resources triggers DeprecationWarning, according to https://setuptools.pypa.io/en/latest/pkg_resources.html pkg_resources should be replaced by importlib
@FussyDuck
Copy link

FussyDuck commented May 3, 2023

CLA assistant check
All committers have signed the CLA.

@veenstrajelmer
Copy link

veenstrajelmer commented May 15, 2024

@grigaut thanks for this PR, it is a step towards fixing #89.

Hierover, I would suggest to replace the current suggestion by something more robust without the need for a try-except statement. The builtin importlib.metadata is available since python 3.8. should work like this:

from importlib.metadata import version

cdsapi_version = version("cdsapi")
self.session.headers = {
        "User-Agent": f"cdsapi/{cdsapi_version}",
        }

I believe this should result in the desired behaviour with less code, but I have not tested it so I might be mistaken.

@EddyCMWF
Copy link
Collaborator

EddyCMWF commented Oct 24, 2024

Many thanks for you contribution, this has been fixed in #126

@EddyCMWF EddyCMWF closed this Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants