Open grigaut opened 1 year ago
@grigaut thanks for this PR, it is a step towards fixing https://github.com/ecmwf/cdsapi/issues/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.
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:
import cdsapi
pytest test.py
Pytest should raise following warning:
warnings.warn("pkg_resources is deprecated as an API", DeprecationWarning)