Skip to content

Commit edcf00f

Browse files
Ensure autodoc is able to import pymongoarrow.api when building on ReadTheDocs (#25)
1 parent f8ddbe7 commit edcf00f

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

bindings/python/docs/source/conf.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
# add these directories to sys.path here. If the directory is relative to the
1111
# documentation root, use os.path.abspath to make it absolute, like shown here.
1212
#
13-
# import os
14-
# import sys
15-
# sys.path.insert(0, os.path.abspath('.'))
13+
import os
14+
import sys
15+
sys.path.insert(0, os.path.abspath('../..'))
1616

1717

1818
# -- Project information -----------------------------------------------------
@@ -36,6 +36,11 @@
3636
'sphinx.ext.intersphinx'
3737
]
3838

39+
# https://docs.readthedocs.io/en/stable/faq.html#i-get-import-errors-on-libraries-that-depend-on-c-modules
40+
autodoc_mock_imports = ['pyarrow',
41+
'pymongoarrow.lib',
42+
'bson']
43+
3944
# Add any paths that contain templates here, relative to this directory.
4045
templates_path = ['_templates']
4146

bindings/python/pymongoarrow/__init__.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
14+
import os
1515
# We must import pyarrow before attempting to load the Cython module.
1616
import pyarrow
1717

@@ -27,8 +27,10 @@
2727
def _parse_version(version):
2828
return _LooseVersion(version)
2929

30-
31-
if _parse_version(libbson_version) < _parse_version(_MIN_LIBBSON_VERSION):
32-
raise ImportError(
33-
f"Expected libbson version {_MIN_LIBBSON_VERSION} or greater, "
34-
f"found {libbson_version}")
30+
# TODO: PYTHON-2659
31+
on_rtd = os.environ.get('READTHEDOCS') == 'True'
32+
if not on_rtd:
33+
if _parse_version(libbson_version) < _parse_version(_MIN_LIBBSON_VERSION):
34+
raise ImportError(
35+
f"Expected libbson version {_MIN_LIBBSON_VERSION} or greater, "
36+
f"found {libbson_version}")

0 commit comments

Comments
 (0)