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

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

Merged
merged 3 commits into from
Feb 13, 2025

Conversation

ChristianFredrikJohnsen
Copy link
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
17 checks passed
@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
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