From 2041df24c24a65aac1f3973188e2e529fef37874 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Thu, 26 Dec 2024 16:24:36 +0100 Subject: [PATCH] Fix flattening nested if/else blocks Probably fixes #2165 --- conda_smithy/linter/utils.py | 4 ++-- news/fix-if-else-in-run.rst | 1 + tests/recipes/v1_recipes/torchvision.yaml | 12 ++++++------ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/conda_smithy/linter/utils.py b/conda_smithy/linter/utils.py index 281d43c0f..5c9ccfddc 100644 --- a/conda_smithy/linter/utils.py +++ b/conda_smithy/linter/utils.py @@ -236,8 +236,8 @@ def flatten_v1_if_else(requirements: list[str | dict]) -> list[str]: flattened_requirements = [] for req in requirements: if isinstance(req, dict): - flattened_requirements.extend(req["then"]) - flattened_requirements.extend(req.get("else") or []) + flattened_requirements.extend(flatten_v1_if_else(req["then"])) + flattened_requirements.extend(flatten_v1_if_else(req.get("else") or [])) else: flattened_requirements.append(req) return flattened_requirements diff --git a/news/fix-if-else-in-run.rst b/news/fix-if-else-in-run.rst index 8a4b6ba70..b47bab217 100644 --- a/news/fix-if-else-in-run.rst +++ b/news/fix-if-else-in-run.rst @@ -17,6 +17,7 @@ **Fixed:** * Fix handling ``if``/``else`` blocks in ``run`` and ``run_constraints`` requirements, for v1 recipes (#2197) +* Fix flattening nested ``if``/``else`` blocks in v1 recipes (#2197) **Security:** diff --git a/tests/recipes/v1_recipes/torchvision.yaml b/tests/recipes/v1_recipes/torchvision.yaml index 10311fe78..0f943464b 100644 --- a/tests/recipes/v1_recipes/torchvision.yaml +++ b/tests/recipes/v1_recipes/torchvision.yaml @@ -114,18 +114,18 @@ outputs: - ${{ compiler('cuda') }} # avoid nested conditions because of # https://github.com/conda-forge/conda-smithy/issues/2165 - - if: build_platform != target_platform and cuda_compiler_version != "None" - then: - - libcublas-dev - - libcusolver-dev - - libcusparse-dev - - libnvjpeg-dev - if: build_platform != target_platform then: - python - cross-python_${{ target_platform }} # - numpy - pytorch ${{ compatible_pytorch }}.* [build=${{ torch_proc_type }}*] + - if: cuda_compiler_version != "None" + then: + - libcublas-dev + - libcusolver-dev + - libcusparse-dev + - libnvjpeg-dev host: - python # - numpy