Skip to content

Commit a705f9d

Browse files
committed
Address review feedback and remove most of my deleted code :)
1 parent aa15e78 commit a705f9d

File tree

4 files changed

+76
-11
lines changed

4 files changed

+76
-11
lines changed

docs/yaml-config.rst

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,20 @@ The ``build`` block configures specific aspects of the documentation build.
8080
build.image
8181
```````````
8282

83-
* Default: ``2.0``
83+
84+
* Default: :djangosetting:`DOCKER_IMAGE`
8485
* Options: ``1.0``, ``2.0``, ``latest``
8586

86-
The docker image to use for specific builds.
87-
This lets users specify a more experimental builder,
87+
The build image to use for specific builds.
88+
This lets users specify a more experimental build image,
8889
if they want to be on the cutting edge.
8990

90-
Certain Python versions require a certain builder,
91+
Certain Python versions require a certain build image,
9192
as defined here::
9293

93-
* '1.0': 2, 2.7, 3, 3.4
94-
* '2.0': 2, 2.7, 3, 3.5
95-
* 'latest': 2, 2.7, 3, 3.3, 3.4, 3.5, 3.6
94+
* `'1.0': 2, 2.7, 3, 3.4`
95+
* `'2.0': 2, 2.7, 3, 3.5`
96+
* `'latest': 2, 2.7, 3, 3.3, 3.4, 3.5, 3.6`
9697

9798
.. code-block:: yaml
9899

readthedocs/doc_builder/config.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
from readthedocs_build.config import load as load_config
99
from readthedocs_build.config import BuildConfig, ConfigError, InvalidConfig
1010

11+
from .constants import DOCKER_BUILD_IMAGES, DOCKER_IMAGE
12+
1113

1214
class ConfigWrapper(object):
1315

@@ -57,7 +59,7 @@ def python_interpreter(self):
5759
list(
5860
filter(
5961
lambda x: x < ver + 1,
60-
self._yaml_config.PYTHON_SUPPORTED_VERSIONS,
62+
self._yaml_config.get_valid_python_versions(),
6163
)))
6264
return 'python{0}'.format(ver)
6365

@@ -133,8 +135,22 @@ def load_yaml_config(version):
133135
parsing consistent between projects.
134136
"""
135137
checkout_path = version.project.checkout_path(version.slug)
138+
env_config = {}
139+
140+
# Get build image to set up the python version validation. Pass in the
141+
# build image python limitations to the loaded config so that the versions
142+
# can be rejected at validation
143+
build_image = DOCKER_BUILD_IMAGES.get(
144+
version.project.container_image,
145+
DOCKER_BUILD_IMAGES.get(DOCKER_IMAGE, None),
146+
)
147+
if build_image:
148+
env_config = {
149+
'python': build_image['python'],
150+
}
151+
136152
try:
137-
sphinx_env_config = {}
153+
sphinx_env_config = env_config.copy()
138154
sphinx_env_config.update({
139155
'output_base': '',
140156
'type': 'sphinx',
@@ -148,9 +164,8 @@ def load_yaml_config(version):
148164
# This is a subclass of ConfigError, so has to come first
149165
raise
150166
except ConfigError:
151-
# Just fall back to defaults
152167
config = BuildConfig(
153-
env_config={},
168+
env_config=env_config,
154169
raw_config={},
155170
source_file='empty',
156171
source_position=0,

readthedocs/doc_builder/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
)
3434
DOCKER_VERSION = getattr(settings, 'DOCKER_VERSION', 'auto')
3535
DOCKER_IMAGE = getattr(settings, 'DOCKER_IMAGE', 'readthedocs/build:2.0')
36+
DOCKER_BUILD_IMAGES = getattr(settings, 'DOCKER_BUILD_IMAGES', {})
3637
DOCKER_LIMITS = {'memory': '200m', 'time': 600}
3738
DOCKER_LIMITS.update(getattr(settings, 'DOCKER_LIMITS', {}))
3839

readthedocs/rtd_tests/tests/test_config_wrapper.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,54 @@ def setUp(self):
4646
install_project=False, requirements_file='urls.py')
4747
self.version = get(Version, project=self.project)
4848

49+
def test_python_supported_versions_default_image_1_0(self, load_config):
50+
load_config.side_effect = create_load()
51+
self.project.container_image = 'readthedocs/build:1.0'
52+
self.project.save()
53+
config = load_yaml_config(self.version)
54+
self.assertEqual(load_config.call_count, 1)
55+
load_config.assert_has_calls([
56+
mock.call(path=mock.ANY, env_config={
57+
'python': {'supported_versions': [2, 2.7, 3, 3.4]},
58+
'type': 'sphinx',
59+
'output_base': '',
60+
'name': mock.ANY
61+
}),
62+
])
63+
self.assertEqual(config.python_version, 2)
64+
65+
def test_python_supported_versions_image_2_0(self, load_config):
66+
load_config.side_effect = create_load()
67+
self.project.container_image = 'readthedocs/build:2.0'
68+
self.project.save()
69+
config = load_yaml_config(self.version)
70+
self.assertEqual(load_config.call_count, 1)
71+
load_config.assert_has_calls([
72+
mock.call(path=mock.ANY, env_config={
73+
'python': {'supported_versions': [2, 2.7, 3, 3.5]},
74+
'type': 'sphinx',
75+
'output_base': '',
76+
'name': mock.ANY
77+
}),
78+
])
79+
self.assertEqual(config.python_version, 2)
80+
81+
def test_python_supported_versions_image_latest(self, load_config):
82+
load_config.side_effect = create_load()
83+
self.project.container_image = 'readthedocs/build:latest'
84+
self.project.save()
85+
config = load_yaml_config(self.version)
86+
self.assertEqual(load_config.call_count, 1)
87+
load_config.assert_has_calls([
88+
mock.call(path=mock.ANY, env_config={
89+
'python': {'supported_versions': [2, 2.7, 3, 3.3, 3.4, 3.5, 3.6]},
90+
'type': 'sphinx',
91+
'output_base': '',
92+
'name': mock.ANY
93+
}),
94+
])
95+
self.assertEqual(config.python_version, 2)
96+
4997
def test_python_default_version(self, load_config):
5098
load_config.side_effect = create_load()
5199
config = load_yaml_config(self.version)

0 commit comments

Comments
 (0)