python / python/cpython

Customizable venv prompt prefix and suffix

Aperta
#144,203 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

stdlib topic-venv type-feature
Lingua principale
Python
Stelle
77.2k
Fork
35.9k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

Feature or enhancement

Proposal:

In venv activate PS1 is updated with the fixed format.

Some user like me doesn't like such format for some reason.

For my case, I'd like to keep empty line between the previous output and the current prompt like

[/tmp]                                                                                                                                                                                                                                                                                                                                                                                                                                  
<username>@<hostname>% python --version
Python 3.14.2

[/tmp]                                                                                                                                                                                                                                                                                                                                                                                                                                  
<username>@<hostname>% 

If I enable venv, it breaks my preference like

(.python.venv.default.3.14.2) 
[/tmp]                                                                                                                                                                                                                                                                                                                                                                                                                                  
<username>@<hostname>% python --version
Python 3.14.2
(.python.venv.default.3.14.2) 
[/tmp]                                                                                                                                                                                                                                                                                                                                                                                                                                  
<username>@<hostname>% 

I want to keep empty like between previous output and commands like

(.python.venv.default.3.14.2) 
[/tmp]                                                                                                                                                                                                                                                                                                                                                                                                                                  
<username>@<hostname>% python --version
Python 3.14.2

(.python.venv.default.3.14.2) 
[/tmp]                                                                                                                                                                                                                                                                                                                                                                                                                                  
<username>@<hostname>% 

This can be easily achieved keeping the compatibility by taking prefix and suffix for venv name in activate to set PS1 instaed of current "(" and ") ".

It makes someone to use explain venv name as their preferred way like

(Python env: /home/<...>/.venv)
[/tmp]                                                                                                                                                                                                                                                                                                                                                                                                                                  
<username>@<hostname>% python --version
Python 3.14.2

(Python env: /home/<...>/.venv) 
[/tmp]                                                                                                                                                                                                                                                                                                                                                                                                                                  
<username>@<hostname>% 

with

# Auto activate .venv in the new dir
function chpwd() {
    if [[ -d "`pwd`/.venv" ]]; then
        VIRTUAL_ENV_PROMPT_PREFIX="
(Python env: `pwd`/" source `pwd`/.venv/bin/activate
    fi
}
Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs
  • gh-144205

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia dallo script di attivazione di venv citato nella proposta e verifica come imposta attualmente PS1. Confronta il comportamento richiesto per un prefisso e un suffisso configurabili con il lavoro collegato in gh-144205; il lavoro è completo quando viene mantenuto il valore predefinito esistente, consentendo al contempo il formato del prompt mostrato negli esempi.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
tooling
Tipo di issue
Funzionalità
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.