flathub / flathub/com.visualstudio.code

Symlinks in python virtual environments will not work on systems that do not follow PEP 394

Aperta
#82 0 commenti 3 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Shell
Stelle
217
Fork
82
Merge medio
1g 7h
PR unite (30g)
1

Descrizione

This is a combination of several quirks on the whole OS chain and I'm not entirely sure who should be considered responsible, so please tell me if it belongs elsewhere.

* Flatpak, as recommanded by [PEP 394][1], uses `python2` as the default `python` interpreter. That convention was put into place after Arch Linux (the distribution I'm currently using) decided to make `python3` the default interpreter instead.
* Python venv creates symlinks to the system binaries [for Python 3 specifically][2]. It [creates symlinks to `env_exe`, which normally points towards `/usr/bin/python3`][3], and appears to collapse those absolute symlinks into relative ones if multiple symlinks point towards the same binary. Thus:

```
$ ls -l /usr/bin/python*
lrwxrwxrwx 1 root root 7 26 mar 17:43 /usr/bin/python -> python3
lrwxrwxrwx 1 root root 9 26 mar 17:43 /usr/bin/python3 -> python3.7
-rwxr-xr-x 2 root root 14120 26 mar 17:43 /usr/bin/python3.7

$ mkdir test-python
$ cd test-python/
$ python -m venv .pyenv
$ ls -l .pyenv/bin/python*
lrwxrwxrwx 1 user user 15 1 jun 22:05 .pyenv/bin/python -> /usr/bin/python
lrwxrwxrwx 1 user user 6 1 jun 22:05 .pyenv/bin/python3 -> python
```

This would normally be harmless, except it creates a situation where both symlinks would, if executed inside the flatpak sandbox, point towards a python 2.7 executable. Creating the virtual environment through the internal VSCode terminal, which would be running from inside the Flatpak sandbox, creates the symlinks correctly.

```
sh-4.4$ python --version
Python 2.7.16
sh-4.4$ python3 -m venv .pyenv
sh-4.4$ ls -l .pyenv/bin/python*
lrwxrwxrwx 1 user user 7 Jun 1 22:36 .pyenv/bin/python -> python3
lrwxrwxrwx 1 user user 16 Jun 1 22:36 .pyenv/bin/python3 -> /usr/bin/python3
```

With all of that said, I have no idea who is supposed to be at fault here. I'm starting by submitting this here since I do not believe that this bug can surface anywhere else. Everyone is technically doing their part correctly, but the combination of non-issues ends up creating a non-trivial problem.

[1]:https://www.python.org/dev/peps/pep-0394/
[2]:https://www.python.org/dev/peps/pep-0405/
[3]: https://github.com/python/cpython/blob/3.7/Lib/venv/__init__.py#L202-L224

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

Read the linked CPython Lib/venv/__init__.py lines 202-224, then reproduce the two venv creation cases shown in the issue inside and outside the Flatpak terminal. Establish which component owns the mismatch and define the expected symlink targets before deciding what a fix would mean.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
devtools, operating-systems
Tipo di issue
Bug
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.