Skip to content

Pass build env python limits to config object #2627

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 6 commits into from
Feb 13, 2017
Merged
Show file tree
Hide file tree
Changes from 2 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
49 changes: 33 additions & 16 deletions readthedocs/doc_builder/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
load as load_config)


from .constants import BUILD_IMAGES, DOCKER_IMAGE
from readthedocs.projects.exceptions import ProjectImportError


Expand Down Expand Up @@ -49,20 +50,20 @@ def extra_requirements(self):

@property
def python_interpreter(self):
if 'version' in self._yaml_config.get('python', {}):
ver = self._yaml_config['python']['version']
if str(ver).startswith('2'):
return 'python'
else:
return 'python3'
else:
return self._project.python_interpreter
ver = self.python_version
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(filter(
lambda x: x < ver + 1,
self._yaml_config.get_valid_python_versions(),
))
return 'python{0}'.format(ver)

@property
def python_version(self):
if 'version' in self._yaml_config.get('python', {}):
ver = self._yaml_config['python']['version']
return ver
return self._yaml_config['python']['version']
else:
if self._project.python_interpreter == 'python':
return 2
Expand Down Expand Up @@ -125,20 +126,36 @@ def load_yaml_config(version):
"""

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(
version.project.container_image,
BUILD_IMAGES.get(DOCKER_IMAGE, None),
)
if build_image:
env_config = {
'python': build_image['python'],
}

try:
sphinx_env_config = env_config.copy()
sphinx_env_config.update({
'output_base': '',
'type': 'sphinx',
'name': version.slug,
})
config = load_config(
path=checkout_path,
env_config={
'output_base': '',
'type': 'sphinx',
'name': version.slug,
},
env_config=sphinx_env_config,
)[0]
except InvalidConfig: # This is a subclass of ConfigError, so has to come first
raise
except ConfigError:
config = BuildConfig(
env_config={},
env_config=env_config,
raw_config={},
source_file='empty',
source_position=0,
Expand Down
14 changes: 14 additions & 0 deletions readthedocs/doc_builder/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

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

# Docker
DOCKER_SOCKET = getattr(settings, 'DOCKER_SOCKET', 'unix:///var/run/docker.sock')
DOCKER_VERSION = getattr(settings, 'DOCKER_VERSION', 'auto')
DOCKER_IMAGE = getattr(settings, 'DOCKER_IMAGE', 'rtfd-build')
Expand All @@ -25,3 +26,16 @@
DOCKER_OOM_EXIT_CODE = 137

DOCKER_HOSTNAME_MAX_LEN = 64

# Build images
BUILD_IMAGES = {
'readthedocs/build:14.04': {
'python': {'supported_versions': [2, 2.7, 3, 3.3]},
},
'readthedocs/build:16.04': {
'python': {'supported_versions': [2, 2.7, 3, 3.5]},
},
'readthedocs/build:beta': {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonder if this should be given a more specific name? Seems like we'll want to do stuff over time where beta isn't really reflective of, and we don't want it to conflict.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking about naming schemes myself, however I was considering how to make names more generic. I don't think it's important to have a 16.04 branch of names and a 14.04 branch of images. Perhaps we adopt semver versioning instead? I'll leave this for now, we can discuss versioning in the docker-images repo

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'python': {'supported_versions': [2, 2.7, 3, 3.3, 3.4, 3.5, 3.6]},
},
}
8 changes: 7 additions & 1 deletion readthedocs/projects/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from django.conf import settings
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _
from readthedocs_build.config import ConfigError

from readthedocs.builds.constants import (LATEST,
BUILD_STATE_CLONING,
Expand Down Expand Up @@ -132,7 +133,12 @@ def run(self, pk, version_pk=None, build_pk=None, record=True, docker=False,
status_code=423
)

self.config = load_yaml_config(version=self.version)
try:
self.config = load_yaml_config(version=self.version)
except ConfigError as e:
raise BuildEnvironmentError(
'Problem parsing YAML configuration. {0}'.format(str(e))
)

if self.setup_env.failure or self.config is None:
self._log('Failing build because of setup failure: %s' % self.setup_env.failure)
Expand Down
2 changes: 1 addition & 1 deletion requirements/pip.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ docutils==0.11
Sphinx==1.3.5
Pygments==2.0.2
mkdocs==0.14.0
git+https://github.com/rtfd/readthedocs-build.git@db4ad19df4f432bfbbd56d05964c58b6634356f3#egg=readthedocs-build-2.0.6.dev
git+https://github.com/rtfd/readthedocs-build.git@31082ec0e7c6597c8e05c0e821271aaacd715dc7#egg=readthedocs-build-2.0.7.dev
django==1.8.16

django-tastypie==0.12.2
Expand Down