Skip to content

Commit c906bb0

Browse files
Merge pull request #965 from sadielbartholomew/env-function-updates
Update `cf.environment()` including sorting long output
2 parents 05e8c72 + 250ca5b commit c906bb0

2 files changed

Lines changed: 37 additions & 22 deletions

File tree

cf/functions.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import warnings
44
from collections.abc import Iterable
55
from functools import lru_cache, partial
6+
from importlib.metadata import version
67
from importlib.util import find_spec
78
from itertools import product
89
from os import mkdir
@@ -3123,6 +3124,11 @@ def environment(display=True, paths=True):
31233124
"cartopy": _get_module_info("cartopy", try_except=True),
31243125
"cfplot": _get_module_info("cfplot", try_except=True),
31253126
"cf": (__version__, _os_path_abspath(__file__)),
3127+
# Healpix module doesn't define a __version__, so can't as standard use
3128+
# _get_module_info, but I have opened an Issue with them to define
3129+
# this (see: https://github.com/ntessore/healpix/issues/108)
3130+
"healpix": (version("healpix"), find_spec("healpix").origin),
3131+
"pyproj": _get_module_info("pyproj", try_except=True),
31263132
}
31273133
string = "{0}: {1!s}"
31283134
if paths:
@@ -3136,6 +3142,12 @@ def environment(display=True, paths=True):
31363142
]
31373143
)
31383144

3145+
# There are a lot of dependencies (compulsory + optional) to print so
3146+
# show them in asciibetical order, with the happy coincidence that the
3147+
# 'cf*' libraries, 'Platform' and 'Python' still come near the top (the
3148+
# (latter because of the capitalisation) so are easy to pick out.
3149+
out.sort()
3150+
31393151
if display:
31403152
print("\n".join(out)) # pragma: no cover
31413153
else:

cf/test/test_functions.py

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -302,36 +302,39 @@ def test_environment(self):
302302

303303
# Expected full set of components
304304
expected = [
305+
"HDF5 library",
305306
"Platform",
306307
"Python",
307-
"packaging",
308-
"numpy",
308+
"activestorage",
309+
"cartopy",
310+
"cf",
311+
"cfdm",
309312
"cfdm.core",
310-
"udunits2 library",
311-
"HDF5 library",
312-
"netcdf library",
313-
"netCDF4",
314-
"xnetcdf",
315-
"h5netcdf",
316-
"h5py",
317-
"pyfive",
318-
"zarr",
319-
"fsspec",
320-
"scipy",
321-
"dask",
322-
"distributed",
313+
"cfplot",
323314
"cftime",
324315
"cfunits",
325-
"cfdm",
316+
"dask",
317+
"distributed",
326318
"esmpy/ESMF",
327-
"psutil",
319+
"fsspec",
320+
"h5netcdf",
321+
"h5py",
322+
"healpix",
328323
"matplotlib",
329-
"activestorage",
330-
"cartopy",
331-
"cfplot",
332-
"cf",
333-
"xarray",
324+
"netCDF4",
325+
"netcdf library",
326+
"numpy",
327+
"packaging",
328+
"psutil",
329+
"pyfive",
330+
"pyproj",
331+
"scipy",
332+
"udunits2 library",
334333
"umfive",
334+
"uritools",
335+
"xarray",
336+
"xnetcdf",
337+
"zarr",
335338
]
336339

337340
# Ensure all expected components are present

0 commit comments

Comments
 (0)