Skip to content
  • Kirill Smelkov's avatar
    pyx/build: Replace pkgutil.get_loader with importlib.util.find_spec on py3 · ffa1fb88
    Kirill Smelkov authored
    Starting from py3.14 pkgutil.get_loader was removed(*) and so pygolang
    can not even start building:
    
        (py314.venv) pygolang$ python setup.py build_ext -i
        Traceback (most recent call last):
          File "/home/kirr/src/tools/go/pygolang-master/setup.py", line 226, in <module>
            x_dsos      = [DSO('golang.runtime.libgolang',
                           ~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                                ['golang/runtime/libgolang.cpp',
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            ...<33 lines>...
                                define_macros   = [('BUILDING_LIBGOLANG', None)],
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                                soversion       = '0.1'),
                                ^^^^^^^^^^^^^^^^^^^^^^^^
          File "/home/kirr/src/tools/go/pygolang-master/golang/pyx/build.py", line 235, in DSO
            _, kw = _with_build_defaults(name, kw)
                    ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
          File "/home/kirr/src/tools/go/pygolang-master/golang/pyx/build.py", line 244, in _with_build_defaults
            gopkg = _findpkg("golang")
          File "/home/kirr/src/tools/go/pygolang-master/golang/pyx/build.py", line 134, in _findpkg
            pkg = pkgutil.get_loader(pkgname)
                  ^^^^^^^^^^^^^^^^^^
        AttributeError: module 'pkgutil' has no attribute 'get_loader'
    
    -> Fix it by replacing pkgutil.get_loader with importlib.util.find_spec .
    
    Need to adjust trun to inject golang.__spec__ in addition to
    golang.__loader__ because else find_spec cannot find the golang module.
    
    (*) https://docs.python.org/3/whatsnew/3.14.html#pkgutil
    
    /reviewed-by @jerome
    /reviewed-on !39
    ffa1fb88