Skip to content

Show rendered conf.py file in build logs #1651

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 14, 2015
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
107 changes: 59 additions & 48 deletions readthedocs/doc_builder/backends/sphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,59 +65,70 @@ def append_conf(self, **kwargs):

project = self.project
# Open file for appending.
outfile_path = project.conf_file(self.version.slug)
try:
outfile = codecs.open(project.conf_file(self.version.slug), encoding='utf-8', mode='a')
outfile = codecs.open(outfile_path, encoding='utf-8', mode='a')
except IOError:
trace = sys.exc_info()[2]
raise ProjectImportError('Conf file not found'), None, trace
outfile.write("\n")
conf_py_path = self.version.get_conf_py_path()
remote_version = self.version.get_vcs_slug()

github_user, github_repo = version_utils.get_github_username_repo(
url=self.project.repo)
github_version_is_editable = (self.version.type == 'branch')
display_github = github_user is not None

bitbucket_user, bitbucket_repo = version_utils.get_bitbucket_username_repo(
url=self.project.repo)
bitbucket_version_is_editable = (self.version.type == 'branch')
display_bitbucket = bitbucket_user is not None

rtd_ctx = {
'current_version': self.version.verbose_name,
'project': project,
'settings': settings,
'static_path': SPHINX_STATIC_DIR,
'template_path': SPHINX_TEMPLATE_DIR,
'conf_py_path': conf_py_path,
'api_host': getattr(settings, 'SLUMBER_API_HOST', 'https://readthedocs.org'),
# GitHub
'github_user': github_user,
'github_repo': github_repo,
'github_version': remote_version,
'github_version_is_editable': github_version_is_editable,
'display_github': display_github,
# BitBucket
'bitbucket_user': bitbucket_user,
'bitbucket_repo': bitbucket_repo,
'bitbucket_version': remote_version,
'bitbucket_version_is_editable': bitbucket_version_is_editable,
'display_bitbucket': display_bitbucket,
'commit': self.project.vcs_repo(self.version.slug).commit,
}

# Avoid hitting database and API if using Docker build environment
if getattr(settings, 'DONT_HIT_API', False):
rtd_ctx['versions'] = project.active_versions()
rtd_ctx['downloads'] = self.version.get_downloads(pretty=True)
else:
rtd_ctx['versions'] = project.api_versions()
rtd_ctx['downloads'] = (api.version(self.version.pk)
.get()['downloads'])
try:
outfile.write("\n")
conf_py_path = self.version.get_conf_py_path()
remote_version = self.version.get_vcs_slug()

github_user, github_repo = version_utils.get_github_username_repo(
url=self.project.repo)
github_version_is_editable = (self.version.type == 'branch')
display_github = github_user is not None

bitbucket_user, bitbucket_repo = version_utils.get_bitbucket_username_repo(
url=self.project.repo)
bitbucket_version_is_editable = (self.version.type == 'branch')
display_bitbucket = bitbucket_user is not None

rtd_ctx = {
'current_version': self.version.verbose_name,
'project': project,
'settings': settings,
'static_path': SPHINX_STATIC_DIR,
'template_path': SPHINX_TEMPLATE_DIR,
'conf_py_path': conf_py_path,
'api_host': getattr(settings, 'SLUMBER_API_HOST', 'https://readthedocs.org'),
# GitHub
'github_user': github_user,
'github_repo': github_repo,
'github_version': remote_version,
'github_version_is_editable': github_version_is_editable,
'display_github': display_github,
# BitBucket
'bitbucket_user': bitbucket_user,
'bitbucket_repo': bitbucket_repo,
'bitbucket_version': remote_version,
'bitbucket_version_is_editable': bitbucket_version_is_editable,
'display_bitbucket': display_bitbucket,
'commit': self.project.vcs_repo(self.version.slug).commit,
}

# Avoid hitting database and API if using Docker build environment
if getattr(settings, 'DONT_HIT_API', False):
rtd_ctx['versions'] = project.active_versions()
rtd_ctx['downloads'] = self.version.get_downloads(pretty=True)
else:
rtd_ctx['versions'] = project.api_versions()
rtd_ctx['downloads'] = (api.version(self.version.pk)
.get()['downloads'])

rtd_string = template_loader.get_template('doc_builder/conf.py.tmpl').render(rtd_ctx)
outfile.write(rtd_string)
rtd_string = template_loader.get_template('doc_builder/conf.py.tmpl').render(rtd_ctx)
outfile.write(rtd_string)
finally:
outfile.close()

# Print the contents of conf.py in order to make the rendered
# configfile visible in the build logs
self.run(
'cat', os.path.basename(outfile_path),
cwd=os.path.dirname(outfile_path),
)

def build(self, **kwargs):
self.clean()
Expand Down
14 changes: 14 additions & 0 deletions readthedocs/doc_builder/templates/doc_builder/conf.py.tmpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
{% load projects_tags %}


###########################################################################
# auto-created readthedocs.org specific configuration #
###########################################################################


#
# The following code was added during an automated build on readthedocs.org
# It is auto created and injected for every build. The result is based on the
# conf.py.tmpl file found in the readthedocs.org codebase:
# https://github.com/rtfd/readthedocs.org/blob/master/readthedocs/doc_builder/templates/doc_builder/conf.py.tmpl
#


import sys
from six import string_types

Expand Down