sysinfo module

class gridtools.sysinfo.SysInfo(grd=None)

Bases: object

A small helper class to provide basic system information and misc operating system utilities. Useful for debugging module or system conflicts. Simple core calls should be placed into the utils module. More complex functions that depend on results from other functions should go into this module. For example, tracking or detecting module versions are in this module.

detectPythonEnvironment()

This attempts to detect a python virtual environment that is running the python script.

This attempts to guess if the script is running under conda or venv. If the answer is neither, then native is assumed.

Other possible environments are covered in an article: https://towardsdatascience.com/comparing-python-virtual-environment-tools-9a6543643a44

  • virtualenv/virtualenvwrapper

  • pew (unmaintained ~ March 2018)

  • venv (recommended since Python 3.5)

  • pipenv

dumpVersionData()

Return a string for use in netCDF attributes

get_jupyterlab_modules()
get_python_loaded_modules()
get_python_module_version(mdlName)

Try to obtain the python module version. This returns the version numer if the module was found or None if nothing was found or an error was encountered.

isAvailable(pkgReq, verReq, orLower=False)
is_lab_notebook()

Detects if current process is a jupyter-lab process.

loadVersionData(**kwargs)

This function loads module version data in a variety of ways. The default is for modules currently loaded by the python executable.

Keyword arguments

  • usePackageManager (boolean) Use a package manager to discover module versions. Default: False

  • packageManager (string) Specify conda or venv as the package manager to use to show versions of installed software. Default: auto

Note

This function by default only obtains version information for modules already loaded into the python environment. Switching to a package manager will display all installed software which may be more information than desired.

For the conda package manager, the conda python module may be installed or the conda executable is available.

The conda python module may be installed within the environment: conda install -c conda-forge conda

printInfo(k, kd, msg)
resetVersionData()

This resets any loaded module version data.

runCommand(cmdString)

Generic function to run a command string and return the results as an array of three items. Return: (stdout, stderr, returncode)

show(showOnly=[], vList=[])
showAll(vList=[])
showEnvironment()
showPackageVersions(vList=[])
showSystem()