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

Conversation

jameslamb
Copy link
Contributor

@jameslamb jameslamb commented Apr 30, 2024

Description

Fixes #5323

"Use Environment Variables" in the conda-build docs says the following about variables in build.script_env in recipes (my emphasis)

If a listed environment variable is missing from the environment seen by the conda-build process itself, a UserWarning is emitted during the build process and the variable remains undefined.

(link)

As of #5105, conda-build does not behave that way for multi-output recipes. As of that PR, any variable mentioned in the recipe's build.script_env but not found in the environment where conda-build is called from will be set to the empty string '' in the build script environment.

This PR proposes ensuring that such variables remain unset in the build script environment.

Thanks for your time and consideration.

Benefits of these changes

Removes a source of behavioral difference between top-level and multi-output builds.

Reduces a source of friction when using build scripts that are sensitive to the difference between environment variables being unset and being set to an empty string. (for example, with optional AWS credentials for sccache like this).

Checklist - did you ...

  • Add a file to the news directory (using the template) for the next release's release notes?
  • Add / update necessary tests?
  • Add / update outdated documentation?

How I tested this

The unit test I've added here fails on main.

git checkout main -- conda_build/build.py
pytest tests/test_subpackages.py::test_build_script_does_not_set_env_from_script_env_if_missing
# Failed: DID NOT RAISE <class 'subprocess.CalledProcessError'>

And prints this message from the build script in stdout of the build process, showing that the unset environment variable is set to ''.

val... 

But passes on this branch.

@jameslamb jameslamb requested a review from a team as a code owner April 30, 2024 15:26
@conda-bot conda-bot added the cla-signed [bot] added once the contributor has signed the CLA label Apr 30, 2024
Copy link

codspeed-hq bot commented Apr 30, 2024

CodSpeed Performance Report

Merging #5322 will not alter performance

Comparing jameslamb:fix/undefined-env-vars (380c796) with main (6dbdec8)

Summary

✅ 3 untouched benchmarks

@jameslamb
Copy link
Contributor Author

I've added an issue write-up (#5323), so this can be documented even if this specific PR isn't accepted.

Thanks for your time and consideration.

@jaimergp
Copy link
Contributor

Thanks for the write-up. I think this looks good to go, but I wasn't involved in the mentioned PR. Tagging @msarahan and @kenodegard to see what they think.

mbargull
mbargull previously approved these changes May 23, 2024
Copy link
Member

@mbargull mbargull left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@jameslamb
Copy link
Contributor Author

As of #5264, a codepath that was raising subprocess.CalledProcessError started raising conda_build.exceptions.BuildScriptException, breaking the unit test I'd added here.

I've merged latest main into this PR and updated the test. See f7ac317

@jameslamb
Copy link
Contributor Author

I've updated this to latest main.

Is there anything else you'd like to see on this PR? More tests, docs, etc.?

@jakirkham
Copy link
Member

Most of the CI jobs are seeing a known failure, which happens outside this PR and is being debugged: #5426

The macOS Python 3.12 canary jobs see 2 failures. They appear unrelated to this PR (which has been passing in the past). Have raised them as issues:

Given there is support for this change and these issues appear unrelated, will go ahead and merge to fix this bug

@jakirkham jakirkham enabled auto-merge (squash) July 26, 2024 22:51
@jakirkham jakirkham merged commit 1fd2dcb into conda:main Jul 29, 2024
28 checks passed
@jameslamb jameslamb deleted the fix/undefined-env-vars branch August 12, 2024 23:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed [bot] added once the contributor has signed the CLA
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Undefined environment variables are redefined in build script environment for multi-output builds
7 participants