On Windows Powershell, venv folders are unexpectedly importable due to how namespace package and venv works
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 35/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- powershell, python
調査の方向性
まず、報告にある Windows PowerShell コマンドを再現し、venv を作成してアクティベートした後の sys.path を調べます。Windows と Linux の venv の動作を比較し、その後、Include、Lib、Scripts ディレクトリがどのようにインポート可能になるのかを特定します。通常の環境のインポートを壊すことなく、意図しない venv ディレクトリがインポートできなくなれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Bug report
PEP420 introduced implicit namespace package, basically by creating a folder without __init__.py, it is treated as namespace package.
For some reasons, in Windows Powershell, venv added the environment's root folder into sys.path (this behavior was not observed in Linux's venv), e.g.
PS C:\Users\TestUser> python -m venv testenv
PS C:\Users\TestUser> . .\testenv\Scripts\activate
(testenv) PS C:\Users\TestUser> python
Python 3.10.5 (tags/v3.10.5:f377153, Jun 6 2022, 16:14:13) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
[
[snip]
'C:\\Users\\TestUser\\testenv',
'C:\\Users\\TestUser\\testenv\\lib\\site-packages'
]
And because of the way namespace package works, you can import some folders that really aren't intended to be importable:
>>> import Include
>>> Include.__path__
_NamespacePath(['C:\\Users\\TestUser\\testenv\\Include'])
>>>
This was a namespace package created from the Include folder in the root of the testvenv folder:
PS C:\Users\TestUser> ls .\testenv\
Directory: C:\Users\TestUser\testenv
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 7/18/2022 1:15 PM Include
d----- 7/18/2022 1:15 PM Lib
d----- 7/18/2022 1:15 PM Scripts
-a---- 7/18/2022 1:15 PM 127 pyvenv.cfg
Similarly, you could have imported Lib and Scripts.
Your environment
Python 3.10.5 (tags/v3.10.5:f377153, Jun 6 2022, 16:14:13) [MSC v.1929 64 bit (AMD64)] on win32
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 36k
- 平均マージ
- 1日 9時間
- マージ済み PR(30日)
- 558
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
python/cpython のほかの issue
-
docs pending
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
stdlib type-feature
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
stdlib type-feature
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
build type-bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
-
stdlib topic-email type-feature
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
似ている issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
zostera/django-bootstrap4#894 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
use-agent-os/agent-os#3276 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
zephyrproject-rtos/zephyr#119726 ·
-
area/auth bug comp/agent P3 platform/discord type/security
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
NousResearch/hermes-agent#117848 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
zilliztech/memsearch#759 ·