diff --git a/conda_lock/src_parser/environment_yaml.py b/conda_lock/src_parser/environment_yaml.py index 02821c34..7cbab58f 100644 --- a/conda_lock/src_parser/environment_yaml.py +++ b/conda_lock/src_parser/environment_yaml.py @@ -114,6 +114,11 @@ def parse_environment_file( env_yaml_data = yaml.safe_load(content) channels: List[str] = env_yaml_data.get("channels", []) + try: + # conda-lock will use `--override-channels` so nodefaults is redundant. + channels.remove("nodefaults") + except ValueError: + pass # These extension fields are nonstandard category: str = env_yaml_data.get("category") or "main" diff --git a/tests/test-env-nodefaults/environment.yml b/tests/test-env-nodefaults/environment.yml new file mode 100644 index 00000000..382a0fd6 --- /dev/null +++ b/tests/test-env-nodefaults/environment.yml @@ -0,0 +1,5 @@ +channels: + - nodefaults + - conda-forge +dependencies: + - python <3.11 \ No newline at end of file diff --git a/tests/test_conda_lock.py b/tests/test_conda_lock.py index 6e325f57..86ab7730 100644 --- a/tests/test_conda_lock.py +++ b/tests/test_conda_lock.py @@ -138,6 +138,11 @@ def filter_conda_environment(tmp_path: Path): return x +@pytest.fixture +def nodefaults_environment(tmp_path: Path): + return clone_test_dir("test-env-nodefaults", tmp_path).joinpath("environment.yml") + + @pytest.fixture def pip_environment(tmp_path: Path): return clone_test_dir("test-pypi-resolve", tmp_path).joinpath("environment.yml") @@ -400,6 +405,11 @@ def test_parse_environment_file_with_pip(pip_environment: Path): ] +def test_parse_env_file_with_no_defaults(nodefaults_environment: Path): + res = parse_environment_file(nodefaults_environment, DEFAULT_PLATFORMS) + assert res.channels == [Channel.from_string("conda-forge")] + + def test_parse_env_file_with_filters_no_args(filter_conda_environment: Path): platforms = parse_platforms_from_env_file(filter_conda_environment) res = parse_environment_file(filter_conda_environment, platforms)