ecmwf / eccodes-python

Python interface to the ecCodes GRIB/BUFR decoder/encoder
Apache License 2.0
113 stars 33 forks source link

Please use the warnings library for selfcheck #64

Closed dsjstc closed 1 year ago

dsjstc commented 2 years ago

On Ubuntu 21.04 (a very common docker environment), the easily available version of libeccodes is version 2.20.0. Any pip-installed version of eccodes-python newer than 1.1.0 gives the following warning at import time:

Warning: ecCodes 2.21.0 or higher is recommended. You are running version 2.20.0

It would be really nice if this warning could be emitted by the warnings library, so it would be possible to catch it if desired, with code like this:

import warnings
with warnings.catch_warnings():
    import eccodes

In the meantime, if I don't want this (practically unaddressable) warning emitted by my script, I see no choice but to revert to pip install eccodes==1.1.0.

shahramn commented 2 years ago

The ecCodes library is now v2.26.0. Can I ask why your library version is so old? Version 2.20.0 is from January 2021

See https://confluence.ecmwf.int/display/ECC/History+of+Changes

dsjstc commented 2 years ago

The ecCodes library is now v2.26.0. Can I ask why your library version is so old? Version 2.20.0 is from January 2021

It is typical to use packaged linux distributions for containerized development. Ubuntu Impish (21.04) is a very common container environment, and is the one that my company's ML deployment platform is based on. EcCodes 2.20 is the package version available in the Ubuntu repositories for Ubuntu Impish.

This situation is very common for people who wish to use packages but not build them.

uwefladrich commented 1 year ago

I have run into the same issue. Writing warnings to stdout via print messes up the output of tools that import eccodes. Writing via the Python standardlib warnings module would make the warnings appear on stderr (by default), which would also allow for shell redirection.

Pointing to newer versions of eccodes does not really address the issue.

shahramn commented 1 year ago

I have fixed this (check my develop branch)

uwefladrich commented 1 year ago

Great, thanks a lot! :+1:

dsjstc commented 1 year ago

Cool, thanks!