FS#76193 - [python] IDLE fails to launch

Attached to Project: Arch Linux
Opened by Joel (jmcb) - Thursday, 13 October 2022, 17:39 GMT
Last edited by Toolybird (Toolybird) - Sunday, 25 December 2022, 21:16 GMT
Task Type Bug Report
Category Packages: Core
Status Closed
Assigned To Felix Yan (felixonmars)
Architecture All
Severity Low
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 2
Private No

Details

Description:
```
$ idle
Traceback (most recent call last):
File "/usr/bin/idle", line 3, in <module>
from idlelib.pyshell import main
File "/usr/lib/python3.10/idlelib/pyshell.py", line 53, in <module>
from idlelib import debugger
File "/usr/lib/python3.10/idlelib/debugger.py", line 7, in <module>
from idlelib import macosx
File "/usr/lib/python3.10/idlelib/macosx.py", line 7, in <module>
from test.support import requires, ResourceDenied
ModuleNotFoundError: No module named 'test'
```

This appears to be because of the way the pkgbuild removes the `test` module (https://github.com/archlinux/svntogit-packages/blob/packages/python/trunk/PKGBUILD#L108) and may cause other issues

Additional info:
* package version(s)
3.10.8-1

* config and/or log files etc.
* link to upstream bug report, if any

Steps to reproduce:
This task depends upon

Closed by  Toolybird (Toolybird)
Sunday, 25 December 2022, 21:16 GMT
Reason for closing:  Fixed
Additional comments about closing:  @yan12125 says "Issue gone with Python 3.10.9"
Comment by Joel (jmcb) - Thursday, 13 October 2022, 17:43 GMT Comment by Felix Yan (felixonmars) - Thursday, 13 October 2022, 22:24 GMT
Please try again with python 3.10.8-2 which moved only the `test.support` library back to the main python package.

I have searched through the installed package and only `test.support` was referenced (not only in idlelib). The split is still very effective as the split python-tests package is even larger than the python package.
Comment by Chih-Hsuan Yen (yan12125) - Sunday, 16 October 2022, 13:21 GMT
Apparently the issue persists with python 3.10.8-2:

$ idle
Traceback (most recent call last):
File "/usr/bin/idle", line 3, in <module>
from idlelib.pyshell import main
File "/usr/lib/python3.10/idlelib/pyshell.py", line 53, in <module>
from idlelib import debugger
File "/usr/lib/python3.10/idlelib/debugger.py", line 7, in <module>
from idlelib import macosx
File "/usr/lib/python3.10/idlelib/macosx.py", line 7, in <module>
from test.support import requires, ResourceDenied
ModuleNotFoundError: No module named 'test.support'

$ pacman -Q python
python 3.10.8-2

If I create an empty file /usr/lib/python3.10/test/__init__.py, IDLE can start.
Comment by Felix Yan (felixonmars) - Sunday, 16 October 2022, 14:08 GMT
I could not reproduce it here. IDLE starts just fine without __init__.py here.

$ ls -lah /usr/lib/python3.10/test/
total 20K
drwxr-xr-x 3 root root 4.0K Oct 14 01:20 ./
drwxr-xr-x 37 root root 12K Oct 14 01:20 ../
drwxr-xr-x 3 root root 4.0K Oct 14 01:20 support/

You may try to see if `python -c "from test.support import *"` works and probably strace it to find out what it tries to open.
Comment by Chih-Hsuan Yen (yan12125) - Sunday, 16 October 2022, 15:47 GMT
It turns out on my machine, `import test` uses /usr/lib/python3.10/site-packages/test/__init__.py (from https://aur.archlinux.org/packages/python-pysodium), so python -c `import test.support` fails.

Some side notes:
* community/python-augeas also has /usr/lib/python3.10/site-packages/test/__init__.py
* There is a feature request to check such files in namcap https://gitlab.archlinux.org/pacman/namcap/-/issues/22
Comment by kachelaqa (kachelaqa) - Monday, 21 November 2022, 21:15 GMT
@Felix Yan

The problem here is that creating the "test" directory without an "__init__.py" file implicitly creates a *namespace package* (see: https://docs.python.org/3/reference/import.html#namespace-packages) which can radically alter the normal python import process. Any users who coincidently have another directory/package called "test" somewhere on their import path may suddenly start seeing import-errors, depending on which directory/package python happens to find first. This is largely out of the user's control, since *any* package could legitimately install its own "test" modules into one of the "test" directories found on the import path. Whether a user is affected or not will depend on the mix of python packages they currently happen to have installed (including the ones they may have installed via pip under $HOME/.local/lib).

It's clear from the python source code that "test" is intended to be a regular package rather than a namespace package. So if the "test.support" subpackage is included by default, its parent "test" package should also include an empty "__init__.py" file, even if the other "test" modules/subpackages aren't also installed by default.
Comment by Chih-Hsuan Yen (yan12125) - Sunday, 18 December 2022, 04:59 GMT
Looks like IDLE no longer imports test.support unconditionally in Python 3.10.9: https://github.com/python/cpython/commit/928b5f1bdeb4f9ab243ccfdf0aa0ca52839974f9.

By the way, that commit also mentions 3.11.0 is never affected.

Loading...