-
Notifications
You must be signed in to change notification settings - Fork 25
Add the ability to add a docker config image #33
Changes from 5 commits
827182b
2db1cec
9f17586
d766f41
d93c81c
4d8537d
3ae0685
23cf764
91d49ef
de3e359
b597d3b
73a184a
79f78d2
8e8164e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,12 +5,8 @@ | |
from .find import find_one | ||
from .parser import ParseError | ||
from .parser import parse | ||
from .validation import validate_bool | ||
from .validation import validate_choice | ||
from .validation import validate_directory | ||
from .validation import validate_file | ||
from .validation import validate_string | ||
from .validation import ValidationError | ||
from .validation import (validate_bool, validate_choice, validate_directory, | ||
validate_file, validate_string, ValidationError) | ||
|
||
|
||
__all__ = ( | ||
|
@@ -30,6 +26,18 @@ | |
TYPE_REQUIRED = 'type-required' | ||
PYTHON_INVALID = 'python-invalid' | ||
|
||
DOCKER_BUILD_IMAGES = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make this updatable from a setting as it was, so we can define a custome DOCKER_BUILD_IMAGES in our development instance. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm, good call. Hadn't thought of that specific use. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 on a setting, we shouldn't change that behavior. This is important for all non-prod instances. |
||
'1.0': { | ||
'python': {'supported_versions': [2, 2.7, 3, 3.4]}, | ||
}, | ||
'2.0': { | ||
'python': {'supported_versions': [2, 2.7, 3, 3.5]}, | ||
}, | ||
'latest': { | ||
'python': {'supported_versions': [2, 2.7, 3, 3.3, 3.4, 3.5, 3.6]}, | ||
}, | ||
} | ||
|
||
|
||
class ConfigError(Exception): | ||
|
||
|
@@ -79,6 +87,7 @@ class BuildConfig(dict): | |
'"python.extra_requirements" section must be a list.') | ||
|
||
PYTHON_SUPPORTED_VERSIONS = [2, 2.7, 3, 3.3, 3.4, 3.5, 3.6] | ||
DOCKER_SUPPORTED_VERSIONS = ['1.0', '2.0', 'latest'] | ||
|
||
def __init__(self, env_config, raw_config, source_file, source_position): | ||
self.env_config = env_config | ||
|
@@ -115,13 +124,6 @@ def get_valid_types(self): | |
'sphinx', | ||
) | ||
|
||
def get_valid_python_versions(self): | ||
try: | ||
return self.env_config['python']['supported_versions'] | ||
except (KeyError, TypeError): | ||
pass | ||
return self.PYTHON_SUPPORTED_VERSIONS | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the reason to remove this? Seems we want validation on this still. |
||
def get_valid_formats(self): | ||
return ( | ||
'none', | ||
|
@@ -145,6 +147,9 @@ def validate(self): | |
# Validate env_config. | ||
self.validate_output_base() | ||
|
||
# Validate the build environment first | ||
self.validate_build() # Must happen before `validate_python`! | ||
|
||
# Validate raw_config. Order matters. | ||
self.validate_name() | ||
self.validate_type() | ||
|
@@ -205,6 +210,23 @@ def validate_base(self): | |
base = validate_directory(base, base_path) | ||
self['base'] = base | ||
|
||
def validate_build(self): | ||
# Defaults | ||
build = {'image': '2.0'} | ||
if 'build' in self.raw_config: | ||
_build = self.raw_config['build'] | ||
if 'image' in _build: | ||
with self.catch_validation_error('build'): | ||
build['image'] = validate_choice( | ||
str(_build['image']), | ||
self.DOCKER_SUPPORTED_VERSIONS, | ||
) | ||
self['build'] = build | ||
|
||
# Set the valid python versions for this container | ||
img = build['image'] | ||
self.PYTHON_SUPPORTED_VERSIONS = DOCKER_BUILD_IMAGES[img]['python']['supported_versions'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The ordering of the validation is going to continue to matter (because we need to read the docker image, then determine python version), so it will have to set state somewhere, but agreed on making it a bit nicer. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe we are/were doing ordering of validation one level up anyways: So, dependencies would naturally be filled there, as the validation steps are ordered there |
||
|
||
def validate_python(self): | ||
python = { | ||
'use_system_site_packages': False, | ||
|
@@ -280,7 +302,7 @@ def validate_python(self): | |
pass | ||
python['version'] = validate_choice( | ||
version, | ||
self.get_valid_python_versions() | ||
self.PYTHON_SUPPORTED_VERSIONS | ||
) | ||
|
||
self['python'] = python | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -281,23 +281,6 @@ def it_validates_wrong_type_right_value(): | |
build.validate_python() | ||
assert build['python']['version'] == 3 | ||
|
||
def it_validates_env_supported_versions(): | ||
build = get_build_config( | ||
{'python': {'version': 3.6}}, | ||
env_config={'python': {'supported_versions': [3.5]}} | ||
) | ||
with raises(InvalidConfig) as excinfo: | ||
build.validate_python() | ||
assert excinfo.value.key == 'python.version' | ||
assert excinfo.value.code == INVALID_CHOICE | ||
|
||
build = get_build_config( | ||
{'python': {'version': 3.6}}, | ||
env_config={'python': {'supported_versions': [3.5, 3.6]}} | ||
) | ||
build.validate_python() | ||
assert build['python']['version'] == 3.6 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems we should make this error work instead of removing it. We use supported versions for giving intelligent errors to users. |
||
|
||
|
||
def describe_validate_formats(): | ||
|
||
|
@@ -413,6 +396,70 @@ def it_fails_if_base_does_not_exist(tmpdir): | |
assert excinfo.value.code == INVALID_PATH | ||
|
||
|
||
def describe_validate_build(): | ||
|
||
def it_fails_if_build_is_invalid_option(tmpdir): | ||
apply_fs(tmpdir, minimal_config) | ||
build = BuildConfig( | ||
{}, | ||
{'build': {'image': 3.0}}, | ||
source_file=str(tmpdir.join('readthedocs.yml')), | ||
source_position=0) | ||
with raises(InvalidConfig) as excinfo: | ||
build.validate_build() | ||
assert excinfo.value.key == 'build' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just curious, why we don't use something like regular There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is just how this code was written originally. shrug |
||
assert excinfo.value.code == INVALID_CHOICE | ||
|
||
def it_fails_on_python_validation(tmpdir): | ||
apply_fs(tmpdir, minimal_config) | ||
build = BuildConfig( | ||
{}, | ||
{ | ||
'build': {'image': 1.0}, | ||
'python': {'version': '3.3'}, | ||
}, | ||
source_file=str(tmpdir.join('readthedocs.yml')), | ||
source_position=0) | ||
build.validate_build() | ||
with raises(InvalidConfig) as excinfo: | ||
build.validate_python() | ||
assert excinfo.value.key == 'python.version' | ||
assert excinfo.value.code == INVALID_CHOICE | ||
|
||
def it_works_on_python_validation(tmpdir): | ||
apply_fs(tmpdir, minimal_config) | ||
build = BuildConfig( | ||
{}, | ||
{ | ||
'build': {'image': 'latest'}, | ||
'python': {'version': '3.3'}, | ||
}, | ||
source_file=str(tmpdir.join('readthedocs.yml')), | ||
source_position=0) | ||
build.validate_build() | ||
build.validate_python() | ||
|
||
def it_works(tmpdir): | ||
apply_fs(tmpdir, minimal_config) | ||
build = BuildConfig( | ||
{}, | ||
{'build': {'image': 'latest'}}, | ||
source_file=str(tmpdir.join('readthedocs.yml')), | ||
source_position=0) | ||
build.validate_build() | ||
assert build['build']['image'] == 'latest' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't we check here that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we're opinionated about this yet. We should be eventually though. +1 on checks for default version though, that seems to be missing from test cases |
||
|
||
def default(tmpdir): | ||
apply_fs(tmpdir, minimal_config) | ||
build = BuildConfig( | ||
{}, | ||
{}, | ||
source_file=str(tmpdir.join('readthedocs.yml')), | ||
source_position=0) | ||
build.validate_build() | ||
assert build['build']['image'] == '2.0' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here but 2.7, I guess. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure we want to specify python magically, based on container image, do we? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We already do this to a certain degree, but i think the python version tests are testing some of this. For example:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we don't want that, what would it happen if the user doesn't specify the python version? should the test fail? do we have a test for that? |
||
|
||
|
||
def test_build_validate_calls_all_subvalidators(tmpdir): | ||
apply_fs(tmpdir, minimal_config) | ||
build = BuildConfig( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
mock==1.3.0 | ||
pytest>=2.7 | ||
pytest-describe>=0.10.1 | ||
pytest==3.2.5 | ||
pytest-describe==0.11.0 | ||
pytest-xdist>=1.12 | ||
tox>=2.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps "docker image" -> "build image" for consistency on nomenclature. It's not a docker image to end users, nor can arbitrary docker images be used.