Capture environment metadata, refactor utils
1. Provides a new function capture_environment in utils.py, to
- capture important environment data (library versions/commits, environment vars, venvs, paths etc, host system)
- write out meta data file
- write out pip freeze > requirements.txt
- if spack: write spack env yaml & lock files
- if conda: write conda env file
This makes the old functions io.write_sysinfo and io.write_version_githash obsolete.
Note: the git commit hash for packages installed via editable builds is found as before with the
git python package (common.utils.get_git_commit_hash). for non-editable builds, the git commit
can still be found, if the project's pyproject.toml includes the following setup:
pyproject.toml:
[build-system]
requires = ["setuptools>=64", "setuptools_scm[toml]>=6.2"]
build-backend = "setuptools.build_meta"
[project]
dynamic = ["version"]
[tool.setuptools_scm]
write_to = "common/_version.py" # replace by package name here!
write_to_template = """\
__version__ = "{version}"
__git_commit__ = "{scm_version.node}"
"""
Add the following to __init__.py (replace "example" by package name):
try:
from example._version import __git_commit__ as _git_commit
from example._version import __version__
__git_commit__ = _git_commit.lstrip("g") if isinstance(_git_commit, str) else "unknown"
except ImportError:
__version__ = "unknown"
__git_commit__ = "unknown"
2. Renames utils.get_git_commit_hash to git_commit_hash (old, deprecated function is kept for
backward compatibility)