Skip to content

Commit

Permalink
fix: ensure variants are used on first parsing pass
Browse files Browse the repository at this point in the history
  • Loading branch information
beckermr committed Nov 6, 2024
1 parent bd94b7f commit ae48e05
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
17 changes: 16 additions & 1 deletion conda_build/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
find_used_variables_in_shell_script,
find_used_variables_in_text,
get_default_variant,
get_package_variants,
get_vars,
list_of_dicts_to_dict_of_lists,
)
Expand Down Expand Up @@ -1167,7 +1168,21 @@ def __init__(self, path, config=None, variant=None):
# Therefore, undefined jinja variables are permitted here
# In the second pass, we'll be more strict. See build.build()
# Primarily for debugging. Ensure that metadata is not altered after "finalizing"
self.parse_again(permit_undefined_jinja=True, allow_no_other_outputs=True)

try:
# For the first pass, we do a simple read of any variants in the recipe and
# use them. These are then discarded. Other operations on the metadata
# will restore versions of them as needed. This is done to preserve
# old behavior.
old_config = self.config

self.config = get_or_merge_config(config, variant=variant)
self.config.variants = get_package_variants(self)
self.config.variant = self.config.variants[0]
self.parse_again(permit_undefined_jinja=True, allow_no_other_outputs=True)
finally:
self.config = old_config

self.config.disable_pip = self.disable_pip
# establish whether this recipe should squish build and host together

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package:
name: noarch-test
version: 0.1

source:
path: ../../test-package

build:
number: 0
noarch: python

requirements:
host:
- python {{ python_min }}.*
run:
- python >={{ python_min }}
9 changes: 9 additions & 0 deletions tests/test_api_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -2078,3 +2078,12 @@ def test_conda_build_script_errors_without_conda_info_handlers(tmp_path, recipe,
assert "Traceback" in all_output
assert "CalledProcessError" in all_output
assert "returned non-zero exit status 1" in all_output


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):
api.build(recipe_dir, config=testing_config)

testing_config.variant = {"python_min": "3.12"}
api.build(recipe_dir, config=testing_config)

0 comments on commit ae48e05

Please sign in to comment.