`subprocess.run` docs should recommend copying `os.environ` on Windows
Personne n'a encore pris cette issue.
- Langage dominant
- Python
- Étoiles
- 77.2k
- Forks
- 35.9k
- Métriques de merge des PR
- Métriques de PR en attente
Description
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).
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par la documentation commune du paramètre env pour subprocess.run et subprocess.Popen, puis comparez la note Windows existante dans la documentation de Popen. Ajoutez des indications recommandant de partir de os.environ.copy() lors de la personnalisation de l’environnement d’un sous-processus Windows, et vérifiez que la formulation mise à jour couvre clairement les variables requises telles que SystemRoot.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- python
- Domaine
- documentation
- Type d'issue
- Documentation
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 45/100