Skip to content
This repository has been archived by the owner on Nov 5, 2019. It is now read-only.

Using mock App Engine module when building docs. #432

Merged
merged 1 commit into from
Feb 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 30 additions & 19 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,31 @@
from pkg_resources import get_distribution
import sys

import mock

# See
# (http://read-the-docs.readthedocs.org/en/latest/faq.html#\
# i-get-import-errors-on-libraries-that-depend-on-c-modules)

class Mock(mock.Mock):

@classmethod
def __getattr__(cls, name):
return Mock()


MOCK_MODULES = (
'google',
'google.appengine',
'google.appengine.api',
'google.appengine.api.app_identiy',
'google.appengine.api.urlfetch',
'google.appengine.ext',
'google.appengine.ext.webapp',
'google.appengine.ext.webapp.util',
)


# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
Expand Down Expand Up @@ -40,32 +65,18 @@
# settings module and load it. This assumes django has been installed
# (but it must be for the docs to build), so if it has not already
# been installed run `pip install -r docs/requirements.txt`.
os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.contrib.test_django_settings'
import django
if django.VERSION[1] < 7:
sys.path.insert(0, '.')
os.environ['DJANGO_SETTINGS_MODULE'] = 'django_settings'

# -- Options for HTML output ----------------------------------------------

# We fake our more expensive imports when building the docs.
sys.modules.update((mod_name, Mock()) for mod_name in MOCK_MODULES)

# We want to set the RTD theme, but not if we're on RTD.
if os.environ.get('READTHEDOCS', None) == 'True':
# Download the GAE SDK if we are building on READTHEDOCS.
docs_dir = os.path.dirname(os.path.abspath(__file__))
root_dir = os.path.abspath(os.path.join(docs_dir, '..'))
gae_dir = os.path.join(root_dir, 'google_appengine')
if not os.path.isdir(gae_dir):
scripts_dir = os.path.join(root_dir, 'scripts')
sys.path.append(scripts_dir)
import fetch_gae_sdk
# The first argument is the script name and the second is
# the destination dir (where google_appengine is downloaded).
result = fetch_gae_sdk.main([None, root_dir])
if result not in (0, None):
sys.stderr.write('Result failed %d\n' % (result,))
sys.exit(result)
# Allow imports from the GAE directory as well.
sys.path.append(gae_dir)
else:
if os.environ.get('READTHEDOCS', None) != 'True':
import sphinx_rtd_theme
html_theme = 'sphinx_rtd_theme'
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
Expand Down
1 change: 0 additions & 1 deletion docs/django_settings.py

This file was deleted.

1 change: 1 addition & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
django
flask
keyring
mock
pycrypto>=2.6
pyopenssl>=0.14
python-gflags
Expand Down
7 changes: 1 addition & 6 deletions scripts/build_docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Build the oauth2client docs, installing the GAE SDK as needed.
# Build the oauth2client docs.

set -e

if [[ -z "${SKIP_GAE_SDK}" ]]; then
scripts/fetch_gae_sdk.py
export PYTHONPATH="${PWD}/google_appengine:${PYTHONPATH}"
fi

rm -rf docs/_build/* docs/source/*
sphinx-apidoc --separate --force -o docs/source oauth2client
# We only have one package, so modules.rst is overkill.
Expand Down