10
10
from pathlib import Path
11
11
12
12
import structlog
13
- from django .conf import settings
14
- from django .template import loader as template_loader
15
- from django .urls import reverse
16
- from requests .exceptions import ConnectionError
17
-
18
- from readthedocs .builds import utils as version_utils
19
- from readthedocs .builds .models import APIVersion
20
- from readthedocs .core .utils .filesystem import safe_open
21
- from readthedocs .projects .constants import OLD_LANGUAGES_CODE_MAPPING , PUBLIC
13
+
14
+ from readthedocs .projects .constants import OLD_LANGUAGES_CODE_MAPPING
22
15
from readthedocs .projects .exceptions import ProjectConfigurationError , UserFileNotFound
23
- from readthedocs .projects .models import Feature
24
- from readthedocs .projects .templatetags .projects_tags import sort_version_aware
25
16
26
17
from ..base import BaseBuilder
27
18
from ..constants import PDF_RE
28
19
from ..environments import BuildCommand , DockerBuildCommand
29
20
from ..exceptions import BuildUserError
30
- from ..signals import finalize_sphinx_context_data
31
21
32
22
log = structlog .get_logger (__name__ )
33
23
@@ -115,142 +105,8 @@ def get_language(self, project):
115
105
language = project .language
116
106
return OLD_LANGUAGES_CODE_MAPPING .get (language , language )
117
107
118
- def get_config_params (self ):
119
- """Get configuration parameters to be rendered into the conf file."""
120
- # TODO this should be handled better in the theme
121
- conf_py_path = os .path .join (
122
- os .path .sep ,
123
- os .path .dirname (
124
- os .path .relpath (
125
- self .config_file ,
126
- self .project_path ,
127
- ),
128
- ),
129
- "" ,
130
- )
131
- remote_version = self .version .commit_name
132
-
133
- github_user , github_repo = version_utils .get_github_username_repo (
134
- url = self .project .repo ,
135
- )
136
- github_version_is_editable = self .version .type == "branch"
137
- display_github = github_user is not None
138
-
139
- (
140
- bitbucket_user ,
141
- bitbucket_repo ,
142
- ) = version_utils .get_bitbucket_username_repo ( # noqa
143
- url = self .project .repo ,
144
- )
145
- bitbucket_version_is_editable = self .version .type == "branch"
146
- display_bitbucket = bitbucket_user is not None
147
-
148
- gitlab_user , gitlab_repo = version_utils .get_gitlab_username_repo (
149
- url = self .project .repo ,
150
- )
151
- gitlab_version_is_editable = self .version .type == "branch"
152
- display_gitlab = gitlab_user is not None
153
-
154
- versions = []
155
- downloads = []
156
- subproject_urls = []
157
- try :
158
- active_versions_data = self .api_client .project (
159
- self .project .pk
160
- ).active_versions .get ()["versions" ]
161
- versions = sort_version_aware (
162
- [APIVersion (** version_data ) for version_data in active_versions_data ]
163
- )
164
- if not self .project .has_feature (Feature .ALL_VERSIONS_IN_HTML_CONTEXT ):
165
- versions = [v for v in versions if v .privacy_level == PUBLIC ]
166
- downloads = self .api_client .version (self .version .pk ).get ()["downloads" ]
167
- subproject_urls = [
168
- (project ["slug" ], project ["canonical_url" ])
169
- for project in self .api_client .project (self .project .pk )
170
- .subprojects ()
171
- .get ()["subprojects" ]
172
- ]
173
- except ConnectionError :
174
- log .exception (
175
- "Timeout while fetching versions/downloads/subproject_urls for Sphinx context." ,
176
- project_slug = self .project .slug ,
177
- version_slug = self .version .slug ,
178
- )
179
-
180
- build_id = self .build_env .build .get ("id" )
181
- build_url = None
182
- if build_id :
183
- build_url = reverse (
184
- "builds_detail" ,
185
- kwargs = {
186
- "project_slug" : self .project .slug ,
187
- "build_pk" : build_id ,
188
- },
189
- )
190
- protocol = "http" if settings .DEBUG else "https"
191
- build_url = f"{ protocol } ://{ settings .PRODUCTION_DOMAIN } { build_url } "
192
-
193
- vcs_url = None
194
- if self .version .is_external :
195
- vcs_url = self .version .vcs_url
196
-
197
- commit = self .project .vcs_repo (
198
- version = self .version .slug ,
199
- environment = self .build_env ,
200
- ).commit
201
-
202
- data = {
203
- "current_version" : self .version .verbose_name ,
204
- "project" : self .project ,
205
- "version" : self .version ,
206
- "settings" : settings ,
207
- "conf_py_path" : conf_py_path ,
208
- "api_host" : settings .PUBLIC_API_URL ,
209
- "commit" : commit ,
210
- "versions" : versions ,
211
- "downloads" : downloads ,
212
- "subproject_urls" : subproject_urls ,
213
- "build_url" : build_url ,
214
- "vcs_url" : vcs_url ,
215
- "proxied_static_path" : self .project .proxied_static_path ,
216
- # GitHub
217
- "github_user" : github_user ,
218
- "github_repo" : github_repo ,
219
- "github_version" : remote_version ,
220
- "github_version_is_editable" : github_version_is_editable ,
221
- "display_github" : display_github ,
222
- # Bitbucket
223
- "bitbucket_user" : bitbucket_user ,
224
- "bitbucket_repo" : bitbucket_repo ,
225
- "bitbucket_version" : remote_version ,
226
- "bitbucket_version_is_editable" : bitbucket_version_is_editable ,
227
- "display_bitbucket" : display_bitbucket ,
228
- # GitLab
229
- "gitlab_user" : gitlab_user ,
230
- "gitlab_repo" : gitlab_repo ,
231
- "gitlab_version" : remote_version ,
232
- "gitlab_version_is_editable" : gitlab_version_is_editable ,
233
- "display_gitlab" : display_gitlab ,
234
- # Features
235
- "docsearch_disabled" : self .project .has_feature (
236
- Feature .DISABLE_SERVER_SIDE_SEARCH
237
- ),
238
- }
239
-
240
- finalize_sphinx_context_data .send (
241
- sender = self .__class__ ,
242
- build_env = self .build_env ,
243
- data = data ,
244
- )
245
-
246
- return data
247
-
248
- def append_conf (self ):
249
- """
250
- Find a ``conf.py`` and appends default content.
251
-
252
- The default content is rendered from ``doc_builder/conf.py.tmpl``.
253
- """
108
+ def show_conf (self ):
109
+ """Show the current ``conf.py`` being used."""
254
110
if self .config_file is None :
255
111
raise ProjectConfigurationError (ProjectConfigurationError .NOT_FOUND )
256
112
@@ -264,22 +120,6 @@ def append_conf(self):
264
120
},
265
121
)
266
122
267
- if not self .project .has_feature (Feature .DISABLE_SPHINX_MANIPULATION ):
268
- # Allow symlinks, but only the ones that resolve inside the base directory.
269
- # NOTE: if something goes wrong,
270
- # `safe_open` raises an exception that's clearly communicated to the user.
271
- outfile = safe_open (
272
- self .config_file , "a" , allow_symlinks = True , base_path = self .project_path
273
- )
274
-
275
- # Append config to project conf file
276
- tmpl = template_loader .get_template ("doc_builder/conf.py.tmpl" )
277
- rendered = tmpl .render (self .get_config_params ())
278
-
279
- with outfile :
280
- outfile .write ("\n " )
281
- outfile .write (rendered )
282
-
283
123
# Print the contents of conf.py in order to make the rendered
284
124
# configfile visible in the build logs
285
125
self .run (
@@ -357,18 +197,9 @@ def __init__(self, *args, **kwargs):
357
197
358
198
359
199
class LocalMediaBuilder (BaseSphinx ):
360
- sphinx_builder = "readthedocssinglehtmllocalmedia "
200
+ sphinx_builder = "singlehtml "
361
201
relative_output_dir = "htmlzip"
362
202
363
- def __init__ (self , * args , ** kwargs ):
364
- super ().__init__ (* args , ** kwargs )
365
-
366
- # The builder `readthedocssinglehtmllocalmedia` is defined by our
367
- # `readthedocs-sphinx-ext` extension that we are not installing
368
- # anymore; so we want to use the default Sphinx `singlehtml` builder
369
- if self .project .has_feature (Feature .DISABLE_SPHINX_MANIPULATION ):
370
- self .sphinx_builder = "singlehtml"
371
-
372
203
def _post_build (self ):
373
204
"""Internal post build to create the ZIP file from the HTML output."""
374
205
target_file = os .path .join (
0 commit comments