Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[python] verify_core_versions() during import tiledbsoma #2437

Merged
merged 2 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions apis/python/src/tiledbsoma/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
get_SOMA_version,
get_storage_engine,
show_package_versions,
verify_core_versions,
johnkerl marked this conversation as resolved.
Show resolved Hide resolved
)
from ._indexer import IntIndexer, tiledbsoma_build_index
from ._measurement import Measurement
Expand All @@ -168,6 +169,8 @@
tiledbsoma_stats_reset,
)

verify_core_versions()
johnkerl marked this conversation as resolved.
Show resolved Hide resolved

__version__ = get_implementation_version()

__all__ = [
Expand Down
79 changes: 68 additions & 11 deletions apis/python/src/tiledbsoma/_general_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@

"""General utility functions.
"""

import os
import platform
import sys
from re import fullmatch

import tiledb

from .pytiledbsoma import version as libtiledbsoma_version
from .pytiledbsoma import version as libtiledbsoma_core_version_str


def get_SOMA_version() -> str:
Expand Down Expand Up @@ -59,19 +60,75 @@
return "tiledb"


def get_tiledb_py_core_version() -> str:
"""Returns the version of libtiledb ("core") used by the `tiledb` Python library.

Lifecycle: maturing
"""
return ".".join(str(ijk) for ijk in list(tiledb.libtiledb.version()))


def get_libtiledbsoma_core_version() -> str:
"""Returns the version of libtiledb ("core") used by libtiledbsoma.

Lifecycle: maturing
"""
v = libtiledbsoma_core_version_str()
m = fullmatch(r"libtiledb=(\d+\.\d+\.\d+)", v)
if m is None:
raise ValueError(f"Unexpected libtiledbsoma_core_version: {v}")

Check warning on line 79 in apis/python/src/tiledbsoma/_general_utilities.py

View check run for this annotation

Codecov / codecov/patch

apis/python/src/tiledbsoma/_general_utilities.py#L79

Added line #L79 was not covered by tests
return m.group(1)


# Set this env var to "err" to print an error to stderr when TileDB-Py's and libtiledbsoma's core
# versions mismatch (by default, an AssertionError is raised).
TILEDB_CORE_MISMATCHED_VERSIONS_ERROR_LEVEL_VAR = (
"TILEDB_CORE_MISMATCHED_VERSIONS_ERROR_LEVEL"
)


def verify_core_versions() -> None:
"""Verify that the versions of libtiledb used by the `tiledb` Python library and
libtiledbsoma are the same.

See discussion on https://github.com/single-cell-data/TileDB-SOMA/issues/1837; this
will be unnecessary when libtiledbsoma is the only "path to core" (cf.
https://github.com/single-cell-data/TileDB-SOMA/issues/1632).

Lifecycle: maturing
"""
tiledb_py_core_version = get_tiledb_py_core_version()
libtiledbsoma_core_version = get_libtiledbsoma_core_version()
if tiledb_py_core_version != libtiledbsoma_core_version:
msg = "libtiledb versions used by tiledb and libtiledbsoma differ: %s != %s" % (

Check warning on line 103 in apis/python/src/tiledbsoma/_general_utilities.py

View check run for this annotation

Codecov / codecov/patch

apis/python/src/tiledbsoma/_general_utilities.py#L103

Added line #L103 was not covered by tests
tiledb_py_core_version,
libtiledbsoma_core_version,
)
if os.environ.get(TILEDB_CORE_MISMATCHED_VERSIONS_ERROR_LEVEL_VAR) == "err":
print(msg, file=sys.stderr)
print(

Check warning on line 109 in apis/python/src/tiledbsoma/_general_utilities.py

View check run for this annotation

Codecov / codecov/patch

apis/python/src/tiledbsoma/_general_utilities.py#L107-L109

Added lines #L107 - L109 were not covered by tests
f"Continuing, since ${TILEDB_CORE_MISMATCHED_VERSIONS_ERROR_LEVEL_VAR} is set, but it is highly recommended you fix the core version mismatch, as undefined behavior and segfaults can result.",
file=sys.stderr,
)
else:
raise AssertionError(

Check warning on line 114 in apis/python/src/tiledbsoma/_general_utilities.py

View check run for this annotation

Codecov / codecov/patch

apis/python/src/tiledbsoma/_general_utilities.py#L114

Added line #L114 was not covered by tests
f"libtiledb versions used by tiledb and libtiledbsoma differ: {tiledb_py_core_version} != {libtiledbsoma_core_version}"
)


def show_package_versions() -> None:
"""Nominal use is for bug reports, so issue filers and issue fixers can be on
the same page.

Lifecycle: maturing
"""
print("tiledbsoma.__version__ ", get_implementation_version())
print("TileDB-Py tiledb.version() ", tiledb.version())
print(
"TileDB core version ",
".".join(str(ijk) for ijk in list(tiledb.libtiledb.version())),
)
print("libtiledbsoma version() ", libtiledbsoma_version())
print("python version ", ".".join(str(v) for v in sys.version_info))
u = platform.uname()
print("OS version ", u.system, u.release)
# fmt: off
print("tiledbsoma.__version__ ", get_implementation_version())
print("TileDB-Py version ", ".".join(str(v) for v in tiledb.version()))
print("TileDB core version (tiledb) ", get_tiledb_py_core_version())
print("TileDB core version (libtiledbsoma)", get_libtiledbsoma_core_version())
print("python version ", ".".join(str(v) for v in sys.version_info))
print("OS version ", u.system, u.release)
# fmt: on
verify_core_versions()
Loading