def get_version(project, version_pk): """Ensure we're using a sane version""" if version_pk: version_data = api_v2.version(version_pk).get() else: version_data = (api_v2.version( project.slug).get(slug=LATEST)['objects'][0]) return make_api_version(version_data)
def get_config_params(self): """Get configuration parameters to be rendered into the conf file.""" # TODO this should be handled better in the theme conf_py_path = os.path.join(os.path.sep, self.version.get_conf_py_path(), '') remote_version = self.version.commit_name 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 # Avoid hitting database and API if using Docker build environment if getattr(settings, 'DONT_HIT_API', False): versions = self.project.active_versions() downloads = self.version.get_downloads(pretty=True) else: versions = self.project.api_versions() downloads = api.version(self.version.pk).get()['downloads'] data = { 'current_version': self.version.verbose_name, 'project': self.project, 'settings': settings, 'static_path': SPHINX_STATIC_DIR, 'template_path': SPHINX_TEMPLATE_DIR, 'conf_py_path': conf_py_path, 'api_host': getattr(settings, 'PUBLIC_API_URL', 'https://readthedocs.org'), 'commit': self.project.vcs_repo(self.version.slug).commit, 'versions': versions, 'downloads': downloads, # 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, } finalize_sphinx_context_data.send( sender=self.__class__, build_env=self.build_env, data=data, ) return data
def get_version(project=None, version_pk=None): """ Retrieve version data from the API. :param project: project object to sync :type project: projects.models.Project :param version_pk: version pk to sync :type version_pk: int :returns: a data-complete version object :rtype: builds.models.APIVersion """ assert (project or version_pk), 'project or version_pk is needed' if version_pk: version_data = api_v2.version(version_pk).get() else: version_data = (api_v2.version( project.slug).get(slug=LATEST)['objects'][0]) return APIVersion(**version_data)
def get_version(project, version_pk): """Ensure we're using a sane version.""" if version_pk: version_data = api_v2.version(version_pk).get() else: version_data = (api_v2 .version(project.slug) .get(slug=LATEST)['objects'][0]) return APIVersion(**version_data)
def version_from_slug(slug, version): from readthedocs.builds.models import Version, APIVersion from readthedocs.restapi.client import api if getattr(settings, 'DONT_HIT_DB', True): version_data = api.version().get(project=slug, slug=version)['results'][0] v = APIVersion(**version_data) else: v = Version.objects.get(project__slug=slug, slug=version) return v
def version_from_slug(slug, version): from readthedocs.projects import tasks from readthedocs.builds.models import Version from readthedocs.restapi.client import api if getattr(settings, 'DONT_HIT_DB', True): version_data = api.version().get(project=slug, slug=version)['results'][0] v = tasks.make_api_version(version_data) else: v = Version.objects.get(project__slug=slug, slug=version) return v
def version_from_slug(slug, version): from readthedocs.builds.models import Version, APIVersion from readthedocs.restapi.client import api if settings.DONT_HIT_DB: version_data = api.version().get( project=slug, slug=version, )['results'][0] v = APIVersion(**version_data) else: v = Version.objects.get(project__slug=slug, slug=version) return v
def get_config_params(self): """Get configuration parameters to be rendered into the conf file.""" # TODO this should be handled better in the theme conf_py_path = os.path.join(os.path.sep, self.version.get_conf_py_path(), '') remote_version = self.version.commit_name 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 # Avoid hitting database and API if using Docker build environment if getattr(settings, 'DONT_HIT_API', False): versions = self.project.active_versions() downloads = self.version.get_downloads(pretty=True) else: versions = self.project.api_versions() downloads = api.version(self.version.pk).get()['downloads'] return { 'current_version': self.version.verbose_name, 'project': self.project, 'settings': settings, 'static_path': SPHINX_STATIC_DIR, 'template_path': SPHINX_TEMPLATE_DIR, 'conf_py_path': conf_py_path, 'api_host': getattr(settings, 'PUBLIC_API_URL', 'https://readthedocs.org'), 'commit': self.project.vcs_repo(self.version.slug).commit, 'versions': versions, 'downloads': downloads, # 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, }
def update_app_instances( self, html=False, localmedia=False, search=False, pdf=False, epub=False, ): """ Update application instances with build artifacts. This triggers updates across application instances for html, pdf, epub, downloads, and search. Tasks are broadcast to all web servers from here. """ # Update version if we have successfully built HTML output try: if html: version = api_v2.version(self.version.pk) version.patch({ 'built': True, }) except HttpClientError: log.exception( 'Updating version failed, skipping file sync: version=%s', self.version, ) # Broadcast finalization steps to web application instances broadcast( type='app', task=sync_files, args=[ self.project.pk, self.version.pk, self.config.doctype, ], kwargs=dict( hostname=socket.gethostname(), html=html, localmedia=localmedia, search=search, pdf=pdf, epub=epub, ), callback=sync_callback.s( version_pk=self.version.pk, commit=self.build['commit'], search=search, ), )
def update_app_instances(self, html=False, localmedia=False, search=False, pdf=False, epub=False): """Update application instances with build artifacts This triggers updates across application instances for html, pdf, epub, downloads, and search. Tasks are broadcast to all web servers from here. """ # Update version if we have successfully built HTML output try: if html: version = api_v2.version(self.version.pk) version.patch({ 'active': True, 'built': True, }) except HttpClientError as e: log.error( 'Updating version failed, skipping file sync: version=%s', self.version.pk, exc_info=True) else: # Broadcast finalization steps to web application instances broadcast(type='app', task=sync_files, args=[ self.project.pk, self.version.pk, ], kwargs=dict( hostname=socket.gethostname(), html=html, localmedia=localmedia, search=search, pdf=pdf, epub=epub, )) # Delayed tasks # TODO these should be chained on to the broadcast calls. The # broadcast calls could be lumped together into a promise, and on # task result, these next few tasks can be updated, also in a # chained fashion fileify.delay(self.version.pk, commit=self.build.get('commit')) update_search.delay(self.version.pk, commit=self.build.get('commit'))
def get_version(project=None, version_pk=None): """ Retrieve version data from the API. :param project: project object to sync :type project: projects.models.Project :param version_pk: version pk to sync :type version_pk: int :returns: a data-complete version object :rtype: builds.models.APIVersion """ assert (project or version_pk), 'project or version_pk is needed' if version_pk: version_data = api_v2.version(version_pk).get() else: version_data = (api_v2 .version(project.slug) .get(slug=LATEST)['objects'][0]) return APIVersion(**version_data)
def update_app_instances(self, html=False, localmedia=False, search=False, pdf=False, epub=False): """ Update application instances with build artifacts. This triggers updates across application instances for html, pdf, epub, downloads, and search. Tasks are broadcast to all web servers from here. """ # Update version if we have successfully built HTML output try: if html: version = api_v2.version(self.version.pk) version.patch({ 'active': True, 'built': True, }) except HttpClientError: log.exception( 'Updating version failed, skipping file sync: version=%s', self.version, ) # Broadcast finalization steps to web application instances broadcast( type='app', task=sync_files, args=[ self.project.pk, self.version.pk, ], kwargs=dict( hostname=socket.gethostname(), html=html, localmedia=localmedia, search=search, pdf=pdf, epub=epub, ), callback=sync_callback.s(version_pk=self.version.pk, commit=self.build['commit']), )
def get_config_params(self): """Get configuration parameters to be rendered into the conf file.""" # TODO this should be handled better in the theme conf_py_path = os.path.join( os.path.sep, self.version.get_conf_py_path(), '', ) remote_version = self.version.commit_name 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( # noqa url=self.project.repo) bitbucket_version_is_editable = (self.version.type == 'branch') display_bitbucket = bitbucket_user is not None gitlab_user, gitlab_repo = version_utils.get_gitlab_username_repo( url=self.project.repo) gitlab_version_is_editable = (self.version.type == 'branch') display_gitlab = gitlab_user is not None # Avoid hitting database and API if using Docker build environment if getattr(settings, 'DONT_HIT_API', False): versions = self.project.active_versions() downloads = self.version.get_downloads(pretty=True) else: versions = self.project.api_versions() downloads = api.version(self.version.pk).get()['downloads'] data = { 'current_version': self.version.verbose_name, 'project': self.project, 'version': self.version, 'settings': settings, 'static_path': SPHINX_STATIC_DIR, 'template_path': SPHINX_TEMPLATE_DIR, 'conf_py_path': conf_py_path, 'api_host': getattr( settings, 'PUBLIC_API_URL', 'https://readthedocs.org', ), 'commit': self.project.vcs_repo(self.version.slug).commit, 'versions': versions, 'downloads': downloads, # 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, # GitLab 'gitlab_user': gitlab_user, 'gitlab_repo': gitlab_repo, 'gitlab_version': remote_version, 'gitlab_version_is_editable': gitlab_version_is_editable, 'display_gitlab': display_gitlab, # Features 'generate_json_artifacts': self.project.has_feature(Feature.BUILD_JSON_ARTIFACTS_WITH_HTML), } finalize_sphinx_context_data.send( sender=self.__class__, build_env=self.build_env, data=data, ) return data
def update_imported_docs(version_pk): """ Check out or update the given project's repository :param version_pk: Version id to update """ version_data = api_v2.version(version_pk).get() version = make_api_version(version_data) project = version.project ret_dict = {} # Make Dirs if not os.path.exists(project.doc_path): os.makedirs(project.doc_path) if not project.vcs_repo(): raise ProjectImportError( ("Repo type '{0}' unknown".format(project.repo_type))) with project.repo_nonblockinglock(version=version, max_lock_age=getattr( settings, 'REPO_LOCK_SECONDS', 30)): # Get the actual code on disk try: before_vcs.send(sender=version) if version: log.info( LOG_TEMPLATE.format( project=project.slug, version=version.slug, msg='Checking out version {slug}: {identifier}'.format( slug=version.slug, identifier=version.identifier))) version_slug = version.slug version_repo = project.vcs_repo(version_slug) ret_dict['checkout'] = version_repo.checkout( version.identifier) else: # Does this ever get called? log.info( LOG_TEMPLATE.format(project=project.slug, version=version.slug, msg='Updating to latest revision')) version_slug = LATEST version_repo = project.vcs_repo(version_slug) ret_dict['checkout'] = version_repo.update() except Exception: raise finally: after_vcs.send(sender=version) # Update tags/version version_post_data = {'repo': version_repo.repo_url} if version_repo.supports_tags: version_post_data['tags'] = [{ 'identifier': v.identifier, 'verbose_name': v.verbose_name, } for v in version_repo.tags] if version_repo.supports_branches: version_post_data['branches'] = [{ 'identifier': v.identifier, 'verbose_name': v.verbose_name, } for v in version_repo.branches] try: api_v2.project(project.pk).sync_versions.post(version_post_data) except HttpClientError as e: log.error("Sync Versions Exception: %s", e.content) except Exception as e: log.error("Unknown Sync Versions Exception", exc_info=True) return ret_dict
def get_config_params(self): """Get configuration parameters to be rendered into the conf file.""" # TODO this should be handled better in the theme conf_py_path = os.path.join( os.path.sep, os.path.dirname( os.path.relpath( self.config_file, self.project.checkout_path(self.version.slug), ), ), '', ) remote_version = self.version.commit_name 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( # noqa url=self.project.repo, ) bitbucket_version_is_editable = (self.version.type == 'branch') display_bitbucket = bitbucket_user is not None gitlab_user, gitlab_repo = version_utils.get_gitlab_username_repo( url=self.project.repo, ) gitlab_version_is_editable = (self.version.type == 'branch') display_gitlab = gitlab_user is not None # Avoid hitting database and API if using Docker build environment if settings.DONT_HIT_API: versions = self.project.active_versions() downloads = self.version.get_downloads(pretty=True) else: versions = self.project.api_versions() downloads = api.version(self.version.pk).get()['downloads'] data = { 'html_theme': 'sphinx_rtd_theme', 'html_theme_import': 'sphinx_rtd_theme', 'current_version': self.version.verbose_name, 'project': self.project, 'version': self.version, 'settings': settings, 'conf_py_path': conf_py_path, 'api_host': settings.PUBLIC_API_URL, 'commit': self.project.vcs_repo(self.version.slug).commit, 'versions': versions, 'downloads': downloads, # 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, # GitLab 'gitlab_user': gitlab_user, 'gitlab_repo': gitlab_repo, 'gitlab_version': remote_version, 'gitlab_version_is_editable': gitlab_version_is_editable, 'display_gitlab': display_gitlab, # Features 'dont_overwrite_sphinx_context': self.project.has_feature( Feature.DONT_OVERWRITE_SPHINX_CONTEXT, ), 'use_pdf_latexmk': self.project.has_feature( Feature.USE_PDF_LATEXMK, ), } finalize_sphinx_context_data.send( sender=self.__class__, build_env=self.build_env, data=data, ) return data
def append_conf(self, **kwargs): """Modify the given ``conf.py`` file from a whitelisted user's project. """ # Pull config data try: conf_py_path = self.version.get_conf_py_path() except ProjectImportError: self._write_config() self.create_index(extension='rst') project = self.version.project # Open file for appending. try: outfile = codecs.open(project.conf_file(self.version.slug), 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.version.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.version.project.repo) bitbucket_version_is_editable = (self.version.type == 'branch') display_bitbucket = bitbucket_user is not None rtd_ctx = Context({ 'current_version': self.version.verbose_name, 'project': project, 'settings': settings, 'static_path': STATIC_DIR, 'template_path': 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.version.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)
def update_imported_docs(version_pk): """ Check out or update the given project's repository. :param version_pk: Version id to update """ version_data = api_v2.version(version_pk).get() version = APIVersion(**version_data) project = version.project ret_dict = {} # Make Dirs if not os.path.exists(project.doc_path): os.makedirs(project.doc_path) if not project.vcs_repo(): raise RepositoryError( _('Repository type "{repo_type}" unknown').format( repo_type=project.repo_type ) ) with project.repo_nonblockinglock( version=version, max_lock_age=getattr(settings, 'REPO_LOCK_SECONDS', 30)): # Get the actual code on disk try: before_vcs.send(sender=version) if version: log.info( LOG_TEMPLATE.format( project=project.slug, version=version.slug, msg='Checking out version {slug}: {identifier}'.format( slug=version.slug, identifier=version.identifier ) ) ) version_slug = version.slug version_repo = project.vcs_repo(version_slug) ret_dict['checkout'] = version_repo.checkout(version.identifier) else: # Does this ever get called? log.info(LOG_TEMPLATE.format( project=project.slug, version=version.slug, msg='Updating to latest revision')) version_slug = LATEST version_repo = project.vcs_repo(version_slug) ret_dict['checkout'] = version_repo.update() finally: after_vcs.send(sender=version) # Update tags/version version_post_data = {'repo': version_repo.repo_url} if version_repo.supports_tags: version_post_data['tags'] = [ {'identifier': v.identifier, 'verbose_name': v.verbose_name, } for v in version_repo.tags ] if version_repo.supports_branches: version_post_data['branches'] = [ {'identifier': v.identifier, 'verbose_name': v.verbose_name, } for v in version_repo.branches ] try: api_v2.project(project.pk).sync_versions.post(version_post_data) except HttpClientError: log.exception("Sync Versions Exception") except Exception: log.exception("Unknown Sync Versions Exception") return ret_dict
def append_conf(self, **kwargs): """Modify the given ``conf.py`` file from a whitelisted user's project. """ # Pull config data try: conf_py_path = self.version.get_conf_py_path() except ProjectImportError: master_doc = self.create_index(extension='rst') self._write_config(master_doc=master_doc) project = self.project # Open file for appending. outfile_path = project.conf_file(self.version.slug) try: 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 try: outfile.write("\n") # TODO this should be handled better in the theme conf_py_path = os.path.join(os.path.sep, self.version.get_conf_py_path(), '') remote_version = self.version.commit_name 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, 'PUBLIC_API_URL', '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) 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 append_conf(self, **kwargs): """Modify the given ``conf.py`` file from a whitelisted user's project. """ # Pull config data try: conf_py_path = self.version.get_conf_py_path() except ProjectImportError: master_doc = self.create_index(extension='rst') self._write_config(master_doc=master_doc) project = self.project # Open file for appending. outfile_path = project.conf_file(self.version.slug) try: 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 try: outfile.write("\n") # TODO this should be handled better in the theme conf_py_path = os.path.join(os.path.sep, self.version.get_conf_py_path(), '') remote_version = self.version.commit_name 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, 'PUBLIC_API_URL', '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) 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 append_conf(self, **kwargs): """Modify the given ``conf.py`` file from a whitelisted user's project. """ # Pull config data try: conf_py_path = self.version.get_conf_py_path() except ProjectImportError: master_doc = self.create_index(extension="rst") self._write_config(master_doc=master_doc) project = self.project # Open file for appending. outfile_path = project.conf_file(self.version.slug) try: 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 try: outfile.write("\n") # TODO this should be handled better in the theme conf_py_path = os.path.join(os.path.sep, self.version.get_conf_py_path(), "") remote_version = self.version.commit_name 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) 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 get_config_params(self): """Get configuration parameters to be rendered into the conf file.""" # TODO this should be handled better in the theme conf_py_path = os.path.join( os.path.sep, os.path.dirname( os.path.relpath( self.config_file, self.project.checkout_path(self.version.slug), ), ), '', ) remote_version = self.version.commit_name 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( # noqa url=self.project.repo, ) bitbucket_version_is_editable = (self.version.type == 'branch') display_bitbucket = bitbucket_user is not None gitlab_user, gitlab_repo = version_utils.get_gitlab_username_repo( url=self.project.repo, ) gitlab_version_is_editable = (self.version.type == 'branch') display_gitlab = gitlab_user is not None # Avoid hitting database and API if using Docker build environment if getattr(settings, 'DONT_HIT_API', False): versions = self.project.active_versions() downloads = self.version.get_downloads(pretty=True) else: versions = self.project.api_versions() downloads = api.version(self.version.pk).get()['downloads'] data = { 'html_theme': 'sphinx_rtd_theme', 'html_theme_import': 'sphinx_rtd_theme', 'current_version': self.version.verbose_name, 'project': self.project, 'version': self.version, 'settings': settings, 'conf_py_path': conf_py_path, 'api_host': getattr( settings, 'PUBLIC_API_URL', 'https://readthedocs.org', ), 'commit': self.project.vcs_repo(self.version.slug).commit, 'versions': versions, 'downloads': downloads, # 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, # GitLab 'gitlab_user': gitlab_user, 'gitlab_repo': gitlab_repo, 'gitlab_version': remote_version, 'gitlab_version_is_editable': gitlab_version_is_editable, 'display_gitlab': display_gitlab, # Features 'dont_overwrite_sphinx_context': self.project.has_feature(Feature.DONT_OVERWRITE_SPHINX_CONTEXT, ), } finalize_sphinx_context_data.send( sender=self.__class__, build_env=self.build_env, data=data, ) return data