version_info
Documentation for eth_defi.version_info Python module.
Read Docker image git version stamp.
During the Docker image build, the git revision of the source tree is
written into GIT_VERSION_TAG.txt, GIT_COMMIT_MESSAGE.txt and
GIT_VERSION_HASH.txt files at the install root — see
Dockerfile.vault-scanner. This module reads those files back at
runtime so long-running services can report which code revision they
are running, e.g. the vault scanner embedding its version in the
top-vaults JSON export.
Modelled on the trade-executor VersionInfo pattern, based on
https://stackoverflow.com/a/74694676/315168
Example:
from eth_defi.version_info import VersionInfo
version = VersionInfo.read_docker_version()
print(version.commit_hash) # None outside Docker
Module Attributes
Sentinel written by the Docker build when a version ARG was not passed. |
|
Custom Parquet key containing the same mapping as JSON export |
Functions
|
Add vault-scanner build provenance to a PyArrow schema. |
Classes
Reflect the git version information embedded in the Docker image during build. |
- VERSION_FILE_ROOT: pathlib.Path = PosixPath('/home/runner/work/web3-ethereum-defi/web3-ethereum-defi')
Install root where the Docker build writes the version stamp files.
Resolves to the directory containing the
eth_defipackage, e.g./usr/src/web3-ethereum-defiinside the vault scanner image or the repository checkout when running from source.
- UNSPECIFIED_SENTINEL = 'unspecified'
Sentinel written by the Docker build when a version ARG was not passed.
Dockerfile.vault-scannerdefaults eachGIT_*build ARG tounspecified, so an image built without the args (e.g. a plaindocker compose build) stamps this literal string into the files.VersionInfo.read_version_file()normalises it toNone.
- PARQUET_VERSION_METADATA_KEY = b'metadata.version'
Custom Parquet key containing the same mapping as JSON export
metadata.versionfields. The value is a UTF-8 JSON object, because Apache Parquet file metadata is a flat bytes-to-bytes mapping.
- class VersionInfo
Bases:
objectReflect the git version information embedded in the Docker image during build.
All fields are
Nonewhen running outside a stamped Docker image, e.g. from a source checkout. Individual fields can also beNoneinside a stamped image when the corresponding build ARG was not passed — in particulartagisNonefor images built from an untagged commit. SeeDockerfile.vault-scannerfor how the stamp files are written.- tag: Optional[str]
Git tag at build time, e.g.
v0.30.Often
None: only set when the image was built with theGIT_VERSION_TAGbuild ARG, which requires a tagged commit. Usecommit_hashas the primary build identifier.
- static read_version_file(name, root=PosixPath('/home/runner/work/web3-ethereum-defi/web3-ethereum-defi'))
Read one version stamp file written by the Docker build.
- Parameters
name (str) – Stamp file name, e.g.
GIT_VERSION_HASH.txt.root (pathlib.Path) – Directory holding the stamp files.
- Returns
Stripped file content, or
Noneif the file does not exist, is empty, or contains theUNSPECIFIED_SENTINELplaceholder written when the build ARG was not passed.- Return type
- classmethod read_docker_version(root=PosixPath('/home/runner/work/web3-ethereum-defi/web3-ethereum-defi'))
Read version information burnt within the Docker file system during image build.
- Parameters
root (pathlib.Path) – Directory holding the stamp files. Defaults to the
eth_defiinstall root.- Returns
Populated version info, or
Nonefor every field when the stamp files are absent (e.g. running from a source checkout).- Return type
- as_dict()
Return a JSON-serialisable dict for embedding in data exports.
- as_parquet_metadata()
Serialise this version stamp for Parquet file metadata.
Uses
PARQUET_VERSION_METADATA_KEYwith the exact mapping returned byas_dict(). This is the Parquet equivalent of themetadata.versionobject included in vault scanner JSON exports.
- stamp_parquet_schema_metadata(schema, version_info=None)
Add vault-scanner build provenance to a PyArrow schema.
Preserves existing schema metadata, such as pandas’ column-index metadata, while replacing the scanner’s version stamp with the version of the code currently writing the file. Use this for every scanner-produced Parquet artefact so raw, cleaned, and sample price data can be traced to the same Docker build as the JSON exports.
- Parameters
schema (Any) – PyArrow schema to stamp.
Anyavoids imposing a runtime PyArrow dependency on the lightweight version-information module.version_info (Optional[eth_defi.version_info.VersionInfo]) – Optional explicit version for tests or specialised callers. When omitted, reads the Docker image stamp of the current process.
- Returns
A copy of
schemawithmetadata.versionprovenance metadata.- Return type