Skip to content

Commit

Permalink
fix: catch CondaBuildUserError w/ SystemExit (#5538)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
beckermr authored Nov 15, 2024
1 parent 41856b5 commit 0ad4bb6
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 4 deletions.
4 changes: 2 additions & 2 deletions conda_build/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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 = []
Expand Down
4 changes: 2 additions & 2 deletions conda_build/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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

Expand Down
20 changes: 20 additions & 0 deletions news/5538-sysexit-vs-cdusererror
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
### Enhancements

* <news item>

### Bug fixes

* Fixed a bug where some ``CondaBuildUserError`` exceptions that were formally ``SystemExit`` exceptions
were not being caught properly. (#5538)

### Deprecations

* <news item>

### Docs

* <news item>

### Other

* <news item>
45 changes: 45 additions & 0 deletions tests/test_api_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import os
import re
import textwrap
from itertools import count, islice

import pytest
Expand All @@ -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
Expand Down Expand Up @@ -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,
)

0 comments on commit 0ad4bb6

Please sign in to comment.