-
Notifications
You must be signed in to change notification settings - Fork 427
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
Fix: Build environments not activated #4665
Conversation
Its members are very dynamic so it is problematic to use it for cached calculations.
Needed to set .activate=True on the MetaData's own .config
I updated the OP with explanations for what happened and how this is mitigated. cc @jezdez, @kenodegard |
- Prefix "bin" directory get added on all platforms - Prefix root directory should only be added on Windows
36133a6
to
998597c
Compare
# TODO: Prepending the prefixes here should probably be guarded by | ||
# if not m.activate_build_script: | ||
# Leaving it as is, for now, since we need a quick, non-disruptive patch release. | ||
with utils.path_prepended(m.config.host_prefix, False): | ||
with utils.path_prepended(m.config.build_prefix, False): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before removing this in a future release, we should add more test cases.
The test added in this PR only checks for the case when there is build
+host
, activate=True
and no outputs
.
Other configurations that should be tested:
activate=False
build
andhost
merged- with
activate=True
- with
activate=False
- with
- recipes with
outputs
- and those for potential combinations of the aforementioned other cases.
I consider this out of scope for this PR since we should put out a patch release quickly and because those other cases touch other issues like #3993 -- that's another can of worms (one we should take care of, but not hastily in a small patch release).
@@ -950,11 +950,10 @@ def get_build_folders(croot): | |||
|
|||
|
|||
def prepend_bin_path(env, prefix, prepend_prefix=False): | |||
# bin_dirname takes care of bin on *nix, Scripts on win | |||
env['PATH'] = join(prefix, bin_dirname) + os.pathsep + env['PATH'] | |||
env['PATH'] = join(prefix, "bin") + os.pathsep + env['PATH'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
conda activate
always adds "bin"
to PATH
. We have to have it here too. The addition of "Scripts"
is taken care of a few lines below.
def path_prepended(prefix, prepend_prefix=True): | ||
# FIXME: Unclear why prepend_prefix=True for all platforms. | ||
old_path = os.environ['PATH'] | ||
os.environ['PATH'] = prepend_bin_path(os.environ.copy(), prefix, True)['PATH'] | ||
os.environ['PATH'] = prepend_bin_path(os.environ.copy(), prefix, prepend_prefix)['PATH'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No idea why this is prepend_prefix=True
for all platforms.
For now, I left it that way and only changed it to False
in build.write_build_scripts
where I needed it.
I did not look at the other places where path_prepended
is used. For me, this is also out of scope for this PR, but I'd like us to fix it, hence the added FIXME
-note.
# And apparently here the previously added build env gets deactivated | ||
# from the activation hook, hence only host is on PATH twice. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe CONDA_SHLVL
is not reset for Windows builds? IDK. I didn't check since debugging for Windows is rather time-consuming on my end.
This can be investigated later; not something we have to do in this PR.
This PR also adds PREFIX/bin to PATH on Windows and removes PREFIX root from PATH on Unix. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @mbargull
Thanks for this pull request. So far everything looks okay with this pull request, and I will be happy to approve, but I would really appreciate it if you could add a descriptive doc string to your test explaining exactly why it exists and perhaps its shortcomings as you mentioned.
We are trying hard to make sure the tests in conda-build are more maintainable and these simple descriptions are very helpful for future maintainers.
Thank you! ✌️
@travishathaway, thanks for the review! Addressed in 1ebe72c .
Glad to hear that process started! 😸 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@travishathaway I don't mind doc strings in test cases... more important for me: test cases follow a given/when/then or setup/run-subject-under-test/compare-outcome structure (which is given here), which often makes the code self explanatory beyond to what can described in english via doctsrings. |
Failure in
|
It sounds like we would like to capture this in a patch release of conda-build (like 3.23.3). Is that something that could be started? |
Yes |
Description
In conda-forge/conda-feedstock#181 (comment) we encountered unexpected failures for PyPy variants of the builds with
It turned out, this happened because the build environments were not activated at all.
The correct Python interpreter was launched because the build script used
$PYTHON
.The CPython variants built fine "by chance" only since our CPython builds carry library lookup patches to also function without an activated environment and other programs needed for the build were already on
PATH
from outside the build environment.This happened due to a regression caused by cecb031 .
Previously,
conda
'smemoized
bailed out from caching anything because of the additionally passed non-hashabledict
.Memoizing with a
MetaData
instance as a key is problematic since that object/its members are highly mutable duringconda-build
's work.The actual fix in commit 7f047c7 just removes the memoization.
I also added two guards to avoid regressions:
MetaData
non-hashable in 9fd7165.PATH
as expected.Note that the added test did not replicate the behavior from the conda-forge build entirely.
During the test runs, the prefixes were only added in a wrong order (possibly due to merged
build
/host
at the time of memoization) but they were not completely omitted like in theconda-feedstock
build.These subtleties can be expected due to different setups and different times of memoization.
It is also likely that the early memoization changed other parts of the builds; changes to
PATH
were just most visible.This PR also adds PREFIX/bin to PATH on Windows and removes PREFIX root from PATH on Unix.
Those were two bugs I noticed broke the added test case.
Fixing that should be non-controversial without any downsides, really (those are plain bugs anyway).
Checklist - did you ...
news
directory (using the template) for the next release's release notes?