2017-02-09 81 views
1

我有一個名爲gaend的Google App Engine項目。我正在嘗試使用readthedocs爲其構建更好的文檔。我已經使用如何爲Google App Engine項目構建sphinx(readthedocs)文檔?

> sphinx-quickstart 

建立我的基地sphinx項目。跟着

> sphinx-apidoc -o . ../gaend 

生成項目的API列表。然後我運行

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 

我認識到問題在於它無法訪問Google Cloud SDK。我在運行單元測試時遇到了類似的問題,並且要做到這一點的工作是runner.py。但是,這依賴於我的系統上安裝了Google Cloud SDK(安裝了Python Google App Engine模塊)。我如何在構建文檔的readthedocs服務器上獲得Google Cloud SDK(和Python GAE)?

回答

1

我同樣的問題,我不記得在那裏我找到了解決辦法,也許不會解決您的問題,但我解決了我的加入google_appengine文件夾和google_appengine/lib/yam/lib文件夾的路徑conf.py文件在源文件夾內獅身人面像doc文件夾中,這樣的事情:

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'] 

我知道,這將是相對路徑更好,但它爲我工作。

獅身人面像需要運行你正在記錄的程序是我不明白,但無論如何,是一個很好的工具。

+0

感謝胡安,我做https://github.com/samedhi/gaend/commit/d279e0ada41c2225b23498a6bb7ddba94ae624e5。在當地工作,但當readthedocs試圖在他們的服務器上構建我的文檔時,當然會失敗......也許我缺少一個步驟或什麼? –

0

我剛剛解決了同樣的問題。不會有太多的問題詢問有關獅身人面像+ GAE,所以我張貼conf.py代碼,得到它的希望工作對於我來說,幫助別人:

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() 
相關問題