1
- import json
2
1
from fnmatch import fnmatch
3
2
4
3
import structlog
5
- from django .conf import settings
6
- from sphinx .ext import intersphinx
7
4
8
5
from readthedocs .builds .constants import EXTERNAL
9
6
from readthedocs .builds .models import Version
10
- from readthedocs .projects .models import Feature , HTMLFile , ImportedFile , Project
7
+ from readthedocs .projects .models import HTMLFile , ImportedFile , Project
11
8
from readthedocs .projects .signals import files_changed
12
9
from readthedocs .search .utils import index_new_files , remove_indexed_files
13
- from readthedocs .sphinx_domains .models import SphinxDomain
14
10
from readthedocs .storage import build_media_storage
15
11
from readthedocs .worker import app
16
12
@@ -54,14 +50,6 @@ def fileify(version_pk, commit, build, search_ranking, search_ignore):
54
50
except Exception :
55
51
log .exception ('Failed during ImportedFile creation' )
56
52
57
- # XXX: Don't access the sphinx domains table while we migrate the ID type
58
- # https://github.com/readthedocs/readthedocs.org/pull/9482.
59
- if not project .has_feature (Feature .DISABLE_SPHINX_DOMAINS ):
60
- try :
61
- _create_intersphinx_data (version , commit , build )
62
- except Exception :
63
- log .exception ("Failed during SphinxDomain creation" )
64
-
65
53
try :
66
54
_sync_imported_files (version , build )
67
55
except Exception :
@@ -88,18 +76,6 @@ def _sync_imported_files(version, build):
88
76
build_id = build ,
89
77
)
90
78
91
- # Delete SphinxDomain objects from previous versions
92
- # This has to be done before deleting ImportedFiles and not with a cascade,
93
- # because multiple Domain's can reference a specific HTMLFile.
94
- # XXX: Don't access the sphinx domains table while we migrate the ID type
95
- # https://github.com/readthedocs/readthedocs.org/pull/9482.
96
- if not project .has_feature (Feature .DISABLE_SPHINX_DOMAINS ):
97
- (
98
- SphinxDomain .objects .filter (project = project , version = version )
99
- .exclude (build = build )
100
- .delete ()
101
- )
102
-
103
79
# Delete ImportedFiles objects (including HTMLFiles)
104
80
# from the previous build of the version.
105
81
(
@@ -119,132 +95,6 @@ def remove_search_indexes(project_slug, version_slug=None):
119
95
)
120
96
121
97
122
- def _create_intersphinx_data (version , commit , build ):
123
- """
124
- Create intersphinx data for this version.
125
-
126
- :param version: Version instance
127
- :param commit: Commit that updated path
128
- :param build: Build id
129
- """
130
- if not version .is_sphinx_type :
131
- return
132
-
133
- html_storage_path = version .project .get_storage_path (
134
- type_ = 'html' , version_slug = version .slug , include_file = False
135
- )
136
- json_storage_path = version .project .get_storage_path (
137
- type_ = 'json' , version_slug = version .slug , include_file = False
138
- )
139
-
140
- object_file = build_media_storage .join (html_storage_path , 'objects.inv' )
141
- if not build_media_storage .exists (object_file ):
142
- log .debug ('No objects.inv, skipping intersphinx indexing.' )
143
- return
144
-
145
- type_file = build_media_storage .join (json_storage_path , 'readthedocs-sphinx-domain-names.json' )
146
- types = {}
147
- titles = {}
148
- if build_media_storage .exists (type_file ):
149
- try :
150
- data = json .load (build_media_storage .open (type_file ))
151
- types = data ['types' ]
152
- titles = data ['titles' ]
153
- except Exception :
154
- log .exception ('Exception parsing readthedocs-sphinx-domain-names.json' )
155
-
156
- # These classes are copied from Sphinx
157
- # https://github.com/sphinx-doc/sphinx/blob/d79d041f4f90818e0b495523fdcc28db12783caf/sphinx/ext/intersphinx.py#L400-L403 # noqa
158
- class MockConfig :
159
- intersphinx_timeout = None
160
- tls_verify = False
161
- user_agent = None
162
-
163
- class MockApp :
164
- srcdir = ''
165
- config = MockConfig ()
166
-
167
- def warn (self , msg ):
168
- log .warning ('Sphinx MockApp.' , msg = msg )
169
-
170
- # Re-create all objects from the new build of the version
171
- object_file_url = build_media_storage .url (object_file )
172
- if object_file_url .startswith ('/' ):
173
- # Filesystem backed storage simply prepends MEDIA_URL to the path to get the URL
174
- # This can cause an issue if MEDIA_URL is not fully qualified
175
- object_file_url = settings .RTD_INTERSPHINX_URL + object_file_url
176
-
177
- invdata = intersphinx .fetch_inventory (MockApp (), '' , object_file_url )
178
- for key , value in sorted (invdata .items () or {}):
179
- domain , _type = key .split (':' , 1 )
180
- for name , einfo in sorted (value .items ()):
181
- # project, version, url, display_name
182
- # ('Sphinx', '1.7.9', 'faq.html#epub-faq', 'Epub info')
183
- try :
184
- url = einfo [2 ]
185
- if '#' in url :
186
- doc_name , anchor = url .split (
187
- '#' ,
188
- # The anchor can contain ``#`` characters
189
- maxsplit = 1
190
- )
191
- else :
192
- doc_name , anchor = url , ''
193
- display_name = einfo [3 ]
194
- except Exception :
195
- log .exception (
196
- 'Error while getting sphinx domain information. Skipping...' ,
197
- project_slug = version .project .slug ,
198
- version_slug = version .slug ,
199
- sphinx_domain = f"{ domain } ->{ name } " ,
200
- )
201
- continue
202
-
203
- # HACK: This is done because the difference between
204
- # ``sphinx.builders.html.StandaloneHTMLBuilder``
205
- # and ``sphinx.builders.dirhtml.DirectoryHTMLBuilder``.
206
- # They both have different ways of generating HTML Files,
207
- # and therefore the doc_name generated is different.
208
- # More info on: http://www.sphinx-doc.org/en/master/usage/builders/index.html#builders
209
- # Also see issue: https://github.com/readthedocs/readthedocs.org/issues/5821
210
- if doc_name .endswith ('/' ):
211
- doc_name += 'index.html'
212
-
213
- html_file = HTMLFile .objects .filter (
214
- project = version .project , version = version ,
215
- path = doc_name , build = build ,
216
- ).first ()
217
-
218
- if not html_file :
219
- log .debug (
220
- 'HTMLFile object not found.' ,
221
- project_slug = version .project .slug ,
222
- version_slug = version .slug ,
223
- build_id = build ,
224
- doc_name = doc_name
225
- )
226
-
227
- # Don't create Sphinx Domain objects
228
- # if the HTMLFile object is not found.
229
- continue
230
-
231
- SphinxDomain .objects .create (
232
- project = version .project ,
233
- version = version ,
234
- html_file = html_file ,
235
- domain = domain ,
236
- name = name ,
237
- display_name = display_name ,
238
- type = _type ,
239
- type_display = types .get (f'{ domain } :{ _type } ' , '' ),
240
- doc_name = doc_name ,
241
- doc_display = titles .get (doc_name , '' ),
242
- anchor = anchor ,
243
- commit = commit ,
244
- build = build ,
245
- )
246
-
247
-
248
98
def _create_imported_files (* , version , commit , build , search_ranking , search_ignore ):
249
99
"""
250
100
Create imported files for version.
0 commit comments