poetry shell fails to set Python path if prompt uses VT100 escape sequences to read terminal information
まだ誰も着手していません。
評価
調査の方向性
poetry shell のエントリーポイントから開始し、pexpect がどのようにシェルを起動して仮想環境のアクティベーションコマンドを送信するかを追跡します。Issue に示されている VT100 対応プロンプトで失敗を再現し、その後、アクティベーションコマンドの一部を消費せずにシェルが正しくアクティベートされることを確認します。
索引モデルが issue の本文から書いたものです。
説明
- Poetry version: 1.4.2
- Python version: 3.11.2
- OS version and name: Ubuntu 23.04
- I am on the latest stable Poetry version, installed using a recommended method.
- I have searched the issues of this repo and believe that this is not a duplicate.
- I have consulted the FAQ and blog for any relevant entries or release notes.
- If an exception occurs when executing a command, I executed it again in debug mode (
-vvvoption) and have included the output below.
Issue
Related: https://github.com/python-poetry/poetry-plugin-shell/issues/18 https://github.com/python-poetry/poetry/issues/571
This is a result of me diagnosing why poetry shell starts a new shell, but without the virtual env activated.
Looking at how poetry uses the shell, it uses pexpect to run it, writing the command to activate the python environment as its first input. This breaks in all configurations that read anything before that; particularly, any configuration that uses VT100 escape sequences that read anything. These may be more or less common in, for example, prompts.
For example, I have this in my .bashrc, essentially from this StackOverflow comment:
new_line_ps1() {
local _ y x _
local LIGHT_YELLOW="\001\033[1;93m\002"
local RESET="\001\e[0m\002"
IFS='[;' read -p $'\e[6n' -d R -rs _ y x _
if [[ "$x" != 1 ]]; then
printf "\n${LIGHT_YELLOW}^^ no newline at end of output ^^\n${RESET}"
fi
}
if [ "$color_prompt" = yes ]; then
PS1='$(new_line_ps1)${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
PS1='$(new_line_ps1)${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt
My analysis of what happens:
What this prompt does is it outputs the "\e[6n" VT100 escape code to read cursor position. VT100 compliant terminals respond to this by producing the a string like "\e[10;1R" as if input from a keyboard. This can then be read by the program to determine that the cursor is on line 10, column 1.
The way poetry shell is implemented, it typically claims to be VT100 compliant if run from such a terminal (because it does not change the TERM environment variable), yet it does not respond to VT100 queries the shell outputs before giving it the activation command. In this case, that results in the read command in the prompt reading (part of) the activation command.
- 主要言語
- Python
- スター
- 141
- フォーク
- 10
- 平均マージ
- 59分
- マージ済み PR(30日)
- 3
環境構築
このプロジェクトの環境構築ファイルはまだ確認していません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
python-poetry/poetry-plugin-shell のほかの issue
-
難易度 4/5 3〜5日 初心者へのやさしさ 20/100
python-poetry/poetry-plugin-shell#43 · コメント 1 件 · リアクション 1 件 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 52/100
python-poetry/poetry-plugin-shell#42 · コメント 4 件 · リアクション 15 件 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 38/100
python-poetry/poetry-plugin-shell#40 · コメント 4 件 · リアクション 2 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 42/100
python-poetry/poetry-plugin-shell#37 · コメント 3 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 25/100
python-poetry/poetry-plugin-shell#34 · コメント 1 件 ·
python-poetry/poetry-plugin-shell の issue をすべて見る
似ている issue
-
customer-reported
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
Azure/azure-cli#34150 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
community-request
難易度 1/5 1時間未満 初心者へのやさしさ 95/100
NVIDIA-NeMo/Curator#2464 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
WeblateOrg/translation-finder#1099 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
trezor/trezor-firmware#7997 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
メンテナーはふだん 1 日以内に返信