classification
Title: shebanged scripts can escape from `venv` depending on how it was created
Type: Stage: resolved
Components: Library (Lib) Versions: Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Anthony Sottile, vinay.sajip
Priority: normal Keywords: patch

Created on 2020-02-16 19:21 by Anthony Sottile, last changed 2020-03-19 11:20 by vinay.sajip. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 19030 merged Anthony Sottile, 2020-03-16 18:40
Messages (2)
msg362095 - (view) Author: Anthony Sottile (Anthony Sottile) * Date: 2020-02-16 19:21
This is distilled from a larger example to be small/silly, however this caused real problems

A script which was intended for python3.6 exactly was written as follows:

```
#!/usr/bin/env python3.6
...
```

when creating a virtualenv with `python3.6 -m venv venv36` you end up with `python` / `python3` / `python3.6` executables in the venv

however, when creating a virtualenv with `python3 -m venv venv36` you only end up with `python` / `python3` executables

___

using `-mvirtualenv` (pypa/virtualenv) instead of venv, all three are reliably created

___

the fix is fairly straightforward, adding `f'python3.{sys.version_info[0]}'` to this tuple: https://github.com/python/cpython/blob/c33bdbb20cf55b3a2aa7a91bd3d91fcb59796fad/Lib/venv/__init__.py#L246
msg364389 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2020-03-17 07:29
New changeset 58ec58a42bece5b2804b178c7a6a7e67328465db by Anthony Sottile in branch 'master':
bpo-39656: Ensure `bin/python3.#` is always present in virtual environments on POSIX (GH-19030)
https://github.com/python/cpython/commit/58ec58a42bece5b2804b178c7a6a7e67328465db
History
Date User Action Args
2020-04-27 07:37:57ned.deilylinkissue32444 superseder
2020-03-19 11:20:59vinay.sajipsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2020-03-17 07:29:17vinay.sajipsetnosy: + vinay.sajip
messages: + msg364389
2020-03-16 18:40:05Anthony Sottilesetkeywords: + patch
stage: patch review
pull_requests: + pull_request18379
2020-02-16 19:21:51Anthony Sottilecreate