Skip to content

Require conda.file when using conda in v1 #5338

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 2 commits into from
Feb 22, 2019
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
17 changes: 8 additions & 9 deletions readthedocs/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,15 +489,14 @@ def validate_conda(self):
raw_conda = self.raw_config['conda']
with self.catch_validation_error('conda'):
validate_dict(raw_conda)
conda_environment = None
if 'file' in raw_conda:
with self.catch_validation_error('conda.file'):
conda_environment = validate_file(
raw_conda['file'],
self.base_path,
)
conda['environment'] = conda_environment

with self.catch_validation_error('conda.file'):
if 'file' not in raw_conda:
raise ValidationError('file', VALUE_NOT_FOUND)
conda_environment = validate_file(
raw_conda['file'],
self.base_path,
)
conda['environment'] = conda_environment
return conda
return None

Expand Down
20 changes: 12 additions & 8 deletions readthedocs/config/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,29 +557,33 @@ def test_it_priorities_image_from_env_config(self, tmpdir, image):
assert build.build.image == image


def test_use_conda_default_false():
def test_use_conda_default_none():
build = get_build_config({})
build.validate()
assert build.conda is None


def test_use_conda_respects_config():
def test_validates_conda_file(tmpdir):
apply_fs(tmpdir, {'environment.yml': ''})
build = get_build_config(
{'conda': {}},
{'conda': {'file': 'environment.yml'}},
source_file=str(tmpdir.join('readthedocs.yml')),
)
build.validate()
assert isinstance(build.conda, Conda)
assert build.conda.environment == str(tmpdir.join('environment.yml'))


def test_validates_conda_file(tmpdir):
def test_file_is_required_when_using_conda(tmpdir):
apply_fs(tmpdir, {'environment.yml': ''})
build = get_build_config(
{'conda': {'file': 'environment.yml'}},
{'conda': {'foo': 'environment.yml'}},
source_file=str(tmpdir.join('readthedocs.yml')),
)
build.validate()
assert isinstance(build.conda, Conda)
assert build.conda.environment == str(tmpdir.join('environment.yml'))
with raises(InvalidConfig) as excinfo:
build.validate()
assert excinfo.value.key == 'conda.file'
assert excinfo.value.code == VALUE_NOT_FOUND


def test_requirements_file_empty():
Expand Down