0

I am trying to generate API documentation from comments (in numpydoc style) in my project and I am stuck at vague import errors from sphinx:

/home/carbolymer/workspace/si-app/doc/source/scripts.rst:10: WARNING: autodoc: failed to import module 'scripts.backtest'; the following exception was raised:
Traceback (most recent call last):
  File "/usr/lib/python3.5/site-packages/sphinx/ext/autodoc.py", line 547, in import_object
    __import__(self.modname)
  File "/home/carbolymer/workspace/si-app/application/scripts/backtest.py", line 6, in <module>
    from scipy import stats
  File "/usr/lib/python3.5/site-packages/scipy/__init__.py", line 64, in <module>
    from numpy import __version__ as __numpy_version__
ImportError: cannot import name '__version__'
/home/carbolymer/workspace/si-app/doc/source/scripts.rst:18: WARNING: autodoc: failed to import module 'scripts.importdb'; the following exception was raised:
Traceback (most recent call last):
  File "/usr/lib/python3.5/site-packages/sphinx/ext/autodoc.py", line 547, in import_object
    __import__(self.modname)
  File "/home/carbolymer/workspace/si-app/application/scripts/importdb.py", line 5, in <module>
    from si.storage.dataimport import DataImport, database_drivers, sources
  File "/home/carbolymer/workspace/si-app/application/si/storage/dataimport.py", line 6, in <module>
    from si.storage.datasource.file import Stooq as StooqFile
  File "/home/carbolymer/workspace/si-app/application/si/storage/datasource/file.py", line 19, in <module>
    from si.storage.datasource.util import correct_prices
  File "/home/carbolymer/workspace/si-app/application/si/storage/datasource/util.py", line 4, in <module>
    def correct_prices(dataframe, calendar=PolishCalendar()):
  File "/usr/lib/python3.5/unittest/mock.py", line 917, in __call__
    return _mock_self._mock_call(*args, **kwargs)
  File "/usr/lib/python3.5/unittest/mock.py", line 976, in _mock_call
    result = next(effect)
StopIteration

Full log:

http://pastebin.com/tycmVQdN

I've tried mocking numpy.__version__ but it does not work. Also I have no clue what about the lines containing PolishCalendar() - why sphinx is trying to mock this object?

Because of those import errors, these files are missing in the documentation. How can I fix this?

My build command:

make clean ; sphinx-apidoc -a -f -o ./source ../application ; make html

Versions:

$ sphinx-build --version
Sphinx (sphinx-build) 1.5.1
$ python --version                                                        
Python 3.5.2

source/conf.py: http://pastebin.com/VfsiX4uZ

carbolymer
  • 1,439
  • 1
  • 15
  • 30
  • `which python`, `which sphinx-build` ? – Pierre de Buyl Dec 27 '16 at 12:37
  • @PierredeBuyl http://pastebin.com/Uy5hMNum – carbolymer Dec 27 '16 at 13:53
  • Thank you, this means that you are using system's Python and system's sphinx. What is your OS? Also, can you give the output of `python -c 'import numpy ; print(numpy.__version__)` – Pierre de Buyl Dec 27 '16 at 20:16
  • @PierredeBuyl `python -c 'import numpy ; print(numpy.__version__)'` gives `1.11.2` – carbolymer Dec 28 '16 at 15:23
  • This really is unusual. What is your OS and how did you install Python/NumPy/SciPy ? – Pierre de Buyl Dec 28 '16 at 17:50
  • @PierredeBuyl it is Arch Linux and I've installed python, numpy and scipy via package manager. What is so unusual about this configuration? – carbolymer Dec 28 '16 at 19:32
  • What is unusual is that you can import python from the command-line but that it fails to import in sphinx. The problem here is the `ImportError`: NumPy cannot be imported and this occurs in the build of the doc where SciPy is imported. Do you have a file named `numpy.py` or a directory named `numpy` in your project? (Sorry for the multiple steps, I am trying different ideas...). – Pierre de Buyl Dec 28 '16 at 20:37
  • @PierredeBuyl It's ok. I really appreciate that you're trying to help me. :) No, I don't have any directory/package/file named numpy or numpy.py. Maybe I am doing something wrong with the mocking? – carbolymer Dec 28 '16 at 23:13
  • 1
    Are the messages above obtained with mocking? If so, what do you mean by that? A minimal working example would be welcome at this point. (I asked about directory/package/file because that can lead to `import numpy` not actually importing the actual numpy package. – Pierre de Buyl Dec 29 '16 at 21:09
  • @PierreBuyl I suppose so. I've attached config.py in which i've mocked libraries which I use to avoid including them in the generated documentation. – carbolymer Jan 02 '17 at 17:22

0 Answers0