Skip to content

Commit 5b37760

Browse files
committed
Pass config object to builders
1 parent 32c9aeb commit 5b37760

File tree

5 files changed

+44
-15
lines changed

5 files changed

+44
-15
lines changed

readthedocs/doc_builder/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@ class BaseBuilder(object):
4141

4242
# old_artifact_path = ..
4343

44-
def __init__(self, build_env, python_env, force=False):
44+
def __init__(self, build_env, python_env, config, force=False):
4545
self.build_env = build_env
4646
self.python_env = python_env
4747
self.version = build_env.version
4848
self.project = build_env.project
49+
self.config = config
4950
self._force = force
5051
self.target = self.project.artifact_path(
5152
version=self.version.slug, type_=self.type)

readthedocs/doc_builder/python_environments.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,12 @@ def install_user_requirements(self):
274274
requirements_file_path = self.config.python.requirements
275275
if not requirements_file_path and requirements_file_path != '':
276276
builder_class = get_builder_class(self.project.documentation_type)
277-
docs_dir = (builder_class(build_env=self.build_env, python_env=self)
278-
.docs_dir())
277+
builder = builder_class(
278+
build_env=self.build_env,
279+
python_env=self,
280+
config=self.config
281+
)
282+
docs_dir = builder.docs_dir()
279283
paths = [docs_dir, '']
280284
req_files = ['pip_requirements.txt', 'requirements.txt']
281285
for path, req_file in itertools.product(paths, req_files):

readthedocs/projects/tasks.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -702,9 +702,10 @@ def build_docs(self):
702702

703703
def build_docs_html(self):
704704
"""Build HTML docs."""
705-
html_builder = get_builder_class(self.project.documentation_type)(
705+
html_builder = get_builder_class(self.config.doctype)(
706706
build_env=self.build_env,
707707
python_env=self.python_env,
708+
config=self.config,
708709
)
709710
if self.build_force:
710711
html_builder.force()
@@ -775,7 +776,11 @@ def build_docs_class(self, builder_class):
775776
only raise a warning exception here. A hard error will halt the build
776777
process.
777778
"""
778-
builder = get_builder_class(builder_class)(self.build_env, python_env=self.python_env)
779+
builder = get_builder_class(builder_class)(
780+
self.build_env,
781+
python_env=self.python_env,
782+
config=self.config,
783+
)
779784
success = builder.build()
780785
builder.move()
781786
return success

readthedocs/rtd_tests/tests/test_builds.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import absolute_import
22

33
import mock
4-
import six
54

65
from django.test import TestCase
76
from django_dynamic_fixture import get
@@ -11,7 +10,6 @@
1110
from readthedocs.doc_builder.config import load_yaml_config
1211
from readthedocs.doc_builder.environments import LocalBuildEnvironment
1312
from readthedocs.doc_builder.python_environments import Virtualenv
14-
from readthedocs.doc_builder.loader import get_builder_class
1513
from readthedocs.projects.tasks import UpdateDocsTaskStep
1614
from readthedocs.rtd_tests.tests.test_config_integration import create_load
1715

readthedocs/rtd_tests/tests/test_doc_builder.py

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
import tempfile
77
from collections import namedtuple
88

9+
import mock
910
import pytest
1011
import yaml
11-
import mock
1212
from django.test import TestCase
1313
from django.test.utils import override_settings
1414
from django_dynamic_fixture import get
@@ -17,6 +17,7 @@
1717
from readthedocs.builds.models import Version
1818
from readthedocs.doc_builder.backends.mkdocs import BaseMkdocs, MkdocsHTML
1919
from readthedocs.doc_builder.backends.sphinx import BaseSphinx, SearchBuilder
20+
from readthedocs.doc_builder.config import load_yaml_config
2021
from readthedocs.projects.exceptions import ProjectConfigurationError
2122
from readthedocs.projects.models import Project
2223

@@ -35,7 +36,12 @@ def setUp(self):
3536

3637
BaseSphinx.type = 'base'
3738
BaseSphinx.sphinx_build_dir = tempfile.mkdtemp()
38-
self.base_sphinx = BaseSphinx(build_env=build_env, python_env=None)
39+
config = load_yaml_config(self.version)
40+
self.base_sphinx = BaseSphinx(
41+
build_env=build_env,
42+
python_env=None,
43+
config=config,
44+
)
3945

4046
@patch(
4147
'readthedocs.doc_builder.backends.sphinx.SPHINX_TEMPLATE_DIR',
@@ -89,7 +95,12 @@ def setUp(self):
8995
build_env.project = self.project
9096
build_env.version = self.version
9197

92-
self.searchbuilder = SearchBuilder(build_env=build_env, python_env=None)
98+
config = load_yaml_config(self.version)
99+
self.searchbuilder = SearchBuilder(
100+
build_env=build_env,
101+
python_env=None,
102+
config=config,
103+
)
93104

94105
def test_ignore_patterns(self):
95106
src = tempfile.mkdtemp()
@@ -134,9 +145,11 @@ def test_append_conf_create_yaml(self, checkout_path, run):
134145
os.mkdir(os.path.join(tmpdir, 'docs'))
135146
checkout_path.return_value = tmpdir
136147

148+
config = load_yaml_config(self.version)
137149
self.searchbuilder = MkdocsHTML(
138150
build_env=self.build_env,
139-
python_env=None
151+
python_env=None,
152+
config=config,
140153
)
141154
self.searchbuilder.append_conf()
142155

@@ -189,9 +202,11 @@ def test_append_conf_existing_yaml_on_root(self, checkout_path, run):
189202
)
190203
checkout_path.return_value = tmpdir
191204

205+
config = load_yaml_config(self.version)
192206
self.searchbuilder = MkdocsHTML(
193207
build_env=self.build_env,
194-
python_env=None
208+
python_env=None,
209+
config=config,
195210
)
196211
self.searchbuilder.append_conf()
197212

@@ -243,9 +258,11 @@ def test_override_theme_new_style(self, checkout_path, run):
243258
)
244259
checkout_path.return_value = tmpdir
245260

261+
config = load_yaml_config(self.version)
246262
self.searchbuilder = MkdocsHTML(
247263
build_env=self.build_env,
248-
python_env=None
264+
python_env=None,
265+
config=config,
249266
)
250267
self.searchbuilder.append_conf()
251268

@@ -276,9 +293,11 @@ def test_override_theme_old_style(self, checkout_path, run):
276293
)
277294
checkout_path.return_value = tmpdir
278295

296+
config = load_yaml_config(self.version)
279297
self.searchbuilder = MkdocsHTML(
280298
build_env=self.build_env,
281-
python_env=None
299+
python_env=None,
300+
config=config,
282301
)
283302
self.searchbuilder.append_conf()
284303

@@ -307,9 +326,11 @@ def test_dont_override_theme(self, checkout_path, run):
307326
)
308327
checkout_path.return_value = tmpdir
309328

329+
config = load_yaml_config(self.version)
310330
self.searchbuilder = MkdocsHTML(
311331
build_env=self.build_env,
312-
python_env=None
332+
python_env=None,
333+
config=config,
313334
)
314335
self.searchbuilder.append_conf()
315336

0 commit comments

Comments
 (0)