Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ensure undefined script_env variables are undefined in multi-output build environment #5322

Merged
merged 15 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions conda_build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1762,15 +1762,14 @@ def bundle_conda(
if "=" in var:
val = var.split("=", 1)[1]
var = var.split("=", 1)[0]
env_output[var] = val
elif var not in os.environ:
warnings.warn(
f"The environment variable '{var}' specified in script_env is undefined.",
UserWarning,
)
val = ""
else:
val = os.environ[var]
env_output[var] = val
env_output[var] = os.environ[var]
dest_file = os.path.join(metadata.config.work_dir, output["script"])
utils.copy_into(os.path.join(metadata.path, output["script"]), dest_file)
from os import stat
Expand Down
20 changes: 20 additions & 0 deletions news/5322-undefine-build-vars
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
### Enhancements

* <news item>

### Bug fixes

* Ensures that variables mentioned in `script_env` are undefined in multi-output build environment
if undefined in the environment `conda-build` is invoked from.

### Deprecations

* <news item>

### Docs

* <news item>

### Other

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

outputs:
- name: test_1
build:
script_env:
- TEST_FN_DOESNT_EXIST
script:
- python -c "import os; print('val...' + os.environ['TEST_FN_DOESNT_EXIST'])"
requirements:
host:
- python
14 changes: 13 additions & 1 deletion tests/test_subpackages.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from conda.base.context import context

from conda_build import api, utils
from conda_build.exceptions import CondaBuildUserError
from conda_build.exceptions import BuildScriptException, CondaBuildUserError
from conda_build.metadata import MetaDataTuple
from conda_build.render import finalize_metadata

Expand Down Expand Up @@ -354,6 +354,18 @@ def test_build_script_and_script_env_warn_empty_script_env(testing_config):
api.build(recipe, config=testing_config)


@pytest.mark.sanity
def test_build_script_does_not_set_env_from_script_env_if_missing(
testing_config, capfd, monkeypatch
):
monkeypatch.delenv("TEST_FN_DOESNT_EXIST", raising=False)
recipe = os.path.join(subpackage_dir, "_build_script_relying_on_missing_var")
with pytest.raises(BuildScriptException):
api.build(recipe, config=testing_config)
captured = capfd.readouterr()
assert "KeyError: 'TEST_FN_DOESNT_EXIST'" in captured.err


@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
Loading