Skip to content

Config: allow missing conda.environment when using build.commands #11040

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 1 commit into from
Jan 18, 2024
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
6 changes: 5 additions & 1 deletion readthedocs/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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"},
Expand Down
19 changes: 18 additions & 1 deletion readthedocs/config/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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})
Expand Down