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

Implement VIRTUAL_ENV_DISABLE_PROMPT or something covering the same use case(s) #1229

Closed
Russell-Jones opened this issue Jun 14, 2016 · 7 comments

Comments

@Russell-Jones
Copy link

See https://virtualenv.pypa.io/en/stable/reference/#configuration

Handy if, e.g. installing and running xonsh in a VE using --system-site-packages. The prompt is displayed by xonsh, so I guess it'd need to be set in environ.py, but I'm not sure whether it would be best as a change to env_name() or to the prompt templates when env['VIRTUAL_ENV_DISABLE_PROMPT'] is set to anything but ''. The original reportedly prevents activate from modifying the shell prompt, but I can't see a direct equivalent to that (xonsh can't parse or do clever sub-shell things with bash/zsh/*sh prompt strings can it?).

@melund
Copy link
Member

melund commented Jun 14, 2016

The function that sets the environment part of the prompt is here:

def env_name(pre_chars='(', post_chars=') '):

I guess it could just check that environement variable exist:
if builtins.__xonsh_env__.get('VIRTUAL_ENV_DISABLE_PROMPT','') != '': and then not set the environment prompt.

@Russell-Jones
Copy link
Author

Russell-Jones commented Jun 14, 2016

Yes, but should it do it in the prompt template(s) or in env_name()? Is the output of env_name() exposed anywhere? Perhaps the difference in semantics is sufficient that there should be an xonsh specific env var with the closest functionality available.

Hm. Or perhaps display a message saying how to alter your prompt so it doesn't include the virtualenv name if your prompt template contains {env_name}? I need to look more closely at how prompts are specified.

Here's where it was added to virtualenv (not super enlightening that I could see) pypa/virtualenv#5

@melund
Copy link
Member

melund commented Jun 14, 2016

env_name() is the functions that provide the environment name that is inserted into the PROMPT template. I am not familiar with how Virtualenv works but think this should be enough.

@gforsyth
Copy link
Collaborator

Question: it seems like VIRTUAL_ENV_DISABLE_PROMPT comes into play at the time of env creation, is this the behavior we want to enable? Or do we want a general blanket "if this env var is set, don't change the prompt"?

@Russell-Jones Russell-Jones changed the title Implement VIRTUAL_ENV_DISABLE_PROMPT Implement VIRTUAL_ENV_DISABLE_PROMPT or something covering the same use case(s) Jun 15, 2016
@Russell-Jones
Copy link
Author

@gforsyth It's not at env creation, but at env activation.

@gforsyth
Copy link
Collaborator

I don't use virtualenv and can't test this right now, but the documentation you linked to in the initial post indicates otherwise:

VIRTUAL_ENV_DISABLE_PROMPT

Any virtualenv created when this is set to a non-empty value will not have it’s activate script modify the shell prompt.

But I would not be surprised if the docs were out-of-date / incomplete / wrong.

@Russell-Jones
Copy link
Author

I managed to get the effect I wanted with

import os
$FORMATTER_DICT['env_name']=lambda: '' if os.path.basename($VIRTUAL_ENV) == 'myve' else '('+os.path.basename($VIRTUAL_ENV)+')'

Though I could have used the even more succinct $FORMATTER_DICT['env_name']=''
I've put this in ~/.xonshrc and it works fine AFAIAC (I might add sys and a few others there too), so closing.

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

No branches or pull requests

3 participants