diff --git a/readthedocs/config/config.py b/readthedocs/config/config.py index b5e56c98d48..3373c89bc7f 100644 --- a/readthedocs/config/config.py +++ b/readthedocs/config/config.py @@ -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"}, diff --git a/readthedocs/config/tests/test_config.py b/readthedocs/config/tests/test_config.py index 64e9ccf14ad..8acab42b064 100644 --- a/readthedocs/config/tests/test_config.py +++ b/readthedocs/config/tests/test_config.py @@ -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})