devcontainers / devcontainers/images

Python standard library Modulefinder not working with editable installed packages

Open
#1,077 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Shell
Stars
2.1k
Forks
963
Avg merge
7h 48m
Merged PRs (30d)
11

Description

Hello,

This is related to the Python images: https://github.com/devcontainers/images/tree/main/src/python

When having a Python package installed as editable (pip install -e ...) the standard library Modulefinder cannot find the package.

See also: https://github.com/thebjorn/pydeps/issues/222

I'll try to recap/provide a how-to-reproduce:

1) install a (custom) package as editable: `pip install -e mypackage`
2) have it imported by a simple test file: `echo "import mypackage" > test.py`
3) verify that the package can indeed be imported by python: `python test.py` (should not throw import errors)
4) have modulefinder (not) find the package:
```
$ python -m modulefinder test.py

Name File
---- ----
m __main__ test.py

Missing modules:
? mypackage imported from __main__
```

This does not occur when using the Debian provided Python version.

In the latest version that I've tested (3.12-bookworm) this also does not occur when installing the package normally.

In a previous version however (3.11-bullseye) installing it normally threw a stacktrace, ending in:
```
massive stacktrace before this
File "/usr/local/lib/python3.11/modulefinder.py", line 308, in import_module
fp, pathname, stuff = self.find_module(partname,
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/modulefinder.py", line 489, in find_module
return _find_module(name, path)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/modulefinder.py", line 69, in _find_module
if spec.loader.is_package(name):
^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'is_package'
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.