I am attempting to build documentation using Sphinx on ReadTheDocs, for a project that depends on a bunch of pydata packages, some of which depend on C libraries which are not available on ReadTheDocs (namely the python-snappy
package, which provides the snappy
module, implementing Google's snappy compression algorithm, which we are using in Apache Parquet files).
The documentation suggests that the solution is to mock those python modules so that autodoc
can import them, even if the code isn't really there, using the autodoc_mock_imports
parameter in conf.py
So I've got
autodoc_mock_imports = ['snappy', 'python-snappy']
in my Sphinx conf.py
(I think it's really supposed to be just snappy
in there, but I wasn't 100% sure and it wasn't working with snappy
at first, so I added the package name as well as the module name... and it still didn't work).
However, the documentation build is still attempting to compile snappy
and predictably failing, because the C-language headers aren't available. When the build is collecting requirements, it finds python-snappy
, I think in the project setup.py
and says:
Collecting python-snappy (from pudl==0.1.dev398+g5e075d4)
And subsequently the build fails:
Building wheels for collected packages: pudl, python-snappy
Building wheel for pudl (setup.py): started
Building wheel for pudl (setup.py): finished with status 'done'
Stored in directory: /home/docs/checkouts/readthedocs.org/user_builds/catalyst-cooperative-pudl/.cache/pip/wheels/a4/5f/b6/1f8213aeb5876af1c140b54dce3466b845d989ca1101da875a
Building wheel for python-snappy (setup.py): started
Building wheel for python-snappy (setup.py): finished with status 'error'
ERROR: Complete output from command /home/docs/checkouts/readthedocs.org/user_builds/catalyst-cooperative-pudl/envs/python-packaging/bin/python -u -c 'import setuptools, tokenize;__file__='"'"'/tmp/pip-install-z6c1cop3/python-snappy/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-r54uwk2d --python-tag cp37:
ERROR: running bdist_wheel
running build
running build_py
creating build
creating build/lib.linux-x86_64-3.7
creating build/lib.linux-x86_64-3.7/snappy
copying snappy/__init__.py -> build/lib.linux-x86_64-3.7/snappy
copying snappy/snappy_cffi_builder.py -> build/lib.linux-x86_64-3.7/snappy
copying snappy/__main__.py -> build/lib.linux-x86_64-3.7/snappy
copying snappy/hadoop_snappy.py -> build/lib.linux-x86_64-3.7/snappy
copying snappy/snappy_formats.py -> build/lib.linux-x86_64-3.7/snappy
copying snappy/snappy.py -> build/lib.linux-x86_64-3.7/snappy
copying snappy/snappy_cffi.py -> build/lib.linux-x86_64-3.7/snappy
running build_ext
building 'snappy._snappy' extension
creating build/temp.linux-x86_64-3.7
creating build/temp.linux-x86_64-3.7/snappy
gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/home/docs/.pyenv/versions/3.7.3/include/python3.7m -c snappy/snappymodule.cc -o build/temp.linux-x86_64-3.7/snappy/snappymodule.o
snappy/snappymodule.cc:31:10: fatal error: snappy-c.h: No such file or directory
#include <snappy-c.h>
^~~~~~~~~~~~
compilation terminated.
error: command 'gcc' failed with exit status 1
----------------------------------------
ERROR: Failed building wheel for python-snappy
Running setup.py clean for python-snappy
Successfully built pudl
Failed to build python-snappy
python-snappy
is commented out of the requirements.txt
that is included in the documentation build, but of course it is still included in the project setup.py
in the install_requires
parameter.
Why is the mocking not working? How do I get it to stop trying to build this package that can't succeed? On my local system (which has the ``libsnappy-dev` package installed) the documentation build seems to work fine.
The full output from the failed build can be found here:
https://readthedocs.org/projects/catalyst-cooperative-pudl/builds/9376117/