openrvdas.logger.utils.read_version
Utility for reading the OpenRVDAS release version.
The version is derived from git tags (see the [tool.setuptools_scm] section of pyproject.toml) rather than hand-maintained as a static string, so it can't drift from what's actually tagged/released.
For an editable install (pip install -e ., as utils/install_openrvdas.sh
does), pip only computes this once, at install time, and freezes it into
the package's dist-info metadata - a plain git pull on an already-installed
checkout won't update it. So get_version() first asks setuptools_scm to
recompute the version live from the current git tree, and only falls back
to the installed package's (possibly stale) metadata if that's not
possible - e.g. no .git directory present (a non-editable install from a
built wheel/sdist), or setuptools_scm isn't available in this environment.
1#!/usr/bin/env python3 2"""Utility for reading the OpenRVDAS release version. 3 4The version is derived from git tags (see the [tool.setuptools_scm] section 5of pyproject.toml) rather than hand-maintained as a static string, so it 6can't drift from what's actually tagged/released. 7 8For an editable install (`pip install -e .`, as utils/install_openrvdas.sh 9does), pip only computes this once, at install time, and freezes it into 10the package's dist-info metadata - a plain `git pull` on an already-installed 11checkout won't update it. So get_version() first asks setuptools_scm to 12recompute the version live from the current git tree, and only falls back 13to the installed package's (possibly stale) metadata if that's not 14possible - e.g. no .git directory present (a non-editable install from a 15built wheel/sdist), or setuptools_scm isn't available in this environment. 16""" 17import importlib.metadata 18import logging 19from pathlib import Path 20 21# Root of the git checkout: three levels up from this file 22# (logger/utils/read_version.py -> logger/utils -> logger -> repo root). 23_REPO_ROOT = Path(__file__).resolve().parents[2] 24 25 26############################################################################### 27def get_version() -> str: 28 """ 29 Return the OpenRVDAS version. 30 31 Returns: 32 The version string (e.g. "2.6.1", or "2.6.2.dev3+g1234567" for an 33 untagged commit). Prefers a live read of the current git tree; 34 falls back to the installed package's metadata, then to "unknown" 35 if neither is available. 36 """ 37 try: 38 import setuptools_scm 39 return setuptools_scm.get_version(root=str(_REPO_ROOT)) 40 except Exception: 41 # No .git tree to read (non-editable install), setuptools_scm isn't 42 # installed in this environment, or some other lookup failure - 43 # fall back to whatever version was frozen in at install time. 44 pass 45 46 try: 47 return importlib.metadata.version('openrvdas') 48 except importlib.metadata.PackageNotFoundError: 49 logging.warning('OpenRVDAS is not installed as a package; can\'t determine its version.') 50 return 'unknown'
28def get_version() -> str: 29 """ 30 Return the OpenRVDAS version. 31 32 Returns: 33 The version string (e.g. "2.6.1", or "2.6.2.dev3+g1234567" for an 34 untagged commit). Prefers a live read of the current git tree; 35 falls back to the installed package's metadata, then to "unknown" 36 if neither is available. 37 """ 38 try: 39 import setuptools_scm 40 return setuptools_scm.get_version(root=str(_REPO_ROOT)) 41 except Exception: 42 # No .git tree to read (non-editable install), setuptools_scm isn't 43 # installed in this environment, or some other lookup failure - 44 # fall back to whatever version was frozen in at install time. 45 pass 46 47 try: 48 return importlib.metadata.version('openrvdas') 49 except importlib.metadata.PackageNotFoundError: 50 logging.warning('OpenRVDAS is not installed as a package; can\'t determine its version.') 51 return 'unknown'
Return the OpenRVDAS version.
Returns: The version string (e.g. "2.6.1", or "2.6.2.dev3+g1234567" for an untagged commit). Prefers a live read of the current git tree; falls back to the installed package's metadata, then to "unknown" if neither is available.