Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.bugs.dist > #1266136

Bug#1118055: python3-pysmi: might trigger: AttributeError: module 'importlib' has no attribute 'machinery'

From Colin Watson <cjwatson@debian.org>
Newsgroups linux.debian.bugs.dist
Subject Bug#1118055: python3-pysmi: might trigger: AttributeError: module 'importlib' has no attribute 'machinery'
Date 2025-10-14 23:20 +0200
Message-ID <LFUB4-5e57-15@gated-at.bofh.it> (permalink)
References <LFMat-58ly-3@gated-at.bofh.it> <LFMat-58ly-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Tue, Oct 14, 2025 at 02:17:37PM +0200, Cyril Brulebois wrote:
>I've just spotted something a little weird while working on a customer
>package that ships a number of MIBs that are processed via pysmi at
>build time:
> - the package builds fine in a trixie devel schroot;
> - the package fails to build in a clean trixie cowbuilder chroot.
>
>At first I suspected some build-depends might be missing (it declares
>debhelper and python3-pysmi only), but the error is in importlib, which
>is shipped alongside Python:
>
>    Traceback (most recent call last):
>      File "/usr/lib/python3/dist-packages/pysmi/searcher/pyfile.py", line 15, in <module>
>        SOURCE_SUFFIXES = importlib.machinery.SOURCE_SUFFIXES
>                          ^^^^^^^^^^^^^^^^^^^
>    AttributeError: module 'importlib' has no attribute 'machinery'

Importing a module doesn't necessarily mean importing its submodules 
(unless importlib/__init__.py did something like `from . import 
machinery`, which it doesn't).  However, this might well be masked in 
many installations by things like /usr/lib/python3/dist-packages/*.pth 
files that import importlib.machinery and thus add it to sys.modules, 
and some of those do exist.  strace would confirm.

>There are four occurrences of the following, with slight variations:
>
>    try:
>        import importlib
>
>        try:
>            SOURCE_SUFFIXES = importlib.machinery.SOURCE_SUFFIXES
>            BYTECODE_SUFFIXES = importlib.machinery.BYTECODE_SUFFIXES
>
>        except Exception:
>            raise ImportError()
>
>(found in pysmi/searcher/pyfile.py, pysmi/searcher/pypackage.py,
>pysmi/writer/pyfile.py, and pysmi/borrower/pyfile.py)
>
>It seems something based on the following instead could work more
>reliably:
>
>    from importlib.machinery import SOURCE_SUFFIXES, BYTECODE_SUFFIXES

Or just replace `import importlib` with `import importlib.machinery` 
(and `import importlib.util` as needed, etc.).  Importing a submodule 
implicitly imports its parent module, just not vice versa.

-- 
Colin Watson (he/him)                              [cjwatson@debian.org]

Back to linux.debian.bugs.dist | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Bug#1118055: python3-pysmi: might trigger: AttributeError: module 'importlib' has no attribute 'machinery' Cyril Brulebois <cyril@debamax.com> - 2025-10-14 14:20 +0200
  Bug#1118055: python3-pysmi: might trigger: AttributeError: module 'importlib' has no attribute 'machinery' Cyril Brulebois <cyril@debamax.com> - 2025-10-14 16:30 +0200
  Bug#1118055: python3-pysmi: might trigger: AttributeError: module 'importlib' has no attribute 'machinery' Colin Watson <cjwatson@debian.org> - 2025-10-14 23:20 +0200

csiph-web