Skip to content

Fix logic involving creation of Sphinx Domains #5997

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 5 commits into from
Jul 26, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
24 changes: 24 additions & 0 deletions readthedocs/projects/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1396,10 +1396,34 @@ def warn(self, msg):
f'domain->name',
)
continue

# HACK: This is done because the difference between
# ``sphinx.builders.html.StandaloneHTMLBuilder``
# and ``sphinx.builders.dirhtml.DirectoryHTMLBuilder``.
# They both have different ways of generating HTML Files,
# and therefore the doc_name generated is different.
# More info on: http://www.sphinx-doc.org/en/master/usage/builders/index.html#builders
# Also see issue: https://github.com/readthedocs/readthedocs.org/issues/5821
if doc_name.endswith('/'):
doc_name += 'index.html'

html_file = HTMLFile.objects.filter(
project=version.project, version=version,
path=doc_name, build=build,
).first()

if not html_file:
log.debug('[%s] [%s] [Build: %s] HTMLFile object not found. File: %s' % (
version.project,
version,
build,
doc_name,
))

# Don't create Sphinx Domain objects
# if the HTMLFile object is not found.
continue

SphinxDomain.objects.create(
project=version.project,
version=version,
Expand Down
51 changes: 34 additions & 17 deletions readthedocs/search/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,23 +111,40 @@ class Meta:

def prepare_domains(self, html_file):
"""Prepares and returns the values for domains field."""
domains_qs = html_file.sphinx_domains.exclude(
domain='std',
type__in=['doc', 'label']
).iterator()

all_domains = [
{
'role_name': domain.role_name,
'doc_name': domain.doc_name,
'anchor': domain.anchor,
'type_display': domain.type_display,
'doc_display': domain.doc_display,
'name': domain.name,
'display_name': domain.display_name if domain.display_name != '-' else '',
}
for domain in domains_qs
]
all_domains = []

try:
domains_qs = html_file.sphinx_domains.exclude(
domain='std',
type__in=['doc', 'label']
).iterator()

all_domains = [
{
'role_name': domain.role_name,
'doc_name': domain.doc_name,
'anchor': domain.anchor,
'type_display': domain.type_display,
'doc_display': domain.doc_display,
'name': domain.name,
'display_name': domain.display_name if domain.display_name != '-' else '',
}
for domain in domains_qs
]

log.debug("[%s] [%s] Domains for file %s are: %s" % (
html_file.project.slug,
html_file.version.slug,
html_file.path,
all_domains,
))

except Exception:
log.exception("[%s] [%s] Error preparing domain data for file %s" % (
html_file.project.slug,
html_file.version.slug,
html_file.path,
))

return all_domains

Expand Down