Skip to content

Allow BUILD_IMAGES to be updated from a setting #3306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[flake8]
ignore = E125,D100,D101,D102,D105,D200,D211,P101,FI15,FI16,FI12,FI11,FI17,FI50,FI53,FI54
ignore = E125,D100,D101,D102,D105,D107,D200,D211,P101,FI15,FI16,FI12,FI11,FI17,FI50,FI53,FI54
max-line-length = 80
5 changes: 2 additions & 3 deletions .isort.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ line_length=80
indent=' '
multi_line_output=4
default_section=FIRSTPARTY
known_readthedocs=readthedocs
known_readthedocsinc=readthedocsinc
known_third_party=celery,stripe,requests,pytz,builtins,django,annoying
known_firstparty=readthedocs,readthedocsinc
known_third_party=celery,stripe,requests,pytz,builtins,django,annoying,readthedocs_build
sections=FUTURE,STDLIB,THIRDPARTY,FIRSTPARTY,LOCALFOLDER
add_imports=from __future__ import division, from __future__ import print_function, from __future__ import unicode_literals
35 changes: 20 additions & 15 deletions readthedocs/doc_builder/config.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# -*- coding: utf-8 -*-
"""An API to load config from a readthedocs.yml file."""
from __future__ import absolute_import

from builtins import (filter, object)
from __future__ import (
absolute_import, division, print_function, unicode_literals)

from readthedocs_build.config import (ConfigError, BuildConfig, InvalidConfig,
load as load_config)
from .constants import BUILD_IMAGES, DOCKER_IMAGE
from builtins import filter, object
from readthedocs_build.config import load as load_config
from readthedocs_build.config import BuildConfig, ConfigError, InvalidConfig

from .constants import DOCKER_BUILD_IMAGES, DOCKER_IMAGE


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

"""

def __init__(self, version, yaml_config):
Expand Down Expand Up @@ -53,10 +55,12 @@ def python_interpreter(self):
if ver in [2, 3]:
# Get the highest version of the major series version if user only
# gave us a version of '2', or '3'
ver = max(list(filter(
lambda x: x < ver + 1,
self._yaml_config.get_valid_python_versions(),
)))
ver = max(
list(
filter(
lambda x: x < ver + 1,
self._yaml_config.get_valid_python_versions(),
)))
return 'python{0}'.format(ver)

@property
Expand Down Expand Up @@ -118,18 +122,18 @@ def load_yaml_config(version):
"""
Load a configuration from `readthedocs.yml` file.

This uses the configuration logic from `readthedocs-build`,
which will keep parsing consistent between projects.
This uses the configuration logic from `readthedocs-build`, which will keep
parsing consistent between projects.
"""
checkout_path = version.project.checkout_path(version.slug)
env_config = {}

# Get build image to set up the python version validation. Pass in the
# build image python limitations to the loaded config so that the versions
# can be rejected at validation
build_image = BUILD_IMAGES.get(
build_image = DOCKER_BUILD_IMAGES.get(
version.project.container_image,
BUILD_IMAGES.get(DOCKER_IMAGE, None),
DOCKER_BUILD_IMAGES.get(DOCKER_IMAGE, None),
)
if build_image:
env_config = {
Expand All @@ -147,7 +151,8 @@ def load_yaml_config(version):
path=checkout_path,
env_config=sphinx_env_config,
)[0]
except InvalidConfig: # This is a subclass of ConfigError, so has to come first
except InvalidConfig:
# This is a subclass of ConfigError, so has to come first
raise
except ConfigError:
config = BuildConfig(
Expand Down
33 changes: 24 additions & 9 deletions readthedocs/doc_builder/constants.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,36 @@
"""Doc build constants"""
# -*- coding: utf-8 -*-
"""Doc build constants."""

from __future__ import (
absolute_import, division, print_function, unicode_literals)

from __future__ import absolute_import
import os
import re

from django.conf import settings


SPHINX_TEMPLATE_DIR = os.path.join(settings.SITE_ROOT, 'readthedocs',
'templates', 'sphinx')
MKDOCS_TEMPLATE_DIR = os.path.join(settings.SITE_ROOT, 'readthedocs',
'templates', 'mkdocs')
SPHINX_TEMPLATE_DIR = os.path.join(
settings.SITE_ROOT,
'readthedocs',
'templates',
'sphinx',
)
MKDOCS_TEMPLATE_DIR = os.path.join(
settings.SITE_ROOT,
'readthedocs',
'templates',
'mkdocs',
)
SPHINX_STATIC_DIR = os.path.join(SPHINX_TEMPLATE_DIR, '_static')

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

# Docker
DOCKER_SOCKET = getattr(settings, 'DOCKER_SOCKET', 'unix:///var/run/docker.sock')
DOCKER_SOCKET = getattr(
settings,
'DOCKER_SOCKET',
'unix:///var/run/docker.sock',
)
DOCKER_VERSION = getattr(settings, 'DOCKER_VERSION', 'auto')
DOCKER_IMAGE = getattr(settings, 'DOCKER_IMAGE', 'readthedocs/build:2.0')
DOCKER_LIMITS = {'memory': '200m', 'time': 600}
Expand All @@ -28,7 +42,7 @@
DOCKER_HOSTNAME_MAX_LEN = 64

# Build images
BUILD_IMAGES = {
DOCKER_BUILD_IMAGES = {
'readthedocs/build:1.0': {
'python': {'supported_versions': [2, 2.7, 3, 3.4]},
},
Expand All @@ -39,3 +53,4 @@
'python': {'supported_versions': [2, 2.7, 3, 3.3, 3.4, 3.5, 3.6]},
},
}
DOCKER_BUILD_IMAGES.update(getattr(settings, 'DOCKER_BUILD_IMAGES', {}))