Fix PIPENV_ACTIVE not being unset on deactivate#6462
Merged
Conversation
Adds a new section explaining when to use --system (single-app containers) vs. virtual environments (containers with multiple Python apps or system tools). Updates the best practices summary to reflect this nuanced guidance. Closes #6438
When using 'pipenv shell' with pexpect-based compat mode, the deactivate function from the virtualenv's activate script doesn't know to unset the PIPENV_ACTIVE environment variable that pipenv sets. This causes subsequent 'pipenv shell' commands to fail with 'Shell for UNKNOWN_VIRTUAL_ENVIRONMENT already activated' error. This fix adds a wrapper around the deactivate function after sourcing the activate script. The wrapper calls the original deactivate function and then unsets PIPENV_ACTIVE. Support is added for bash, zsh, fish, csh, sh, xonsh, and PowerShell. Fixes #6220
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #6220
When using
pipenv shellwith pexpect-based compat mode, thedeactivatefunction from the virtualenv's activate script doesn't know to unset thePIPENV_ACTIVEenvironment variable that pipenv sets. This causes subsequentpipenv shellcommands to fail with:Solution
This fix adds a wrapper around the
deactivatefunction after sourcing the activate script. The wrapper:deactivatefunctiondeactivatefunction that calls the original and then unsetsPIPENV_ACTIVESupport is added for multiple shells:
declare -fto copy function definitionfunctions -cto copy andset -eto unsetaliasandunsetenvunset$function:andRemove-Item Env:Testing
Added unit test
test_deactivate_wrapper_script_includes_unset_pipenv_activeto verify the wrapper scripts include the appropriate unset command for each shell type.Notes
This fix applies to the
fork_compatmode (pexpect-based shell). Theforkmode (fancy mode) doesn't source the activate script at all, so there's nodeactivatefunction to wrap in that case.Pull Request opened by Augment Code with guidance from the PR author