From 0b2e9e3005255e92df4cc1be359edc04fd5c2ff6 Mon Sep 17 00:00:00 2001 From: Cornelius Roemer Date: Thu, 18 Jul 2024 23:47:33 +0200 Subject: [PATCH 1/8] fix: use copy(v) which works also on str, instead of v.copy() which doesn't resolves #5416 resolves #3404 (closed because stale, not because fixed) Bug was possibly introduced in #3344 --- conda_build/variants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conda_build/variants.py b/conda_build/variants.py index b185a7eb34..fe659067e8 100644 --- a/conda_build/variants.py +++ b/conda_build/variants.py @@ -328,7 +328,7 @@ def _combine_spec_dictionaries( ) != len(ensure_list(v)): break else: - values[k] = v.copy() + values[k] = copy(v) missing_subvalues = [ subvalue for subvalue in ensure_list(v) From 0ad4bb6829b440caae9ae8a4db14ab1ff3788ab7 Mon Sep 17 00:00:00 2001 From: "Matthew R. Becker" Date: Fri, 15 Nov 2024 12:53:56 -0600 Subject: [PATCH 2/8] fix: catch `CondaBuildUserError` w/ `SystemExit` (#5538) * fix: catch user errors in `distribute_variants` * fix: catch a few more SystemExits * test: add test to ensure undefine jinja2 is OK * doc: add news --- conda_build/metadata.py | 4 +-- conda_build/render.py | 4 +-- news/5538-sysexit-vs-cdusererror | 20 ++++++++++++++ tests/test_api_render.py | 45 ++++++++++++++++++++++++++++++++ 4 files changed, 69 insertions(+), 4 deletions(-) create mode 100644 news/5538-sysexit-vs-cdusererror diff --git a/conda_build/metadata.py b/conda_build/metadata.py index 278d56eb1e..5cc5bc129a 100644 --- a/conda_build/metadata.py +++ b/conda_build/metadata.py @@ -2579,7 +2579,7 @@ def get_output_metadata_set( ref_metadata.parse_until_resolved( allow_no_other_outputs=True, bypass_env_check=True ) - except SystemExit: + except (SystemExit, CondaBuildUserError): pass outputs = get_output_dicts_from_metadata(ref_metadata) @@ -2611,7 +2611,7 @@ def get_output_metadata_set( ref_metadata.other_outputs = out_metadata.other_outputs = ( all_output_metadata ) - except SystemExit: + except (SystemExit, CondaBuildUserError): if not permit_undefined_jinja: raise output_tuples = [] diff --git a/conda_build/render.py b/conda_build/render.py index f6cfda491c..6292210301 100644 --- a/conda_build/render.py +++ b/conda_build/render.py @@ -34,7 +34,7 @@ from . import environ, exceptions, source, utils from .config import CondaPkgFormat -from .exceptions import DependencyNeedsBuildingError +from .exceptions import CondaBuildUserError, DependencyNeedsBuildingError from .index import get_build_index from .metadata import MetaData, MetaDataTuple, combine_top_level_metadata_with_output from .utils import ( @@ -894,7 +894,7 @@ def distribute_variants( allow_no_other_outputs=allow_no_other_outputs, bypass_env_check=bypass_env_check, ) - except SystemExit: + except (SystemExit, CondaBuildUserError): pass need_source_download = not mv.needs_source_for_render or not mv.source_provided diff --git a/news/5538-sysexit-vs-cdusererror b/news/5538-sysexit-vs-cdusererror new file mode 100644 index 0000000000..b01e596601 --- /dev/null +++ b/news/5538-sysexit-vs-cdusererror @@ -0,0 +1,20 @@ +### Enhancements + +* + +### Bug fixes + +* Fixed a bug where some ``CondaBuildUserError`` exceptions that were formally ``SystemExit`` exceptions + were not being caught properly. (#5538) + +### Deprecations + +* + +### Docs + +* + +### Other + +* diff --git a/tests/test_api_render.py b/tests/test_api_render.py index 0882de0df1..eb75a283d9 100644 --- a/tests/test_api_render.py +++ b/tests/test_api_render.py @@ -7,6 +7,7 @@ import os import re +import textwrap from itertools import count, islice import pytest @@ -15,6 +16,7 @@ from conda.common.compat import on_win from conda_build import api, render +from conda_build.exceptions import CondaBuildUserError from conda_build.variants import validate_spec from .utils import metadata_dir, variants_dir @@ -341,3 +343,46 @@ def create_variants(): recipe, config=testing_config, channels=[], variants=create_variants() ) assert len(metadata_tuples) == 11 - 3 # omits libarrow-all, pyarrow, pyarrow-tests + + +def test_api_render_missing_jinja2(testing_config, testing_workdir): + with open(os.path.join(testing_workdir, "meta.yaml"), "w") as f: + f.write( + textwrap.dedent( + """ + package: + name: blah-{{ foo }} + version: 0.1 + + build: + number: 0 + + requirements: + host: + - python {{ python_min }} + run: + - python + """ + ) + ) + + meta = api.render( + testing_workdir, + finalize=False, + bypass_env_check=True, + trim_skip=False, + ) + assert meta is not None + assert any("python" in val for val in meta[0][0].get_value("requirements/host")) + assert not any( + "{{ python_min }}" in val for val in meta[0][0].get_value("requirements/run") + ) + assert meta[0][0].get_value("package/name") == "blah-" + + with pytest.raises(CondaBuildUserError): + api.render( + testing_workdir, + finalize=True, + bypass_env_check=True, + trim_skip=False, + ) From 03f99c1d72d1c444e32eee9c7057aa5684728c59 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 18 Nov 2024 11:57:55 -0500 Subject: [PATCH 3/8] [pre-commit.ci] pre-commit autoupdate (#5544) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.7.3 → v0.7.4](https://github.com/astral-sh/ruff-pre-commit/compare/v0.7.3...v0.7.4) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2cbfc4dd0e..6271a02d66 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -58,7 +58,7 @@ repos: # auto format Python codes within docstrings - id: blacken-docs - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.7.3 + rev: v0.7.4 hooks: # lint & attempt to correct failures (e.g. pyupgrade) - id: ruff From 2d893191999fa18b6b84cef117bf3aefb973d6ad Mon Sep 17 00:00:00 2001 From: conda-bot <18747875+conda-bot@users.noreply.github.com> Date: Mon, 25 Nov 2024 10:20:59 +0100 Subject: [PATCH 4/8] =?UTF-8?q?=F0=9F=A4=96=20Update=20infrastructure=20fi?= =?UTF-8?q?le(s)=20(#5553)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cla.yml | 2 +- .github/workflows/stale.yml | 2 +- .github/workflows/update.yml | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/cla.yml b/.github/workflows/cla.yml index ddc0516324..04b3e1c3b3 100644 --- a/.github/workflows/cla.yml +++ b/.github/workflows/cla.yml @@ -18,7 +18,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Check CLA - uses: conda/actions/check-cla@15f883f14f4232f83658e3609c3316d58905138f # v24.8.0 + uses: conda/actions/check-cla@6e72e0db87e72f0020e493aeb02f864363bd9258 # v24.11.1 with: # [required] # A token with ability to comment, label, and modify the commit status diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 9d23fbe661..cf82ffe232 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -33,7 +33,7 @@ jobs: days-before-issue-stale: 90 days-before-issue-close: 21 steps: - - uses: conda/actions/read-yaml@15f883f14f4232f83658e3609c3316d58905138f # v24.8.0 + - uses: conda/actions/read-yaml@6e72e0db87e72f0020e493aeb02f864363bd9258 # v24.11.1 id: read_yaml with: path: https://raw.githubusercontent.com/conda/infra/main/.github/messages.yml diff --git a/.github/workflows/update.yml b/.github/workflows/update.yml index df69f36aa0..90ee32b646 100644 --- a/.github/workflows/update.yml +++ b/.github/workflows/update.yml @@ -55,11 +55,11 @@ jobs: git config --global user.name 'Conda Bot' git config --global user.email '18747875+conda-bot@users.noreply.github.com' - - uses: conda/actions/combine-durations@15f883f14f4232f83658e3609c3316d58905138f # v24.8.0 + - uses: conda/actions/combine-durations@6e72e0db87e72f0020e493aeb02f864363bd9258 # v24.11.1 id: durations continue-on-error: true - - uses: conda/actions/template-files@15f883f14f4232f83658e3609c3316d58905138f # v24.8.0 + - uses: conda/actions/template-files@6e72e0db87e72f0020e493aeb02f864363bd9258 # v24.11.1 id: templates continue-on-error: true From 8d0ca34ed319b114d017651fab756445204d4346 Mon Sep 17 00:00:00 2001 From: "Matthew R. Becker" Date: Tue, 26 Nov 2024 04:27:46 -0600 Subject: [PATCH 5/8] fix: allow incomplete specs during intermediate parsing stages (#5555) * fix: allow incomplete specs if undefined jinja2 * refactor: skip it instead * refactor: simpler * style: pre the commit * style: no extra whitespace * test: add test * test: fix tests --- conda_build/metadata.py | 23 ++++++-- ...555-skip-bad-specs-while-still-parsing.rst | 19 +++++++ tests/test_api_build.py | 2 +- tests/test_metadata.py | 53 +++++++++++++++++++ 4 files changed, 91 insertions(+), 6 deletions(-) create mode 100644 news/5555-skip-bad-specs-while-still-parsing.rst diff --git a/conda_build/metadata.py b/conda_build/metadata.py index 5cc5bc129a..2b8443e68c 100644 --- a/conda_build/metadata.py +++ b/conda_build/metadata.py @@ -1597,21 +1597,34 @@ def ms_depends(self, typ="run"): try: ms = MatchSpec(spec) except AssertionError: - raise RuntimeError(f"Invalid package specification: {spec!r}") + if len(self.undefined_jinja_vars) == 0: + raise RuntimeError(f"Invalid package specification: {spec!r}") + else: + continue except (AttributeError, ValueError) as e: - raise RuntimeError( - "Received dictionary as spec. Note that pip requirements are " - "not supported in conda-build meta.yaml. Error message: " + str(e) - ) + if len(self.undefined_jinja_vars) == 0: + raise RuntimeError( + "Received dictionary as spec. Note that pip requirements are " + "not supported in conda-build meta.yaml. Error message: " + + str(e) + ) + else: + continue + if ms.name == self.name() and not ( typ == "build" and self.config.host_subdir != self.config.build_subdir ): raise RuntimeError(f"{self.name()} cannot depend on itself") + + # TODO: IDK what this does since AFAIK the inner continue applies only + # to the inner loop for name, ver in name_ver_list: if ms.name == name: if self.noarch: continue + # TODO: the validation here appears to be a waste of time since MatchSpec + # appears to validate? for c in "=!@#$%^&*:;\"'\\|<>?/": if c in ms.name: sys.exit( diff --git a/news/5555-skip-bad-specs-while-still-parsing.rst b/news/5555-skip-bad-specs-while-still-parsing.rst new file mode 100644 index 0000000000..1454fb9bad --- /dev/null +++ b/news/5555-skip-bad-specs-while-still-parsing.rst @@ -0,0 +1,19 @@ +### Enhancements + +* + +### Bug fixes + +* Fixed a bug where bad match specs from intermediate parsing results would cause parsing to fail. (#5555) + +### Deprecations + +* + +### Docs + +* + +### Other + +* diff --git a/tests/test_api_build.py b/tests/test_api_build.py index d6a519cc5a..3e70dd64fe 100644 --- a/tests/test_api_build.py +++ b/tests/test_api_build.py @@ -2082,7 +2082,7 @@ def test_conda_build_script_errors_without_conda_info_handlers(tmp_path, recipe, def test_api_build_inject_jinja2_vars_on_first_pass(testing_config): recipe_dir = os.path.join(metadata_dir, "_inject_jinja2_vars_on_first_pass") - with pytest.raises(RuntimeError): + with pytest.raises((RuntimeError, CondaBuildUserError)): api.build(recipe_dir, config=testing_config) testing_config.variant = {"python_min": "3.12"} diff --git a/tests/test_metadata.py b/tests/test_metadata.py index d5feecf53c..3985bdc1df 100644 --- a/tests/test_metadata.py +++ b/tests/test_metadata.py @@ -655,3 +655,56 @@ def test_parse_until_resolved_skip_avoids_undefined_jinja( pytest.fail( "Undefined variable caused error, even though this build is skipped" ) + + +@pytest.mark.parametrize("have_variant", [True, False]) +def test_parse_until_resolved_missing_jinja_in_spec( + testing_metadata: MetaData, + tmp_path: Path, + have_variant: bool, +) -> None: + (recipe := tmp_path / (name := "meta.yaml")).write_text( + """ +package: + name: dummy + version: 1.0.0 + +build: + noarch: python + number: 0 + +requirements: + host: + - python ={{ python_min }} + run: + - python >={{ python_min }} +""" + ) + (tmp_path / "conda_build_config.yaml").write_text( + """ +python_min: + - 3.6 +""" + ) + testing_metadata._meta_path = recipe + testing_metadata._meta_name = name + if have_variant: + testing_metadata.config.variant = {"python_min": "3.6"} + else: + delattr(testing_metadata.config, "variant") + delattr(testing_metadata.config, "variant_config_files") + delattr(testing_metadata.config, "variants") + + try: + testing_metadata.parse_until_resolved() + if not have_variant: + pytest.fail("Undefined variable did NOT cause spec parsing error!") + else: + print("parsed OK!") + except (Exception, SystemExit): + if have_variant: + pytest.fail( + "Undefined variable caused spec parsing error even if we have the variant!" + ) + else: + print("did not parse OK!") From 7d5e991117d431078ed23a175f5896f8a10497c4 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 26 Nov 2024 04:54:13 -0600 Subject: [PATCH 6/8] doc: add news item --- news/5417-fix-str-copy.rst | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 news/5417-fix-str-copy.rst diff --git a/news/5417-fix-str-copy.rst b/news/5417-fix-str-copy.rst new file mode 100644 index 0000000000..ddac53eedc --- /dev/null +++ b/news/5417-fix-str-copy.rst @@ -0,0 +1,19 @@ +### Enhancements + +* + +### Bug fixes + +* Fixed a bug where ``.copy()`` was used on a string instead of ``copy()`` when processing variants. (#5417) + +### Deprecations + +* + +### Docs + +* + +### Other + +* From 18edc99e3564a1f01952587017823cb6a41db71d Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 26 Nov 2024 05:01:42 -0600 Subject: [PATCH 7/8] test: added test for zipkeys insert at same length --- tests/test_variants.py | 161 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 161 insertions(+) diff --git a/tests/test_variants.py b/tests/test_variants.py index 572d6362bf..95ac31bcb1 100644 --- a/tests/test_variants.py +++ b/tests/test_variants.py @@ -899,3 +899,164 @@ def test_find_used_variables_in_batch_script(tmp_path: Path) -> None: f"${{{variants[3]}}}\n" ) assert find_used_variables_in_batch_script(variants, script) == {"FOO", "BAR"} + + +def test_combine_specs_zip_lengths(): + from collections import OrderedDict + + # test case extracted from issue #5416 + specs = OrderedDict( + [ + ( + "internal_defaults", + { + "c_compiler": "gcc", + "cpu_optimization_target": "nocona", + "cran_mirror": "https://cran.r-project.org", + "cxx_compiler": "gxx", + "extend_keys": [ + "pin_run_as_build", + "ignore_version", + "ignore_build_only_deps", + "extend_keys", + ], + "fortran_compiler": "gfortran", + "ignore_build_only_deps": ["python", "numpy"], + "ignore_version": [], + "lua": "5", + "numpy": "1.23", + "perl": "5.26.2", + "pin_run_as_build": { + "python": {"max_pin": "x.x", "min_pin": "x.x"}, + "r-base": {"max_pin": "x.x", "min_pin": "x.x"}, + }, + "python": "3.11", + "r_base": "3.5", + "target_platform": "linux-64", + }, + ), + ( + "/tmp/tmp0wue6mdn/info/recipe/conda_build_config.yaml", + { + "VERBOSE_AT": "V=1", + "VERBOSE_CM": "VERBOSE=1", + "blas_impl": "openblas", + "boost": "1.82", + "boost_cpp": "1.82", + "bzip2": "1.0", + "c_compiler": "gcc", + "c_compiler_version": "11.2.0", + "cairo": "1.16", + "channel_targets": "defaults", + "clang_variant": "clang", + "cpu_optimization_target": "nocona", + "cran_mirror": "https://mran.microsoft.com/snapshot/2018-01-01", + "cuda_compiler": "cuda-nvcc", + "cuda_compiler_version": "12.4", + "cudatoolkit": "11.8", + "cudnn": "8.9.2.26", + "cxx_compiler": "gxx", + "cxx_compiler_version": "11.2.0", + "cyrus_sasl": "2.1.28", + "dbus": "1", + "expat": "2", + "extend_keys": [ + "pin_run_as_build", + "extend_keys", + "ignore_build_only_deps", + "ignore_version", + ], + "fontconfig": "2.14", + "fortran_compiler": "gfortran", + "fortran_compiler_version": "11.2.0", + "freetype": "2.10", + "g2clib": "1.6", + "geos": "3.8.0", + "giflib": "5", + "glib": "2", + "gmp": "6.2", + "gnu": "2.12.2", + "gpu_variant": "cuda-11", + "gst_plugins_base": "1.14", + "gstreamer": "1.14", + "harfbuzz": "4.3.0", + "hdf4": "4.2", + "hdf5": "1.12.1", + "hdfeos2": "2.20", + "hdfeos5": "5.1", + "icu": "73", + "ignore_build_only_deps": ["python", "numpy"], + "jpeg": "9", + "libcurl": "8.1.1", + "libdap4": "3.19", + "libffi": "3.4", + "libgd": "2.3.3", + "libgdal": "3.6.2", + "libgsasl": "1.10", + "libkml": "1.3", + "libnetcdf": "4.8", + "libpng": "1.6", + "libprotobuf": "3.20.3", + "libtiff": "4.2", + "libwebp": "1.3.2", + "libxml2": "2.10", + "libxslt": "1.1", + "llvm_variant": "llvm", + "lua": "5", + "lzo": "2", + "mkl": "2023.*", + "mpfr": "4", + "numpy": "1.21", + "openblas": "0.3.21", + "openjpeg": "2.3", + "openssl": "3.0", + "perl": "5.34", + "pin_run_as_build": { + "libboost": {"max_pin": "x.x.x"}, + "python": {"max_pin": "x.x", "min_pin": "x.x"}, + "r-base": {"max_pin": "x.x", "min_pin": "x.x"}, + }, + "pixman": "0.40", + "proj": "9.3.1", + "proj4": "5.2.0", + "python": "3.9", + "python_impl": "cpython", + "python_implementation": "cpython", + "r_base": "3.5", + "r_implementation": "r-base", + "r_version": "3.5.0", + "readline": "8.1", + "rust_compiler": "rust", + "rust_compiler_version": "1.71.1", + "sqlite": "3", + "target_platform": "linux-64", + "tk": "8.6", + "xz": "5", + "zip_keys": [["python", "numpy"]], + "zlib": "1.2", + "zstd": "1.5.2", + }, + ), + ( + "config.variant", + { + "__cuda": "__cuda >=11.8", + "blas_impl": "openblas", + "c_compiler": "gcc", + "c_compiler_version": "11.2.0", + "channel_targets": "defaults", + "cudatoolkit": "11.8", + "cudnn": "8.9.2.26", + "cxx_compiler": "gxx", + "cxx_compiler_version": "11.2.0", + "gpu_variant": "cuda-11", + "libprotobuf": "3.20.3", + "numpy": "1.21", + "openblas": "0.3.21", + "target_platform": "linux-64", + }, + ), + ] + ) + + combine_specs(specs, log_output=True) From 8f3f22cd598898baaf10337ddc95f6a7aaa02a32 Mon Sep 17 00:00:00 2001 From: Ken Odegard Date: Tue, 26 Nov 2024 07:37:20 -0600 Subject: [PATCH 8/8] Revert non-24.11.x changes --- .github/workflows/cla.yml | 2 +- .github/workflows/stale.yml | 2 +- .github/workflows/update.yml | 4 +- .pre-commit-config.yaml | 2 +- conda_build/metadata.py | 27 +++------- conda_build/render.py | 4 +- news/5538-sysexit-vs-cdusererror | 20 ------- ...555-skip-bad-specs-while-still-parsing.rst | 19 ------- tests/test_api_build.py | 2 +- tests/test_api_render.py | 45 ---------------- tests/test_metadata.py | 53 ------------------- 11 files changed, 15 insertions(+), 165 deletions(-) delete mode 100644 news/5538-sysexit-vs-cdusererror delete mode 100644 news/5555-skip-bad-specs-while-still-parsing.rst diff --git a/.github/workflows/cla.yml b/.github/workflows/cla.yml index 04b3e1c3b3..ddc0516324 100644 --- a/.github/workflows/cla.yml +++ b/.github/workflows/cla.yml @@ -18,7 +18,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Check CLA - uses: conda/actions/check-cla@6e72e0db87e72f0020e493aeb02f864363bd9258 # v24.11.1 + uses: conda/actions/check-cla@15f883f14f4232f83658e3609c3316d58905138f # v24.8.0 with: # [required] # A token with ability to comment, label, and modify the commit status diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index cf82ffe232..9d23fbe661 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -33,7 +33,7 @@ jobs: days-before-issue-stale: 90 days-before-issue-close: 21 steps: - - uses: conda/actions/read-yaml@6e72e0db87e72f0020e493aeb02f864363bd9258 # v24.11.1 + - uses: conda/actions/read-yaml@15f883f14f4232f83658e3609c3316d58905138f # v24.8.0 id: read_yaml with: path: https://raw.githubusercontent.com/conda/infra/main/.github/messages.yml diff --git a/.github/workflows/update.yml b/.github/workflows/update.yml index 90ee32b646..df69f36aa0 100644 --- a/.github/workflows/update.yml +++ b/.github/workflows/update.yml @@ -55,11 +55,11 @@ jobs: git config --global user.name 'Conda Bot' git config --global user.email '18747875+conda-bot@users.noreply.github.com' - - uses: conda/actions/combine-durations@6e72e0db87e72f0020e493aeb02f864363bd9258 # v24.11.1 + - uses: conda/actions/combine-durations@15f883f14f4232f83658e3609c3316d58905138f # v24.8.0 id: durations continue-on-error: true - - uses: conda/actions/template-files@6e72e0db87e72f0020e493aeb02f864363bd9258 # v24.11.1 + - uses: conda/actions/template-files@15f883f14f4232f83658e3609c3316d58905138f # v24.8.0 id: templates continue-on-error: true diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6271a02d66..2cbfc4dd0e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -58,7 +58,7 @@ repos: # auto format Python codes within docstrings - id: blacken-docs - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.7.4 + rev: v0.7.3 hooks: # lint & attempt to correct failures (e.g. pyupgrade) - id: ruff diff --git a/conda_build/metadata.py b/conda_build/metadata.py index 2b8443e68c..278d56eb1e 100644 --- a/conda_build/metadata.py +++ b/conda_build/metadata.py @@ -1597,34 +1597,21 @@ def ms_depends(self, typ="run"): try: ms = MatchSpec(spec) except AssertionError: - if len(self.undefined_jinja_vars) == 0: - raise RuntimeError(f"Invalid package specification: {spec!r}") - else: - continue + raise RuntimeError(f"Invalid package specification: {spec!r}") except (AttributeError, ValueError) as e: - if len(self.undefined_jinja_vars) == 0: - raise RuntimeError( - "Received dictionary as spec. Note that pip requirements are " - "not supported in conda-build meta.yaml. Error message: " - + str(e) - ) - else: - continue - + raise RuntimeError( + "Received dictionary as spec. Note that pip requirements are " + "not supported in conda-build meta.yaml. Error message: " + str(e) + ) if ms.name == self.name() and not ( typ == "build" and self.config.host_subdir != self.config.build_subdir ): raise RuntimeError(f"{self.name()} cannot depend on itself") - - # TODO: IDK what this does since AFAIK the inner continue applies only - # to the inner loop for name, ver in name_ver_list: if ms.name == name: if self.noarch: continue - # TODO: the validation here appears to be a waste of time since MatchSpec - # appears to validate? for c in "=!@#$%^&*:;\"'\\|<>?/": if c in ms.name: sys.exit( @@ -2592,7 +2579,7 @@ def get_output_metadata_set( ref_metadata.parse_until_resolved( allow_no_other_outputs=True, bypass_env_check=True ) - except (SystemExit, CondaBuildUserError): + except SystemExit: pass outputs = get_output_dicts_from_metadata(ref_metadata) @@ -2624,7 +2611,7 @@ def get_output_metadata_set( ref_metadata.other_outputs = out_metadata.other_outputs = ( all_output_metadata ) - except (SystemExit, CondaBuildUserError): + except SystemExit: if not permit_undefined_jinja: raise output_tuples = [] diff --git a/conda_build/render.py b/conda_build/render.py index 6292210301..f6cfda491c 100644 --- a/conda_build/render.py +++ b/conda_build/render.py @@ -34,7 +34,7 @@ from . import environ, exceptions, source, utils from .config import CondaPkgFormat -from .exceptions import CondaBuildUserError, DependencyNeedsBuildingError +from .exceptions import DependencyNeedsBuildingError from .index import get_build_index from .metadata import MetaData, MetaDataTuple, combine_top_level_metadata_with_output from .utils import ( @@ -894,7 +894,7 @@ def distribute_variants( allow_no_other_outputs=allow_no_other_outputs, bypass_env_check=bypass_env_check, ) - except (SystemExit, CondaBuildUserError): + except SystemExit: pass need_source_download = not mv.needs_source_for_render or not mv.source_provided diff --git a/news/5538-sysexit-vs-cdusererror b/news/5538-sysexit-vs-cdusererror deleted file mode 100644 index b01e596601..0000000000 --- a/news/5538-sysexit-vs-cdusererror +++ /dev/null @@ -1,20 +0,0 @@ -### Enhancements - -* - -### Bug fixes - -* Fixed a bug where some ``CondaBuildUserError`` exceptions that were formally ``SystemExit`` exceptions - were not being caught properly. (#5538) - -### Deprecations - -* - -### Docs - -* - -### Other - -* diff --git a/news/5555-skip-bad-specs-while-still-parsing.rst b/news/5555-skip-bad-specs-while-still-parsing.rst deleted file mode 100644 index 1454fb9bad..0000000000 --- a/news/5555-skip-bad-specs-while-still-parsing.rst +++ /dev/null @@ -1,19 +0,0 @@ -### Enhancements - -* - -### Bug fixes - -* Fixed a bug where bad match specs from intermediate parsing results would cause parsing to fail. (#5555) - -### Deprecations - -* - -### Docs - -* - -### Other - -* diff --git a/tests/test_api_build.py b/tests/test_api_build.py index 3e70dd64fe..d6a519cc5a 100644 --- a/tests/test_api_build.py +++ b/tests/test_api_build.py @@ -2082,7 +2082,7 @@ def test_conda_build_script_errors_without_conda_info_handlers(tmp_path, recipe, def test_api_build_inject_jinja2_vars_on_first_pass(testing_config): recipe_dir = os.path.join(metadata_dir, "_inject_jinja2_vars_on_first_pass") - with pytest.raises((RuntimeError, CondaBuildUserError)): + with pytest.raises(RuntimeError): api.build(recipe_dir, config=testing_config) testing_config.variant = {"python_min": "3.12"} diff --git a/tests/test_api_render.py b/tests/test_api_render.py index eb75a283d9..0882de0df1 100644 --- a/tests/test_api_render.py +++ b/tests/test_api_render.py @@ -7,7 +7,6 @@ import os import re -import textwrap from itertools import count, islice import pytest @@ -16,7 +15,6 @@ from conda.common.compat import on_win from conda_build import api, render -from conda_build.exceptions import CondaBuildUserError from conda_build.variants import validate_spec from .utils import metadata_dir, variants_dir @@ -343,46 +341,3 @@ def create_variants(): recipe, config=testing_config, channels=[], variants=create_variants() ) assert len(metadata_tuples) == 11 - 3 # omits libarrow-all, pyarrow, pyarrow-tests - - -def test_api_render_missing_jinja2(testing_config, testing_workdir): - with open(os.path.join(testing_workdir, "meta.yaml"), "w") as f: - f.write( - textwrap.dedent( - """ - package: - name: blah-{{ foo }} - version: 0.1 - - build: - number: 0 - - requirements: - host: - - python {{ python_min }} - run: - - python - """ - ) - ) - - meta = api.render( - testing_workdir, - finalize=False, - bypass_env_check=True, - trim_skip=False, - ) - assert meta is not None - assert any("python" in val for val in meta[0][0].get_value("requirements/host")) - assert not any( - "{{ python_min }}" in val for val in meta[0][0].get_value("requirements/run") - ) - assert meta[0][0].get_value("package/name") == "blah-" - - with pytest.raises(CondaBuildUserError): - api.render( - testing_workdir, - finalize=True, - bypass_env_check=True, - trim_skip=False, - ) diff --git a/tests/test_metadata.py b/tests/test_metadata.py index 3985bdc1df..d5feecf53c 100644 --- a/tests/test_metadata.py +++ b/tests/test_metadata.py @@ -655,56 +655,3 @@ def test_parse_until_resolved_skip_avoids_undefined_jinja( pytest.fail( "Undefined variable caused error, even though this build is skipped" ) - - -@pytest.mark.parametrize("have_variant", [True, False]) -def test_parse_until_resolved_missing_jinja_in_spec( - testing_metadata: MetaData, - tmp_path: Path, - have_variant: bool, -) -> None: - (recipe := tmp_path / (name := "meta.yaml")).write_text( - """ -package: - name: dummy - version: 1.0.0 - -build: - noarch: python - number: 0 - -requirements: - host: - - python ={{ python_min }} - run: - - python >={{ python_min }} -""" - ) - (tmp_path / "conda_build_config.yaml").write_text( - """ -python_min: - - 3.6 -""" - ) - testing_metadata._meta_path = recipe - testing_metadata._meta_name = name - if have_variant: - testing_metadata.config.variant = {"python_min": "3.6"} - else: - delattr(testing_metadata.config, "variant") - delattr(testing_metadata.config, "variant_config_files") - delattr(testing_metadata.config, "variants") - - try: - testing_metadata.parse_until_resolved() - if not have_variant: - pytest.fail("Undefined variable did NOT cause spec parsing error!") - else: - print("parsed OK!") - except (Exception, SystemExit): - if have_variant: - pytest.fail( - "Undefined variable caused spec parsing error even if we have the variant!" - ) - else: - print("did not parse OK!")