Skip to content

Commit

Permalink
Merge pull request readthedocs#5056 from dojutsu-user/using-defaults
Browse files Browse the repository at this point in the history
Use default settings for Config object
  • Loading branch information
stsewd committed Jan 22, 2019
2 parents 3304193 + 7c905c6 commit 7a54182
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 44 deletions.
30 changes: 10 additions & 20 deletions readthedocs/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import os
from contextlib import contextmanager

from django.conf import settings

from readthedocs.config.utils import list_to_dict, to_dict
from readthedocs.projects.constants import DOCUMENTATION_CHOICES

Expand Down Expand Up @@ -61,28 +63,16 @@
INVALID_KEYS_COMBINATION = 'invalid-keys-combination'
INVALID_KEY = 'invalid-key'

DOCKER_DEFAULT_IMAGE = 'readthedocs/build'
DOCKER_DEFAULT_VERSION = '2.0'
DOCKER_DEFAULT_IMAGE = getattr(settings, 'DOCKER_DEFAULT_IMAGE', 'readthedocs/build')
DOCKER_DEFAULT_VERSION = getattr(settings, 'DOCKER_DEFAULT_VERSION', '2.0')
# These map to corresponding settings in the .org,
# so they haven't been renamed.
DOCKER_IMAGE = '{}:{}'.format(DOCKER_DEFAULT_IMAGE, DOCKER_DEFAULT_VERSION)
DOCKER_IMAGE_SETTINGS = {
'readthedocs/build:1.0': {
'python': {'supported_versions': [2, 2.7, 3, 3.4]},
},
'readthedocs/build:2.0': {
'python': {'supported_versions': [2, 2.7, 3, 3.5]},
},
'readthedocs/build:3.0': {
'python': {'supported_versions': [2, 2.7, 3, 3.3, 3.4, 3.5, 3.6]},
},
'readthedocs/build:stable': {
'python': {'supported_versions': [2, 2.7, 3, 3.3, 3.4, 3.5, 3.6]},
},
'readthedocs/build:latest': {
'python': {'supported_versions': [2, 2.7, 3, 3.3, 3.4, 3.5, 3.6]},
},
}
DOCKER_IMAGE = getattr(
settings,
'DOCKER_IMAGE',
'{}:{}'.format(DOCKER_DEFAULT_IMAGE, DOCKER_DEFAULT_VERSION)
)
DOCKER_IMAGE_SETTINGS = getattr(settings, 'DOCKER_IMAGE_SETTINGS', {})


class ConfigError(Exception):
Expand Down
51 changes: 28 additions & 23 deletions readthedocs/rtd_tests/tests/test_config_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from readthedocs.projects import tasks
from readthedocs.projects.models import Feature, Project
from readthedocs.rtd_tests.utils import create_git_submodule, make_git_repo
from doc_builder.constants import DOCKER_IMAGE_SETTINGS


def create_load(config=None):
Expand Down Expand Up @@ -84,30 +85,34 @@ def test_python_supported_versions_default_image_1_0(self, load_config):
self.project.enable_pdf_build = True
self.project.save()
config = load_yaml_config(self.version)
self.assertEqual(load_config.call_count, 1)
load_config.assert_has_calls([
mock.call(

expected_env_config = {
'allow_v2': mock.ANY,
'build': {'image': 'readthedocs/build:1.0'},
'defaults': {
'install_project': self.project.install_project,
'formats': [
'htmlzip',
'epub',
'pdf'
],
'use_system_packages': self.project.use_system_packages,
'requirements_file': self.project.requirements_file,
'python_version': 2,
'sphinx_configuration': mock.ANY,
'build_image': 'readthedocs/build:1.0',
'doctype': self.project.documentation_type,
},
}

img_settings = DOCKER_IMAGE_SETTINGS.get(self.project.container_image, None)
if img_settings:
expected_env_config.update(img_settings)

load_config.assert_called_once_with(
path=mock.ANY,
env_config={
'allow_v2': mock.ANY,
'build': {'image': 'readthedocs/build:1.0'},
'defaults': {
'install_project': self.project.install_project,
'formats': [
'htmlzip',
'epub',
'pdf',
],
'use_system_packages': self.project.use_system_packages,
'requirements_file': self.project.requirements_file,
'python_version': 2,
'sphinx_configuration': mock.ANY,
'build_image': 'readthedocs/build:1.0',
'doctype': self.project.documentation_type,
},
},
),
])
env_config=expected_env_config,
)
self.assertEqual(config.python.version, 2)

@mock.patch('readthedocs.doc_builder.config.load_config')
Expand Down
21 changes: 20 additions & 1 deletion readthedocs/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,26 @@ def USE_PROMOS(self): # noqa

# Docker
DOCKER_ENABLE = False
DOCKER_IMAGE = 'readthedocs/build:2.0'
DOCKER_DEFAULT_IMAGE = 'readthedocs/build'
DOCKER_DEFAULT_VERSION = '2.0'
DOCKER_IMAGE = '{}:{}'.format(DOCKER_DEFAULT_IMAGE, DOCKER_DEFAULT_VERSION)
DOCKER_IMAGE_SETTINGS = {
'readthedocs/build:1.0': {
'python': {'supported_versions': [2, 2.7, 3, 3.4]},
},
'readthedocs/build:2.0': {
'python': {'supported_versions': [2, 2.7, 3, 3.5]},
},
'readthedocs/build:3.0': {
'python': {'supported_versions': [2, 2.7, 3, 3.3, 3.4, 3.5, 3.6]},
},
'readthedocs/build:stable': {
'python': {'supported_versions': [2, 2.7, 3, 3.3, 3.4, 3.5, 3.6]},
},
'readthedocs/build:latest': {
'python': {'supported_versions': [2, 2.7, 3, 3.3, 3.4, 3.5, 3.6]},
},
}

# All auth
ACCOUNT_ADAPTER = 'readthedocs.core.adapters.AccountAdapter'
Expand Down

0 comments on commit 7a54182

Please sign in to comment.