Skip to content

rehash: Do not execute conda-specific code if conda is not installed#3151

Merged
native-api merged 3 commits intopyenv:masterfrom
ChristianFredrikJohnsen:fix/conda-rehash
Feb 13, 2025
Merged

rehash: Do not execute conda-specific code if conda is not installed#3151
native-api merged 3 commits intopyenv:masterfrom
ChristianFredrikJohnsen:fix/conda-rehash

Conversation

@ChristianFredrikJohnsen
Copy link
Copy Markdown
Contributor

Make sure you have checked all steps below.

Prerequisite

Description

  • Here are some details about my PR

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 comments
which 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

pyenv rehash

And by extension, the execution time of:

eval "$(pyenv init -)"

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 doing pip install/uninstall, and thus it all goes automatically.)

Tests

  • My PR adds the following unit tests (if any)

No tests added

@ChristianFredrikJohnsen ChristianFredrikJohnsen changed the title Fix/conda rehash fix: do NOT execute conda specific code if conda not installed Dec 25, 2024
…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.
@native-api native-api merged commit 1c2a765 into pyenv:master Feb 13, 2025
@native-api native-api changed the title fix: do NOT execute conda specific code if conda not installed rehash: Do not execute conda-specific code if conda is not installed Feb 13, 2025
@native-api native-api mentioned this pull request Dec 20, 2025
5 tasks
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants