Skip to content

Commit 9920ba7

Browse files
humitosagjohnson
authored andcommitted
Allow BUILD_IMAGES to be updated from a setting (readthedocs#3306)
* Allow BUILD_IMAGES to be updated from a setting Fixes readthedocs#3524 * Styles * Style updates Config changes: - ignore D107 (__init__ method must have a docstring) in flake8 - readthedocs and readthedocsinc are marked as FIRSTPARTY in isort - readthedocs_build is marked as THIRDPARTY * Rename setting to DOCKER_BUILD_IMAGES
1 parent 90ac70d commit 9920ba7

File tree

4 files changed

+47
-28
lines changed

4 files changed

+47
-28
lines changed

.flake8

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[flake8]
2-
ignore = E125,D100,D101,D102,D105,D200,D211,P101,FI15,FI16,FI12,FI11,FI17,FI50,FI53,FI54
2+
ignore = E125,D100,D101,D102,D105,D107,D200,D211,P101,FI15,FI16,FI12,FI11,FI17,FI50,FI53,FI54
33
max-line-length = 80

.isort.cfg

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ line_length=80
33
indent=' '
44
multi_line_output=4
55
default_section=FIRSTPARTY
6-
known_readthedocs=readthedocs
7-
known_readthedocsinc=readthedocsinc
8-
known_third_party=celery,stripe,requests,pytz,builtins,django,annoying
6+
known_firstparty=readthedocs,readthedocsinc
7+
known_third_party=celery,stripe,requests,pytz,builtins,django,annoying,readthedocs_build
98
sections=FUTURE,STDLIB,THIRDPARTY,FIRSTPARTY,LOCALFOLDER
109
add_imports=from __future__ import division, from __future__ import print_function, from __future__ import unicode_literals

readthedocs/doc_builder/config.py

+20-15
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1+
# -*- coding: utf-8 -*-
12
"""An API to load config from a readthedocs.yml file."""
2-
from __future__ import absolute_import
33

4-
from builtins import (filter, object)
4+
from __future__ import (
5+
absolute_import, division, print_function, unicode_literals)
56

6-
from readthedocs_build.config import (ConfigError, BuildConfig, InvalidConfig,
7-
load as load_config)
8-
from .constants import BUILD_IMAGES, DOCKER_IMAGE
7+
from builtins import filter, object
8+
from readthedocs_build.config import load as load_config
9+
from readthedocs_build.config import BuildConfig, ConfigError, InvalidConfig
10+
11+
from .constants import DOCKER_BUILD_IMAGES, DOCKER_IMAGE
912

1013

1114
class ConfigWrapper(object):
@@ -18,7 +21,6 @@ class ConfigWrapper(object):
1821
We only currently implement a subset of the existing YAML config.
1922
This should be the canonical source for our usage of the YAML files,
2023
never accessing the config object directly.
21-
2224
"""
2325

2426
def __init__(self, version, yaml_config):
@@ -53,10 +55,12 @@ def python_interpreter(self):
5355
if ver in [2, 3]:
5456
# Get the highest version of the major series version if user only
5557
# gave us a version of '2', or '3'
56-
ver = max(list(filter(
57-
lambda x: x < ver + 1,
58-
self._yaml_config.get_valid_python_versions(),
59-
)))
58+
ver = max(
59+
list(
60+
filter(
61+
lambda x: x < ver + 1,
62+
self._yaml_config.get_valid_python_versions(),
63+
)))
6064
return 'python{0}'.format(ver)
6165

6266
@property
@@ -118,18 +122,18 @@ def load_yaml_config(version):
118122
"""
119123
Load a configuration from `readthedocs.yml` file.
120124
121-
This uses the configuration logic from `readthedocs-build`,
122-
which will keep parsing consistent between projects.
125+
This uses the configuration logic from `readthedocs-build`, which will keep
126+
parsing consistent between projects.
123127
"""
124128
checkout_path = version.project.checkout_path(version.slug)
125129
env_config = {}
126130

127131
# Get build image to set up the python version validation. Pass in the
128132
# build image python limitations to the loaded config so that the versions
129133
# can be rejected at validation
130-
build_image = BUILD_IMAGES.get(
134+
build_image = DOCKER_BUILD_IMAGES.get(
131135
version.project.container_image,
132-
BUILD_IMAGES.get(DOCKER_IMAGE, None),
136+
DOCKER_BUILD_IMAGES.get(DOCKER_IMAGE, None),
133137
)
134138
if build_image:
135139
env_config = {
@@ -147,7 +151,8 @@ def load_yaml_config(version):
147151
path=checkout_path,
148152
env_config=sphinx_env_config,
149153
)[0]
150-
except InvalidConfig: # This is a subclass of ConfigError, so has to come first
154+
except InvalidConfig:
155+
# This is a subclass of ConfigError, so has to come first
151156
raise
152157
except ConfigError:
153158
config = BuildConfig(

readthedocs/doc_builder/constants.py

+24-9
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,36 @@
1-
"""Doc build constants"""
1+
# -*- coding: utf-8 -*-
2+
"""Doc build constants."""
3+
4+
from __future__ import (
5+
absolute_import, division, print_function, unicode_literals)
26

3-
from __future__ import absolute_import
47
import os
58
import re
69

710
from django.conf import settings
811

9-
10-
SPHINX_TEMPLATE_DIR = os.path.join(settings.SITE_ROOT, 'readthedocs',
11-
'templates', 'sphinx')
12-
MKDOCS_TEMPLATE_DIR = os.path.join(settings.SITE_ROOT, 'readthedocs',
13-
'templates', 'mkdocs')
12+
SPHINX_TEMPLATE_DIR = os.path.join(
13+
settings.SITE_ROOT,
14+
'readthedocs',
15+
'templates',
16+
'sphinx',
17+
)
18+
MKDOCS_TEMPLATE_DIR = os.path.join(
19+
settings.SITE_ROOT,
20+
'readthedocs',
21+
'templates',
22+
'mkdocs',
23+
)
1424
SPHINX_STATIC_DIR = os.path.join(SPHINX_TEMPLATE_DIR, '_static')
1525

1626
PDF_RE = re.compile('Output written on (.*?)')
1727

1828
# Docker
19-
DOCKER_SOCKET = getattr(settings, 'DOCKER_SOCKET', 'unix:///var/run/docker.sock')
29+
DOCKER_SOCKET = getattr(
30+
settings,
31+
'DOCKER_SOCKET',
32+
'unix:///var/run/docker.sock',
33+
)
2034
DOCKER_VERSION = getattr(settings, 'DOCKER_VERSION', 'auto')
2135
DOCKER_IMAGE = getattr(settings, 'DOCKER_IMAGE', 'readthedocs/build:2.0')
2236
DOCKER_LIMITS = {'memory': '200m', 'time': 600}
@@ -28,7 +42,7 @@
2842
DOCKER_HOSTNAME_MAX_LEN = 64
2943

3044
# Build images
31-
BUILD_IMAGES = {
45+
DOCKER_BUILD_IMAGES = {
3246
'readthedocs/build:1.0': {
3347
'python': {'supported_versions': [2, 2.7, 3, 3.4]},
3448
},
@@ -39,3 +53,4 @@
3953
'python': {'supported_versions': [2, 2.7, 3, 3.3, 3.4, 3.5, 3.6]},
4054
},
4155
}
56+
DOCKER_BUILD_IMAGES.update(getattr(settings, 'DOCKER_BUILD_IMAGES', {}))

0 commit comments

Comments
 (0)