Skip to content

Commit 03bcb23

Browse files
author
Mike Dirolf
committed
helper to check for C extension PYTHON-51
1 parent 2cafc86 commit 03bcb23

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

doc/api/pymongo/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
Alias for :class:`pymongo.connection.Connection`.
1111

12+
.. autofunction:: has_c
13+
1214
Sub-modules:
1315

1416
.. toctree::

pymongo/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,12 @@
3333

3434
Connection = PyMongo_Connection
3535
"""Alias for :class:`pymongo.connection.Connection`."""
36+
37+
def has_c():
38+
"""Is the C extension installed?
39+
"""
40+
try:
41+
from pymongo import _cbson
42+
return True
43+
except ImportError:
44+
return False

tools/fail_if_no_c.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import sys
2121
sys.path[0:0] = [""]
2222

23-
try:
24-
from pymongo import _cbson
25-
except ImportError:
23+
import pymongo
24+
25+
if not pymongo.has_c():
2626
sys.exit("could not import _cbson")

0 commit comments

Comments
 (0)