jeudi 25 juin 2020

Sphinx will not import all modules and is hanging up on random.choice()

I'm having a hard time with Sphinx where it won't import all the modules. There error it is encountering reads as follows:

  File “file path”, line 36, in Individual
    ml_params = {'C': random.choice(svr_C), 'gamma': random.choice(svr_gamma)}
  File "/usr/local/Cellar/sphinx-doc/3.1.1/libexec/lib/python3.8/random.py", line 290, in choice
    raise IndexError('Cannot choose from an empty sequence') from None
IndexError: Cannot choose from an empty sequence

I set sphinx up per the instructions in the following post: Getting Started with Sphinx...

I have followed the recommended steps in the layout and it works well for the most part, except that it gets hung up on random.choice() from random.py. The python code runs without error and does not hang up on random.choice() from random.py.

In the python code, this is how random.choice is used:

svr_C = list(np.linspace(50, 300, 10))
svr_gamma = list(np.logspace(-4, -2, 3))

ml_params = {'C': random.choice(svr_C), 'gamma': random.choice(svr_gamma)}

I need to ignore numpy in the conf.py file, otherwise Sphinx will hang up on the numpy import. I don't know why Sphinx sees this 'np.linspace(50,300,10)' as an empty sequence. Seems like I need a way to convince Sphinx that random.choice() is in fact not empty.

My conf.py is set up as follows:

import os
import sys
sys.path.insert(0, os.path.abspath(os.path.join('..', '..')))

extensions = ['sphinx.ext.autodoc']
autodoc_mock_imports = ["matplotlib", "pandas", "scipy", "statsmodels", "numpy", "xlrd", "sklearn", "fpdf", "rpy2", "joblib", "pathos", "fire", "psutil"]

The file/directory structure:

.
├── Makefile
├── build
│   ├── doctrees
│   │   ├── src_lib.doctree
│   │   ├── environment.pickle
│   │   ├── index.doctree
│   │   └── modules.doctree
│   └── html
│       ├── _sources
│       │   ├── agora_lib.rst.txt
│       │   ├── index.rst.txt
│       │   └── modules.rst.txt
│       ├── _static
│       │   ├── numerous_css_files.css
│       │   ├── numerous_js_files.js
│       │   ├── 1.js
│       │   └── underscore.js
│       ├── src_lib.html
│       ├── genindex.html
│       ├── index.html
│       ├── modules.html
│       ├── objects.inv
│       ├── py-modindex.html
│       ├── search.html
│       └── searchindex.js
├── make.bat
└── source
    ├── _static
    ├── _templates
    ├── src_lib.rst
    ├── conf.py
    ├── index.rst
    └── modules.rst



Aucun commentaire:

Enregistrer un commentaire