better-apidoc
better-apidoc copied to clipboard
UnboundLocalError: local variable 'package_ns' referenced before assignment
VERSION: better-apidoc 0.1.4
Whenever I run:
better-apidoc -t ./_templates -f ../song_match -o song_match
I get the following error:
WARNING: failed to import 'song_match': No module named 'song_match'
Traceback (most recent call last):
File "/home/g/anaconda3/bin/better-apidoc", line 11, in <module>
sys.exit(main())
File "/home/g/anaconda3/lib/python3.6/site-packages/better_apidoc.py", line 604, in main
modules = recurse_tree(rootpath, excludes, opts)
File "/home/g/anaconda3/lib/python3.6/site-packages/better_apidoc.py", line 462, in recurse_tree
py_files, opts, subs, is_namespace)
File "/home/g/anaconda3/lib/python3.6/site-packages/better_apidoc.py", line 365, in create_package_file
text = template.render(**package_ns)
UnboundLocalError: local variable 'package_ns' referenced before assignment
Not sure what I'm doing wrong.
I run the command within ./docs. Here's a snippet of my package structure.
.
├── docs
│ └── _templates
│ ├── module.rst
│ └── package.rst
├── song_match
│ ├── config.py
... The rest is omitted
Whenever I try sphinx-apidoc -f ../song_match -o song_match it works fine.
Any help?
Same here. Thanks for reporting.
Did a little digging. The issue is it's failing to import my song_match module. The WARNING it gives is a critical failure. This is probably because the module is not in sys.path.
I have the following in conf.py though:
sys.path.insert(0, os.path.abspath('.'))
sys.path.insert(0, os.path.abspath('../'))
So I'm still confused. For now, I found a workaround.
Workaround
I added the following to my conf.py, as this is what @goerz does in the QNET conf.py.
# -- Generate API documentation ------------------------------------------------
def run_apidoc(_):
"""Generage API documentation"""
import better_apidoc
better_apidoc.main(
['better-apidoc', '-t', './_templates', '--force', '--no-toc',
'--separate', '-o', './song_match', '../song_mtach'])
def setup(app):
app.connect('builder-inited', run_apidoc)
Works like a charm!