Skip to content

Commit

Permalink
Showing 2 changed files with 23 additions and 2 deletions.
6 changes: 5 additions & 1 deletion readthedocs/config/config.py
Original file line number Diff line number Diff line change
@@ -167,6 +167,10 @@ def validate(self):
def is_using_conda(self):
return self.python_interpreter in ("conda", "mamba")

@property
def is_using_build_commands(self):
return self.build.commands != []

@property
def is_using_setup_py_install(self):
"""Check if this project is using `setup.py install` as installation method."""
@@ -260,7 +264,7 @@ def validate_conda(self):
"""Validates the conda key."""
raw_conda = self._raw_config.get('conda')
if raw_conda is None:
if self.is_using_conda:
if self.is_using_conda and not self.is_using_build_commands:
raise ConfigError(
message_id=ConfigError.CONDA_KEY_REQUIRED,
format_values={"key": "conda"},
19 changes: 18 additions & 1 deletion readthedocs/config/tests/test_config.py
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@
import re
import textwrap
from collections import OrderedDict
from contextlib import nullcontext as does_not_raise

import pytest
from django.conf import settings
@@ -293,12 +294,28 @@ def test_conda_key_required_for_conda_mamba(self):
},
}
)
print(build)
with raises(ConfigError) as excinfo:
build.validate()
assert excinfo.value.message_id == ConfigError.CONDA_KEY_REQUIRED
assert excinfo.value.format_values.get("key") == "conda"

def test_conda_key_not_required_for_conda_mamba_when_build_commands(self):
build = get_build_config(
{
"build": {
"os": "ubuntu-22.04",
"tools": {
"python": "mambaforge-22.9",
},
"commands": [
"mamba env create --file environment.yml",
],
},
}
)
with does_not_raise(ConfigError):
build.validate()

@pytest.mark.parametrize("value", [3, [], "invalid"])
def test_conda_check_invalid_value(self, value):
build = get_build_config({"conda": value})

0 comments on commit 7d7ad16

Please sign in to comment.