diff --git a/cf/functions.py b/cf/functions.py index 04d7555438..1adff73ac2 100644 --- a/cf/functions.py +++ b/cf/functions.py @@ -3,6 +3,7 @@ import warnings from collections.abc import Iterable from functools import lru_cache, partial +from importlib.metadata import version from importlib.util import find_spec from itertools import product from os import mkdir @@ -3123,6 +3124,11 @@ def environment(display=True, paths=True): "cartopy": _get_module_info("cartopy", try_except=True), "cfplot": _get_module_info("cfplot", try_except=True), "cf": (__version__, _os_path_abspath(__file__)), + # Healpix module doesn't define a __version__, so can't as standard use + # _get_module_info, but I have opened an Issue with them to define + # this (see: https://github.com/ntessore/healpix/issues/108) + "healpix": (version("healpix"), find_spec("healpix").origin), + "pyproj": _get_module_info("pyproj", try_except=True), } string = "{0}: {1!s}" if paths: @@ -3136,6 +3142,12 @@ def environment(display=True, paths=True): ] ) + # There are a lot of dependencies (compulsory + optional) to print so + # show them in asciibetical order, with the happy coincidence that the + # 'cf*' libraries, 'Platform' and 'Python' still come near the top (the + # (latter because of the capitalisation) so are easy to pick out. + out.sort() + if display: print("\n".join(out)) # pragma: no cover else: diff --git a/cf/test/test_functions.py b/cf/test/test_functions.py index 23f0306ada..f65eba8819 100644 --- a/cf/test/test_functions.py +++ b/cf/test/test_functions.py @@ -302,36 +302,39 @@ def test_environment(self): # Expected full set of components expected = [ + "HDF5 library", "Platform", "Python", - "packaging", - "numpy", + "activestorage", + "cartopy", + "cf", + "cfdm", "cfdm.core", - "udunits2 library", - "HDF5 library", - "netcdf library", - "netCDF4", - "xnetcdf", - "h5netcdf", - "h5py", - "pyfive", - "zarr", - "fsspec", - "scipy", - "dask", - "distributed", + "cfplot", "cftime", "cfunits", - "cfdm", + "dask", + "distributed", "esmpy/ESMF", - "psutil", + "fsspec", + "h5netcdf", + "h5py", + "healpix", "matplotlib", - "activestorage", - "cartopy", - "cfplot", - "cf", - "xarray", + "netCDF4", + "netcdf library", + "numpy", + "packaging", + "psutil", + "pyfive", + "pyproj", + "scipy", + "udunits2 library", "umfive", + "uritools", + "xarray", + "xnetcdf", + "zarr", ] # Ensure all expected components are present