Check version of LTTng Python module and raise error if below 2.10.7

This commit is contained in:
Christophe Bedard 2020-01-09 20:21:44 -05:00
parent 3a715c7a2e
commit 3980c2dd01
2 changed files with 29 additions and 0 deletions

View file

@ -23,6 +23,15 @@ try:
from . import lttng_impl from . import lttng_impl
_lttng = lttng_impl _lttng = lttng_impl
# Check lttng module version
from distutils.version import StrictVersion
current_version = _lttng.get_version()
LTTNG_MIN_VERSION = '2.10.7'
if current_version is None or current_version < StrictVersion(LTTNG_MIN_VERSION):
raise RuntimeError(
f'lttng module version >={LTTNG_MIN_VERSION} required, found {str(current_version)}'
)
except ImportError: except ImportError:
# Fall back on stub functions so that this still passes linter checks # Fall back on stub functions so that this still passes linter checks
from . import lttng_stub from . import lttng_stub

View file

@ -14,8 +14,11 @@
"""Implementation of the interface for tracing with LTTng.""" """Implementation of the interface for tracing with LTTng."""
from distutils.version import StrictVersion
import re
from typing import List from typing import List
from typing import Optional from typing import Optional
from typing import Union
import lttng import lttng
@ -26,6 +29,23 @@ from .path import DEFAULT_BASE_PATH
from .path import get_full_session_path from .path import get_full_session_path
def get_version() -> Union[StrictVersion, None]:
"""
Get the version of the lttng module.
The module does not have a __version__ attribute, but the version is mentioned in its __doc__,
and seems to be written in a consistent way across versions.
:return: the version as a StrictVersion object, or `None` if it cannot be extracted
"""
doc_lines = lttng.__doc__.split('\n')
first_line = list(filter(None, doc_lines))[0]
version_string = first_line.split(' ')[1]
if not re.compile(r'^[0-9]+\.[0-9]+\.[0-9]+$').match(version_string):
return None
return StrictVersion(version_string)
def setup( def setup(
session_name: str, session_name: str,
base_path: str = DEFAULT_BASE_PATH, base_path: str = DEFAULT_BASE_PATH,