This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: [venv] Add a CLI flag to venv to use the pwd basename as the prompt
Type: enhancement Stage: resolved
Components: Library (Lib) Versions:
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: DahlitzFlorian, brett.cannon, mdk, vinay.sajip, xtreak
Priority: low Keywords: patch

Created on 2019-11-23 22:28 by brett.cannon, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 17946 merged vinay.sajip, 2020-01-10 22:34
Messages (9)
msg357385 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2019-11-23 22:28
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?
msg357418 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2019-11-24 23:19
> 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?
msg357420 - (view) Author: Julien Palard (mdk) * (Python committer) Date: 2019-11-24 23:45
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)...
msg357452 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2019-11-25 18:38
@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).
msg357493 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2019-11-26 13:35
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__
msg358039 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2019-12-08 22:55
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.
msg359462 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2020-01-06 19:49
Any more feedback from anyone on the idea of using the basename of a directory if specified for `--prompt`?
msg359993 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2020-01-14 20:49
New changeset 7d6378051feeadf45b4ce45b4b406b65df255648 by Vinay Sajip in branch 'master':
bpo-38901: Allow setting a venv's prompt to the basename of the current directory. (GH-17946)
msg360003 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2020-01-14 21:54
Can this now be closed, Vinay?
Date User Action Args
2022-04-11 14:59:23adminsetgithub: 83082
2020-01-14 23:57:53vinay.sajipsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2020-01-14 21:54:37brett.cannonsetmessages: + msg360003
2020-01-14 20:49:38vinay.sajipsetmessages: + msg359993
2020-01-10 22:34:59vinay.sajipsetkeywords: + patch
stage: patch review
pull_requests: + pull_request17354
2020-01-06 19:49:23brett.cannonsetmessages: + msg359462
2020-01-06 19:47:29brett.cannonsettitle: 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
2019-12-08 22:55:26brett.cannonsetmessages: + msg358039
2019-11-26 13:35:39vinay.sajipsetmessages: + msg357493
2019-11-25 18:38:39brett.cannonsetmessages: + msg357452
2019-11-24 23:45:49mdksetnosy: + mdk
messages: + msg357420
2019-11-24 23:19:08vinay.sajipsetmessages: + msg357418
2019-11-24 15:03:16DahlitzFloriansetnosy: + DahlitzFlorian
2019-11-24 04:31:04xtreaksetnosy: + xtreak
2019-11-23 22:28:34brett.cannoncreate