Search code examples
pythondockerjenkinspython-sphinxautodoc

Execute sphinx on a non-working Python script


I am trying to learn Docker.

I have a Python script that uses mod library which IS NOT installed on my system. The goal is to execute it inside a Docker container. I wrote the Dockerfile. I added this line inside it:

RUN pip install --trusted-host pypi.python.org -r requirements.txt

And in requirements.txt i wrote mod.

It worked and inside the container it installs mod and the code works well.

Now, I want to generate Sphinx doc on the same script. I know how Sphinx works (the basics). I modified conf.py with sys.path.insert(0, os.path.abspath('..')) and it points to the directory that contains Script.py (alongside Dockerfile and requirements.txt) and then I added the following inside index.rst: Script.py is inside a folder named DockerPython:

.. automodule:: DockerPython.Script
   :members:

When I launch make html (which works fine with other examples) I get the following:

Running Sphinx v2.0.1
making output directory... done
building [mo]: targets for 0 po files that are out of date
building [html]: targets for 1 source files that are out of date
updating environment: 1 added, 0 changed, 0 removed
reading sources... [100%] index
WARNING: autodoc: failed to import module 'Script' from module 'DockerPython'; the following exception was raised:
No module named 'mod'
looking for now-outdated files... none found
pickling environment... done
checking consistency... done
preparing documents... done
writing output... [100%] index
generating indices... genindex
writing additional pages... search
copying static files... done
copying extra files... done
dumping search index in English (code: en) ... done
dumping object inventory... done
build succeeded, 1 warning.

The HTML pages are in build\html.

And the page that I get is empty.

So, my question is: Can Sphinx be executed on a Script that doesn't compile and run well on local Python (because a lib is not installed locally)?

How do I get it to work on a script that works via Docker with specific settings? Thank you.


Solution

  • After two hours of surfing I just figured it out.

    I only had to add this line to conf.py:

    autodoc_mock_imports = ['mod']