Reputation: 14544
I have a Google App Engine project named gaend. I am attempting to build better documentation for it using readthedocs. I have used
> sphinx-quickstart
to build my base sphinx project. Followed by
> sphinx-apidoc -o . ../gaend
to generate a API list of the project. I then run
sphinx-autobuild . _build/html
+--------- manually triggered build ---------------------------------------------
| Running Sphinx v1.5.2
| loading pickled environment... done
| building [mo]: targets for 0 po files that are out of date
| building [html]: targets for 0 source files that are out of date
| updating environment: 0 added, 1 changed, 0 removed
| reading sources... [100%] gaend
/Users/stephen/gaend/docs/gaend.rst:10: WARNING: autodoc: failed to import module u'gaend.bigquery'; the following exception was raised:
Traceback (most recent call last):
File "/Users/stephen/.virtualenvs/gaend/lib/python2.7/site-packages/sphinx/ext/autodoc.py", line 551, in import_object
__import__(self.modname)
File "/Users/stephen/gaend/gaend/bigquery.py", line 1, in <module>
from google.cloud import bigquery
ImportError: No module named google.cloud
...
ImportError: No module named google.appengine.ext
I recognize that the problem is that it does not have access to the Google Cloud SDK. I have had similar issues with running my unit test, and the work around to doing this is in runner.py. However, this relies on having the Google Cloud SDK (with the Python Google App Engine module installed) somewhere on my system. How am I going to get the Google Cloud SDK (and Python GAE) on the readthedocs server that build my documentation?
Upvotes: 1
Views: 681
Reputation: 5276
I just solved the same issue. There are not many questions asking about Sphinx + GAE, so I'm posting the conf.py
code that got it working for me in the hopes it helps others:
import os
import sys
project_id = 'gae-project-id'
# environment variables that several utils are assuming are present
if not os.environ.get('SERVER_SOFTWARE', None):
os.environ['SERVER_SOFTWARE'] = 'Development-'+project_id
if not os.environ.get('APPLICATION_ID', None):
os.environ['APPLICATION_ID'] = 'dev~'+project_id
# project root
sys.path.insert(0, os.path.dirname(__file__))
# downloaded third party libs
sys.path.insert(0, os.path.dirname(__file__)+"/lib")
# path to gae sdk
sdk_path = os.path.join('~/google-cloud-sdk', 'platform/google_appengine')
try:
import google
google.__path__.append("{0}/google".format(sdk_path))
except ImportError:
pass
sys.path.insert(0, os.path.expanduser(sdk_path))
import dev_appserver
dev_appserver.fix_sys_path()
Upvotes: 0
Reputation: 2604
I was the same problem, I don't remember where I found the solution and maybe don't fix your problem but I solved mine adding the path of google_appengine
folder and google_appengine/lib/yam/lib
folder in conf.py
file in your source folder inside of Sphinx doc folder, something like this:
In conf.py
:
sys.path.insert(0, os.path.abspath('../../'))
sys.path.insert(1, '<your local full path>/google_appengine')
sys.path.insert(1, '<your local full path>/google_appengine/lib/yaml/lib')
if 'google' in sys.modules:
del sys.modules['google']
I know that it would be better with relative path but it worked for me.
That Sphinx need run the program that you are documenting is something that I don't understand fine but anyway, is a good tool.
Upvotes: 1