From cf0d667ae925f24e9dc329738497cd4600dc816f Mon Sep 17 00:00:00 2001 From: Ben Mares Date: Mon, 29 May 2023 00:28:13 +0200 Subject: [PATCH] Handle nodefaults in all specs --- conda_lock/models/lock_spec.py | 5 ++++- conda_lock/src_parser/meta_yaml.py | 5 +++++ conda_lock/src_parser/pyproject_toml.py | 9 ++++++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/conda_lock/models/lock_spec.py b/conda_lock/models/lock_spec.py index ded75198..cb561544 100644 --- a/conda_lock/models/lock_spec.py +++ b/conda_lock/models/lock_spec.py @@ -81,5 +81,8 @@ def content_hash_for_platform(self, platform: str) -> str: def validate_channels(cls, v: List[Union[Channel, str]]) -> List[Channel]: for i, e in enumerate(v): if isinstance(e, str): - v[i] = Channel.from_string(e) + e = Channel.from_string(e) + v[i] = e + if e.url == "nodefaults": + raise ValueError("nodefaults channel is not allowed, ref #418") return typing.cast(List[Channel], v) diff --git a/conda_lock/src_parser/meta_yaml.py b/conda_lock/src_parser/meta_yaml.py index c85b4a9f..79470027 100644 --- a/conda_lock/src_parser/meta_yaml.py +++ b/conda_lock/src_parser/meta_yaml.py @@ -103,6 +103,11 @@ def parse_meta_yaml_file( meta_yaml_data = yaml.safe_load(rendered) channels = get_in(["extra", "channels"], meta_yaml_data, []) + try: + # conda-lock will use `--override-channels` so nodefaults is redundant. + channels.remove("nodefaults") + except ValueError: + pass # parse with selectors for each target platform dep_map = { diff --git a/conda_lock/src_parser/pyproject_toml.py b/conda_lock/src_parser/pyproject_toml.py index 25aff242..db7a02ff 100644 --- a/conda_lock/src_parser/pyproject_toml.py +++ b/conda_lock/src_parser/pyproject_toml.py @@ -299,9 +299,16 @@ def specification_with_dependencies( if dep.name in force_pypi: dep.manager = "pip" + channels = get_in(["tool", "conda-lock", "channels"], toml_contents, []) + try: + # conda-lock will use `--override-channels` so nodefaults is redundant. + channels.remove("nodefaults") + except ValueError: + pass + return LockSpecification( dependencies={platform: dependencies for platform in platforms}, - channels=get_in(["tool", "conda-lock", "channels"], toml_contents, []), + channels=channels, sources=[path], allow_pypi_requests=get_in( ["tool", "conda-lock", "allow-pypi-requests"], toml_contents, True