flathub / flathub/com.visualstudio.code

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

Đang mở
#82 0 bình luận 3 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Shell
Star
217
Fork
82
Merge trung bình
1 ngày 7 giờ
Pull request đã merge (30 ngày)
1

Mô tả

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

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.