flathub / flathub/com.visualstudio.code

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

Abierto
#82 0 comentarios 3 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Shell
Estrellas
217
Forks
82
Merge medio
1 d 7 h
PR fusionados (30 d)
1

Descripción

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

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.