-
Type:
Improvement
-
Resolution: Fixed
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
None
-
None
-
None
-
None
-
None
-
None
-
None
In https://github.com/mongodb-labs/mongo-arrow/pull/25 we introduced a runtime check for the READTHEDOCS environment variable in PyMongoArrow's _init_.py to prevent errors like:
WARNING: autodoc: failed to import module 'api' from module 'pymongoarrow'; the following exception was raised: Traceback (most recent call last): File "/Users/pmital/.pyenv/versions/3.7.10/envs/arrow_DOCS/lib/python3.7/site-packages/sphinx/ext/autodoc/importer.py", line 71, in import_module return importlib.import_module(modname) File "/Users/pmital/.pyenv/versions/3.7.10/lib/python3.7/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1006, in _gcd_import File "<frozen importlib._bootstrap>", line 983, in _find_and_load File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 677, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 728, in exec_module File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed File "/Users/pmital/Developer/mongo-arrow-github/bindings/python/pymongoarrow/__init__.py", line 36, in <module> if _parse_version(libbson_version) < _parse_version(_MIN_LIBBSON_VERSION): File "/Users/pmital/.pyenv/versions/3.7.10/envs/arrow_DOCS/lib/python3.7/site-packages/pkg_resources/__init__.py", line 130, in parse_version return packaging.version.Version(v) File "/Users/pmital/.pyenv/versions/3.7.10/envs/arrow_DOCS/lib/python3.7/site-packages/pkg_resources/_vendor/packaging/version.py", line 200, in __init__ match = self._regex.search(version) TypeError: expected string or bytes-like object WARNING: autodoc: failed to import module 'pymongoarrow'; the following exception was raised: Traceback (most recent call last): File "/Users/pmital/.pyenv/versions/3.7.10/envs/arrow_DOCS/lib/python3.7/site-packages/sphinx/ext/autodoc/importer.py", line 71, in import_module return importlib.import_module(modname) File "/Users/pmital/.pyenv/versions/3.7.10/lib/python3.7/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1006, in _gcd_import File "<frozen importlib._bootstrap>", line 983, in _find_and_load File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 677, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 728, in exec_module File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed File "/Users/pmital/Developer/mongo-arrow-github/bindings/python/pymongoarrow/__init__.py", line 36, in <module> if _parse_version(libbson_version) < _parse_version(_MIN_LIBBSON_VERSION): File "/Users/pmital/.pyenv/versions/3.7.10/envs/arrow_DOCS/lib/python3.7/site-packages/pkg_resources/__init__.py", line 130, in parse_version return packaging.version.Version(v) File "/Users/pmital/.pyenv/versions/3.7.10/envs/arrow_DOCS/lib/python3.7/site-packages/pkg_resources/_vendor/packaging/version.py", line 200, in __init__ match = self._regex.search(version) TypeError: expected string or bytes-like object WARNING: autodoc: failed to import module 'monkey' from module 'pymongoarrow'; the following exception was raised: Traceback (most recent call last): File "/Users/pmital/.pyenv/versions/3.7.10/envs/arrow_DOCS/lib/python3.7/site-packages/sphinx/ext/autodoc/importer.py", line 71, in import_module return importlib.import_module(modname) File "/Users/pmital/.pyenv/versions/3.7.10/lib/python3.7/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1006, in _gcd_import File "<frozen importlib._bootstrap>", line 983, in _find_and_load File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 677, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 728, in exec_module File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed File "/Users/pmital/Developer/mongo-arrow-github/bindings/python/pymongoarrow/__init__.py", line 36, in <module> if _parse_version(libbson_version) < _parse_version(_MIN_LIBBSON_VERSION): File "/Users/pmital/.pyenv/versions/3.7.10/envs/arrow_DOCS/lib/python3.7/site-packages/pkg_resources/__init__.py", line 130, in parse_version return packaging.version.Version(v) File "/Users/pmital/.pyenv/versions/3.7.10/envs/arrow_DOCS/lib/python3.7/site-packages/pkg_resources/_vendor/packaging/version.py", line 200, in __init__ match = self._regex.search(version) TypeError: expected string or bytes-like object
The root cause for these errors is that the autodoc extension imports the module to be documented at runtime. In this case, our modules depend on external C-libraries that we cannot install on ReadTheDocs so we utilize the workaround detailed here using the autodoc_mock_imports configopt. However, the import-time libbson version check still fails because autodoc does not know what value to return for this attribute even though it manages to mock it.
Another major downside to this approach is that if we add an import that isn’t in autodoc_mock_imports the docs might break again and we might not notice.
We should investigate to find out if there is a better solution for this problem.
- related to
-
INTPYTHON-21 Test PyMongoArrow documentation build in CI
-
- Closed
-