Skip to content

[venv] Add a CLI flag to venv to use the pwd basename as the prompt #83082

Closed

Description

@brettcannon
BPO 38901
Nosy @brettcannon, @vsajip, @JulienPalard, @DahlitzFlorian, @tirkarthi
PRs
  • bpo-38901: Allow setting a venv's prompt to the basename of the current directory. #17946
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2020-01-14.23:57:53.719>
    created_at = <Date 2019-11-23.22:28:34.409>
    labels = ['type-feature', 'library']
    title = '[venv] Add a CLI flag to venv to use the pwd basename as the prompt'
    updated_at = <Date 2020-01-14.23:57:53.718>
    user = 'https://github.com/brettcannon'

    bugs.python.org fields:

    activity = <Date 2020-01-14.23:57:53.718>
    actor = 'vinay.sajip'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-01-14.23:57:53.719>
    closer = 'vinay.sajip'
    components = ['Library (Lib)']
    creation = <Date 2019-11-23.22:28:34.409>
    creator = 'brett.cannon'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 38901
    keywords = ['patch']
    message_count = 9.0
    messages = ['357385', '357418', '357420', '357452', '357493', '358039', '359462', '359993', '360003']
    nosy_count = 5.0
    nosy_names = ['brett.cannon', 'vinay.sajip', 'mdk', 'DahlitzFlorian', 'xtreak']
    pr_nums = ['17946']
    priority = 'low'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue38901'
    versions = []

    Activity

    1. brettcannon commented on Nov 23, 2019

      @brettcannon
      MemberAuthor

      I did a Twitter poll to see if there was consistent naming of the directory people created a virtual environment into when done locally to code (the answer is no). But a common theme was people not liking that the prompt defaults to the name of the directory that the virtual environment is in and seem to prefer for it to be os.path.basename(os.getcwd()).

      Maybe it makes sense to add a --basename-prompt flag to set the prompt to the current working directory's basename?

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      type-featureA feature request or enhancement
      on Nov 23, 2019
    3. vsajip commented on Nov 24, 2019

      @vsajip
      Member

      Maybe it makes sense to add a --basename-prompt flag to set the prompt to the current working directory's basename?

      What does this buy you beyond using

      --prompt $(basename $PWD)

      ? Perhaps I'm not understanding what you're getting at - how about an example of what you mean?

    4. JulienPalard commented on Nov 24, 2019

      @JulienPalard
      Member

      I like the idea and I think I will use it!

      As it's a bit long to type, I'm searching if other shorter variants could be usefull like:

      python3 -m venv --here
      python3 -m venv --cwd
      python3 -m venv --project
      

      being the equivalent of python3 -m venv --basename-prompt venv, but I'm not satisfied with the names (and it enforces using "venv" as a directory name)...

    5. brettcannon commented on Nov 25, 2019

      @brettcannon
      MemberAuthor

      @vinay you got exactly what I mean. I had to actually teach a ton of people that shell trick with basename and pwd on Twitter, that trick doesn't seem to be something people know about, and yet a ton of people seem to be creating virtual environments with prompts manually specified like that.

      Plus that trick varies from shell to shell and we already have enough issues just explaining to people how to activate between Windows and UNIX and then between even shells on the same OS.

      So this is entirely for convenience.

      @julien default directory names is an entirely separate topic as people can't agree on the default name (e.g. I prefer .venv as my default).

    6. vsajip commented on Nov 26, 2019

      @vsajip
      Member

      Since there is already a --prompt available, I'd prefer a solution that allowed some special value(s) to be passed for this, e.g.

      --prompt .

      or perhaps

      --prompt __curdir__

    7. brettcannon commented on Dec 8, 2019

      @brettcannon
      MemberAuthor

      If it were . would we then always check if the prompt was a folder and then use the folder's name in that case? Or would it only apply to .?

      As for __curdir__, it could work, but I don't know how easy would that be to remember or explain to new users compared to .?

      My vote is to support . and make the rule that if you specify a folder it will use the basename automatically.

    8. changed the title [-]Add a CLI flag to venv to use the pwd basename as the prompt[/-] [+][venv] Add a CLI flag to venv to use the pwd basename as the prompt[/+] on Jan 6, 2020
    9. brettcannon commented on Jan 6, 2020

      @brettcannon
      MemberAuthor

      Any more feedback from anyone on the idea of using the basename of a directory if specified for --prompt?

    10. vsajip commented on Jan 14, 2020

      @vsajip
      Member

      New changeset 7d63780 by Vinay Sajip in branch 'master':
      bpo-38901: Allow setting a venv's prompt to the basename of the current directory. (GH-17946)
      7d63780

    11. brettcannon commented on Jan 14, 2020

      @brettcannon
      MemberAuthor

      Can this now be closed, Vinay?

    12. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      stdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions