Skip to content

COSMETIC: On Windows, --prompt adds a space to the resulting prompt after its argument; doesn't add space on Linux #1168

Closed

Description

@bskinn

When creating a new virtualenv with the --prompt option, on Windows a space is automatically added between the --prompt= value and the tail of the prompt:

C:\temp>virtualenv env --prompt="(myenv)"
...

C:\temp>env\scripts\activate

(myenv) C:\temp> 

On Debian stretch, a space is not added:

me@mycomp:~$ virtualenv env --prompt="(myenv)"
...

me@mycomp:~$ source env/bin/activate

(myenv)me@mycomp:~$ 

If auto-insertion of a space is desired behavior, it should be a simple fix: adding a space here in activate.sh, before the $PS1.

If this is desired, I can create a PR.


EDIT: Per discussion below, the decision has been made to remove the mandatory space after the custom prompt string, for all shells.

Activity

  1. gaborbernat commented on Jan 14, 2019

    @gaborbernat
    Contributor

    @bskinn sure, feel free to do so.

  2. added 4 commits that reference this issue on Jan 14, 2019
    3ca178d
    a488b40
    d4d1a22
    e2fdc3f
  3. asottile commented on Jan 15, 2019

    @asottile
    Contributor

    maybe I'm being contrary, but I actually think the windows behaviour is incorrect here. After adding a space it makes it impossible to produce a prompt without a space. However you can make a prompt with a space by doing --prompt='(foo) '

  4. bskinn commented on Jan 15, 2019

    @bskinn
    Author

    @asottile Very good point. At the time I composed this issue, I hadn't really tried to think of use-cases where a required space would be undesirable... but, for example, a forced space prevents crafting a prompt like:

    envname-C:\git\project> 
    

    For how I construct my prompts, I would like the space to be there by default. But, you're right, it's far more flexible not to mandate the trailing space. I'm now inclined to go the other way with it, and remove the default space on Windows (as long as cmd allows its removal... CONFIRMED, cmd does allow zero space).

    @gaborbernat?

  5. gaborbernat commented on Jan 15, 2019

    @gaborbernat
    Contributor

    I can see peoples complaining once we remove, but let's bite the bullet. Let's remove it.

  6. bskinn commented on Jan 15, 2019

    @bskinn
    Author

    Ok, I will revise the PR to REMOVE the mandated space from both Windows cmd and bash templates, and add tests for both to check for the lack of the trailing space.

    It looks like a mandated space should similarly be removed from the csh and PowerShell templates. (If new tests are desired for these shells, I'm not sure how to add them so that they integrate with the CI.)

    OTOH, fish looks ok to me; and, if I read the xonsh template correctly, it doesn't even mess with the prompt, and so doesn't need to be changed.

  7. bskinn commented on Jan 16, 2019

    @bskinn
    Author

    Just to raise the possibility...what if this change turns out to be a https://xkcd.com/1172/ ? If, say, someone is inspecting %PROMPT% &c to sniff which venv is active.

  8. asottile commented on Jan 16, 2019

    @asottile
    Contributor

    Seems unlikely when $VIRTUAL_ENV is a thing

  9. bskinn commented on Jan 17, 2019

    @bskinn
    Author

    Now that I look at it, I think both activate.csh and activate.ps1 actually ignore --prompt. The lines of code I linked to above appear actually just to always use the environment name as the default prefix.

    Is this desired behavior? Or should these be revised to obey --prompt?

  10. gaborbernat commented on Jan 17, 2019

    @gaborbernat
    Contributor

    I would say should be revised 👍

  11. locked and limited conversation to collaborators on Jan 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions