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

direnv and venv segments #386

Open
v1gnesh opened this issue Jun 18, 2023 · 3 comments
Open

direnv and venv segments #386

v1gnesh opened this issue Jun 18, 2023 · 3 comments
Labels

Comments

@v1gnesh
Copy link
Contributor

v1gnesh commented Jun 18, 2023

Say I have this directory structure:

py-pandas/
py-pandas/.envrc
py-pandas/.direnv
py-pandas/.direnv/venv-de

venv-de is a directory created by running python -m venv venv-de from inside py-pandas.

I'm using direnv, and have both direnv and venv modules in the powerline-go prompt.
When I cd into py-pandas, I see the direnv segment, and it activates the venv ok (confirmed by running python -c "import sys;print(sys.prefix). It prints <blabla>/py-pandas/.direnv/venv-de.

Then, from py-pandas directory, when I do mv .direnv/venv-de .direnv/venv-do, the venv segment magically shows up.
Of course, by now the venv is "broken" and I'm not "in" it.

direnv and venv segments work ok in a faster machine (arch s390x)I have access to.
I should note that the above problem is on a zOS system (same architecture, different OS) that is quite slow (small).

So I wonder if there's a timing issue.

Both direnv and powerline-go updates the $PROMPT_COMMAND, and am using bash.
powerline-go sets it to PROMPT_COMMAND="_update_ps1; $PROMPT_COMMAND", but then direnv also updates this.
When I issue echo $PROMPT_COMMAND (while the venv segment shows the venv's name, but I've renamed the venv directory underneath it), this is what it says - _update_ps1; _direnv_hook.

Anything I can do to make this work?
It would be amazing if the direnv segment automatically shows info about the activated env (be it python or whatever else), by wrapping over powerline-go's venv, etc.
Seeing just the directory name again is not adding much value (direnv segment).

Shell: bash
OS: zOS

Thanks for this excellent, excellent tool. I'm really enjoying it ❤️

@v1gnesh v1gnesh added the bug label Jun 18, 2023
@v1gnesh
Copy link
Contributor Author

v1gnesh commented Jun 19, 2023

Anything I can do to make this work?

Update:
I went looking into segment-virtualenv, and found that it (first) looks for the 'prompt' keyword in pyenv.cfg.
So I deleted existing virtualenvs and venvs, then created one each of virtualenv and venv with --prompt seg-name, and it works alright now.

It would be amazing if the direnv segment automatically shows info about the activated env (be it python or whatever else), by wrapping over powerline-go's venv, etc.

Still think this would be neat.

Seeing just the directory name again is not adding much value (direnv segment).

Alternatively, instead of segment-direnv wrapping segment-virtualenv etc., I could directly just use the available *env modules/segments.
BUT, to avoid repetition in the prompt (direnv segment showing $PWD) in addition to the right side of the prompt already showing $PWD, I think a good solution is to have the segment-direnv not create a new segment, but just colourize the $PWD segment, indicating the activation of a direnv.

RIght now, $PWD comes with bold text. By doing the above, imagine if it were bold and coloured (to indicate direnv).
This will save space on the prompt.

What do you think? 😄

@elebertus
Copy link
Contributor

elebertus commented Jun 27, 2023

Not 100% sure of direnv, but I think the bug #387 being fixed here is at least adjacent to what your'e seeing. The issue with the --prompt flag and the prompt key in pyvenv.cfg is that the behavior of virtualenv changed with >= python 3.6, where the key was no longer written by default and the flat is supplemental.

I would be interested in seeing if you have the time or interest to test that fork and see if the same behavior exists or not.

Edit: *fork, not actually forking, but the fork the PR is being made from 🦖

@v1gnesh
Copy link
Contributor Author

v1gnesh commented Jun 28, 2023

@elebertus, will give it a go and report back.

EDIT: It works, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants