Skip to content

Commit fa7982e

Browse files
authored
ARROW-83 Version Check Warning is Obscured (#70)
1 parent 13805ff commit fa7982e

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

bindings/python/docs/source/developer/installation.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ Conda users can install ``libbson`` as follows::
5050

5151
$ conda install --channel conda-forge libbson pkg-config
5252

53+
The minimum required version is listed in ``pymongoarrow/version.py``.
54+
If you try to build with a lower version a ``ValueError`` will be raised.
55+
5356
Build
5457
-----
5558

bindings/python/pymongoarrow/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@ def _parse_version(version):
2929

3030
try:
3131
from pymongoarrow.lib import libbson_version
32+
except ImportError:
33+
warnings.warn("This library has not been compiled")
34+
libbson_version = None
3235

36+
if libbson_version is not None:
3337
if _parse_version(libbson_version) < _parse_version(_MIN_LIBBSON_VERSION):
3438
raise ImportError(
3539
f"Expected libbson version {_MIN_LIBBSON_VERSION} or greater, "
3640
f"found {libbson_version}"
3741
)
38-
except ImportError:
39-
warnings.warn("This library has not been compiled")

bindings/python/setup.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ def query_pkgconfig(cmd):
3333
return output
3434

3535

36+
def get_min_libbson_version():
37+
version_ns = {}
38+
here = os.path.dirname(__file__)
39+
version_py = os.path.join(here, "pymongoarrow", "version.py")
40+
with open(version_py) as f:
41+
exec(compile(f.read(), version_py, "exec"), version_ns)
42+
return version_ns["_MIN_LIBBSON_VERSION"]
43+
44+
3645
def append_libbson_flags(module):
3746
pc_path = "libbson-1.0"
3847
install_dir = os.environ.get("LIBBSON_INSTALL_DIR")
@@ -84,10 +93,21 @@ def append_libbson_flags(module):
8493
# We have added the library file without raising an error, so return.
8594
return
8695

96+
# Check for the existence of the library.
8797
lnames = query_pkgconfig("pkg-config --libs-only-l {}".format(pc_path))
8898
if not lnames:
8999
raise ValueError(f'Could not find "{pc_path}" library')
90100

101+
# Check against the minimum required version.
102+
min_version = get_min_libbson_version()
103+
mod_version = query_pkgconfig("pkg-config --modversion {}".format(pc_path))
104+
105+
if mod_version < min_version:
106+
raise ValueError(
107+
f"Cannot use {pc_path} with version {mod_version}, minimum required version is {min_version}"
108+
)
109+
110+
# Gather the appropriate flags.
91111
cflags = query_pkgconfig("pkg-config --cflags {}".format(pc_path))
92112

93113
if cflags:

0 commit comments

Comments
 (0)