Skip to content

Commit 7a54182

Browse files
authored
Merge pull request #5056 from dojutsu-user/using-defaults
Use default settings for Config object
2 parents 3304193 + 7c905c6 commit 7a54182

File tree

3 files changed

+58
-44
lines changed

3 files changed

+58
-44
lines changed

readthedocs/config/config.py

+10-20
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import os
77
from contextlib import contextmanager
88

9+
from django.conf import settings
10+
911
from readthedocs.config.utils import list_to_dict, to_dict
1012
from readthedocs.projects.constants import DOCUMENTATION_CHOICES
1113

@@ -61,28 +63,16 @@
6163
INVALID_KEYS_COMBINATION = 'invalid-keys-combination'
6264
INVALID_KEY = 'invalid-key'
6365

64-
DOCKER_DEFAULT_IMAGE = 'readthedocs/build'
65-
DOCKER_DEFAULT_VERSION = '2.0'
66+
DOCKER_DEFAULT_IMAGE = getattr(settings, 'DOCKER_DEFAULT_IMAGE', 'readthedocs/build')
67+
DOCKER_DEFAULT_VERSION = getattr(settings, 'DOCKER_DEFAULT_VERSION', '2.0')
6668
# These map to corresponding settings in the .org,
6769
# so they haven't been renamed.
68-
DOCKER_IMAGE = '{}:{}'.format(DOCKER_DEFAULT_IMAGE, DOCKER_DEFAULT_VERSION)
69-
DOCKER_IMAGE_SETTINGS = {
70-
'readthedocs/build:1.0': {
71-
'python': {'supported_versions': [2, 2.7, 3, 3.4]},
72-
},
73-
'readthedocs/build:2.0': {
74-
'python': {'supported_versions': [2, 2.7, 3, 3.5]},
75-
},
76-
'readthedocs/build:3.0': {
77-
'python': {'supported_versions': [2, 2.7, 3, 3.3, 3.4, 3.5, 3.6]},
78-
},
79-
'readthedocs/build:stable': {
80-
'python': {'supported_versions': [2, 2.7, 3, 3.3, 3.4, 3.5, 3.6]},
81-
},
82-
'readthedocs/build:latest': {
83-
'python': {'supported_versions': [2, 2.7, 3, 3.3, 3.4, 3.5, 3.6]},
84-
},
85-
}
70+
DOCKER_IMAGE = getattr(
71+
settings,
72+
'DOCKER_IMAGE',
73+
'{}:{}'.format(DOCKER_DEFAULT_IMAGE, DOCKER_DEFAULT_VERSION)
74+
)
75+
DOCKER_IMAGE_SETTINGS = getattr(settings, 'DOCKER_IMAGE_SETTINGS', {})
8676

8777

8878
class ConfigError(Exception):

readthedocs/rtd_tests/tests/test_config_integration.py

+28-23
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from readthedocs.projects import tasks
2525
from readthedocs.projects.models import Feature, Project
2626
from readthedocs.rtd_tests.utils import create_git_submodule, make_git_repo
27+
from doc_builder.constants import DOCKER_IMAGE_SETTINGS
2728

2829

2930
def create_load(config=None):
@@ -84,30 +85,34 @@ def test_python_supported_versions_default_image_1_0(self, load_config):
8485
self.project.enable_pdf_build = True
8586
self.project.save()
8687
config = load_yaml_config(self.version)
87-
self.assertEqual(load_config.call_count, 1)
88-
load_config.assert_has_calls([
89-
mock.call(
88+
89+
expected_env_config = {
90+
'allow_v2': mock.ANY,
91+
'build': {'image': 'readthedocs/build:1.0'},
92+
'defaults': {
93+
'install_project': self.project.install_project,
94+
'formats': [
95+
'htmlzip',
96+
'epub',
97+
'pdf'
98+
],
99+
'use_system_packages': self.project.use_system_packages,
100+
'requirements_file': self.project.requirements_file,
101+
'python_version': 2,
102+
'sphinx_configuration': mock.ANY,
103+
'build_image': 'readthedocs/build:1.0',
104+
'doctype': self.project.documentation_type,
105+
},
106+
}
107+
108+
img_settings = DOCKER_IMAGE_SETTINGS.get(self.project.container_image, None)
109+
if img_settings:
110+
expected_env_config.update(img_settings)
111+
112+
load_config.assert_called_once_with(
90113
path=mock.ANY,
91-
env_config={
92-
'allow_v2': mock.ANY,
93-
'build': {'image': 'readthedocs/build:1.0'},
94-
'defaults': {
95-
'install_project': self.project.install_project,
96-
'formats': [
97-
'htmlzip',
98-
'epub',
99-
'pdf',
100-
],
101-
'use_system_packages': self.project.use_system_packages,
102-
'requirements_file': self.project.requirements_file,
103-
'python_version': 2,
104-
'sphinx_configuration': mock.ANY,
105-
'build_image': 'readthedocs/build:1.0',
106-
'doctype': self.project.documentation_type,
107-
},
108-
},
109-
),
110-
])
114+
env_config=expected_env_config,
115+
)
111116
self.assertEqual(config.python.version, 2)
112117

113118
@mock.patch('readthedocs.doc_builder.config.load_config')

readthedocs/settings/base.py

+20-1
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,26 @@ def USE_PROMOS(self): # noqa
271271

272272
# Docker
273273
DOCKER_ENABLE = False
274-
DOCKER_IMAGE = 'readthedocs/build:2.0'
274+
DOCKER_DEFAULT_IMAGE = 'readthedocs/build'
275+
DOCKER_DEFAULT_VERSION = '2.0'
276+
DOCKER_IMAGE = '{}:{}'.format(DOCKER_DEFAULT_IMAGE, DOCKER_DEFAULT_VERSION)
277+
DOCKER_IMAGE_SETTINGS = {
278+
'readthedocs/build:1.0': {
279+
'python': {'supported_versions': [2, 2.7, 3, 3.4]},
280+
},
281+
'readthedocs/build:2.0': {
282+
'python': {'supported_versions': [2, 2.7, 3, 3.5]},
283+
},
284+
'readthedocs/build:3.0': {
285+
'python': {'supported_versions': [2, 2.7, 3, 3.3, 3.4, 3.5, 3.6]},
286+
},
287+
'readthedocs/build:stable': {
288+
'python': {'supported_versions': [2, 2.7, 3, 3.3, 3.4, 3.5, 3.6]},
289+
},
290+
'readthedocs/build:latest': {
291+
'python': {'supported_versions': [2, 2.7, 3, 3.3, 3.4, 3.5, 3.6]},
292+
},
293+
}
275294

276295
# All auth
277296
ACCOUNT_ADAPTER = 'readthedocs.core.adapters.AccountAdapter'

0 commit comments

Comments
 (0)