python / python/cpython

Customizable venv prompt prefix and suffix

オープン
#144,203 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

stdlib topic-venv type-feature
主要言語
Python
スター
77.2k
フォーク
35.9k
PR マージ指標
PR 指標を取得中

説明

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

提案で参照されている venv の activate スクリプトから始め、現在どのように PS1 を設定しているかを確認してください。設定可能なプレフィックスとサフィックスに対して要求されている動作を、gh-144205 の関連する作業と比較してください。既存のデフォルトを維持しつつ、例に示されているプロンプト形式を使用できるようにすれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
tooling
issue の種類
機能追加
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。