`subprocess.run` docs should recommend copying `os.environ` on Windows
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
As described in https://stackoverflow.com/questions/78652758/, when passing custom environment variables to subprocess.run or subprocess.Popen on Windows, you will usually need to include the existing keys from os.environ in order to reliably run arbitrary processes (exactly which keys are required to be present depends on what the subprocess is doing).
The subprocess.Popen docs include a "Note" about this problem, but the subprocess.run docs omit it. Even the subprocess.Popen note is a bit vague, and only specifically mentions SystemRoot:
Note: If specified, env must provide any variables required for the program to execute. On Windows, in order to run a side-by-side assembly the specified env must include a valid SystemRoot.
The common documentation for the env parameter reads:
If env is not None, it must be a mapping that defines the environment variables for the new process; these are used instead of the default behavior of inheriting the current process’ environment. It is passed directly to Popen. This mapping can be str to str on any platform or bytes to bytes on POSIX platforms much like os.environ or os.environb.
Rather than re-using the existing subprocess.Popen note, my suggestion would be to add the following sentence to the above paragraph:
On Windows, many applications require specific environment variables (such as
SystemRoot) to be set as expected in order to work correctly. Accordingly, it is recommended to start fromos.environ.copy()when customing the subprocess environment on Windows, rather than starting from an empty dictionary (otherwise the executed subprocesses may fail with various Windows OS errors).
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
subprocess.run と subprocess.Popen の共有 env パラメータのドキュメントから始め、次に Popen ドキュメントにある既存の Windows に関する注記と比較します。Windows のサブプロセス環境をカスタマイズする際は os.environ.copy() から始めるよう案内を追加し、更新後の文言で SystemRoot などの必須変数が明確に扱われていることを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- documentation
- issue の種類
- ドキュメント
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 45/100