rehash: Do not execute conda-specific code if conda is not installed#3151
Merged
native-api merged 3 commits intopyenv:masterfrom Feb 13, 2025
Merged
Conversation
…t installed. I was doing some debugging with PYENV_DEBUG=1 and noticed that a lot of work was being done in conda.bash, even though I had not installed any conda versions like `mambaforge`. The solution is pretty simple, put all the code inside an if-block. This aligns with what @varikin found in his pull request pyenv#3037 Additionally, I have refactored the code slightly for readability (created function `build_conda_exclusion_list`), and added comments which should make it easier to understand what's going on. This commit simplifies debugging and should reduce the execution time of ```bash eval "$(pyenv init -)" ``` slightly.
Applies to the conda blacklist in `pyenv.d/rehash/conda.d/default.list` No practical difference, but it looks misplaced when it sits at the end of the file.
1) Got rid of useless call to `cat`, much better to simply use sed with file as argument. 2) Got rid of `sort -u`. There is no need to sort the list. Additionally, the list `pyenv.d/rehash/conda.d/default.list` only has unique entries, and even if you have duplicate entries, the function will still work. --> No need for sort nor unique. 3) Further improvement is simple, save a cached cleaned-list-v1.0 in `conda.d` and simple read from that file instead of doing `sed`, which must be a more expensive operation than simply reading from file.
b555e32 to
8e5379e
Compare
jakelodwick
added a commit
to jakelodwick/pyenv
that referenced
this pull request
Mar 9, 2026
The source.bash rehash hook reads source.d/*.list files through a 5-element pipeline (cat | sort | uniq | sed | sed). Simplified to sort -u <files> | sed -e ... -e ...: - cat removed -- sort accepts filenames directly - sort | uniq replaced with sort -u - two sed invocations merged into one with combined expressions Same cleanup applied to conda.bash in pyenv#3151.
native-api
pushed a commit
that referenced
this pull request
Mar 10, 2026
Same cleanup applied to conda.bash in #3151.
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.
Make sure you have checked all steps below.
Prerequisite
Description
I was doing some debugging with PYENV_DEBUG=1 and noticed that a lot of
work was being done in conda.bash, even though I have not installed any
conda versions like
mambaforge.The solution is pretty simple, put all the code inside an if-block.
This aligns with what @varikin found in his pull request #3037
Additionally, I have refactored the code slightly for readability
(created function
build_conda_exclusion_list), and added commentswhich should make it easier to understand what's going on.
In a later commit, I also did some slight performance improvements to
pyenv.d/rehash/conda.bash.This PR simplifies debugging and should slightly reduce the execution time of
And by extension, the execution time of:
will be reduced slightly, especially if conda is not installed.
(NOTE: I am finding that it should be completely unnecessary to do a rehash upon init. I recommend using
pyenv init --no-rehash -and would advocate for having --no-rehash as default option. Reason being that we have automatic rehash when installing/uninstalling python versions, and when doingpipinstall/uninstall, and thus it all goes automatically.)Tests
No tests added