Ouranosinc / xscen

A climate change scenario-building analysis framework.
https://xscen.readthedocs.io/
Apache License 2.0
17 stars 2 forks source link

More robust `show_versions` #281

Closed RondeauG closed 1 year ago

RondeauG commented 1 year ago

Generic Issue

Description

xscen.utils.show_versions has an hard-coded list of dependencies, which isn't great when they change. Ideally, the code should look for the real dependencies.

Possible solution

Taken from elsewhere, but could be adapted to work here.

def check_pip_version(pkgs):
    '''returns a dictionary of packages {pkg_name:version}, as returned by pip list.'''
    try:
        from importlib import metadata
    except ImportError: # for Python<3.8, or bokeh < 3.0.2
        import importlib_metadata as metadata
    return {k:metadata.version(k) for k in pkgs}
Zeitsperre commented 1 year ago

The design goal of show_versions is to specifically have a curated list of specific deps that we know will significantly affect the behaviour of the package (and not list Python version specific standard libraries). For that reason, it's hardcoded.

Another approach could be to gather the list of dependencies from requirements.txt to do this (or read the pyproject.toml when we migrate to that).