Skip to content

Commit

Permalink
reduce unset script_env variable to warning
Browse files Browse the repository at this point in the history
  • Loading branch information
msarahan committed Dec 11, 2023
1 parent 37ab8d3 commit c56381c
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 3 deletions.
7 changes: 5 additions & 2 deletions conda_build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1923,9 +1923,12 @@ def bundle_conda(output, metadata: MetaData, env, stats, **kw):
val = var.split("=", 1)[1]
var = var.split("=", 1)[0]
elif var not in os.environ:
raise ValueError(
f"env var '{var}' specified in script_env, but is not set."
warnings.warn(
"The environment variable '%s' specified in script_env is undefined."
% var,
UserWarning,
)
val = ""
else:
val = os.environ[var]
env_output[var] = val
Expand Down
4 changes: 3 additions & 1 deletion conda_build/environ.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,9 @@ def meta_vars(meta: MetaData, skip_build_id=False):
value = os.getenv(var_name)
if value is None:
warnings.warn(
"The environment variable '%s' is undefined." % var_name, UserWarning
"The environment variable '%s' specified in script_env is undefined."
% var_name,
UserWarning,
)
else:
d[var_name] = value
Expand Down
20 changes: 20 additions & 0 deletions news/5105-script-env-warn
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
### Enhancements

* Relax script_env error in outputs when variable referenced in script_env is not defined.
This unifies current behavior with the top-level build. (#5105)

### Bug fixes

* <news item>

### Deprecations

* <news item>

### Docs

* <news item>

### Other

* <news item>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package:
name: test_build_script_in_output
version: 1.0

outputs:
- name: test_1
build:
script_env:
- TEST_FN
10 changes: 10 additions & 0 deletions tests/test_subpackages.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,16 @@ def test_build_script_and_script_env(testing_config):
api.build(recipe, config=testing_config)


@pytest.mark.sanity
def test_build_script_and_script_env_warn_empty_script_env(testing_config):
recipe = os.path.join(subpackage_dir, "_build_script_missing_var")
with pytest.warns(
UserWarning,
match="The environment variable 'TEST_FN' specified in script_env is undefined",
):
api.build(recipe, config=testing_config)


@pytest.mark.sanity
@pytest.mark.skipif(sys.platform != "darwin", reason="only implemented for mac")
def test_strong_run_exports_from_build_applies_to_host(testing_config):
Expand Down

0 comments on commit c56381c

Please sign in to comment.