flathub / flathub/com.visualstudio.code

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

Ouverte
#82 0 commentaires 3 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
Shell
Étoiles
217
Forks
82
Merge moyen
1 j 7 h
PR mergées (30 j)
1

Description

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

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
python
Domaine
devtools, operating-systems
Type d'issue
Bug
Difficulté
5/5
Temps estimé
Plus d'une semaine
Activité
À l'abandon
Clarté
À clarifier
Accessibilité débutants
25/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.