Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

The imp module is used but is removed in Python 3.12 #21537

Open
dvzrv opened this issue Mar 1, 2024 · 0 comments 路 May be fixed by #22214
Open

The imp module is used but is removed in Python 3.12 #21537

dvzrv opened this issue Mar 1, 2024 · 0 comments 路 May be fixed by #22214
Labels

Comments

@dvzrv
Copy link

dvzrv commented Mar 1, 2024

Description of the bug:

Hi! 馃憢

We're currently going through a list of projects still using the imp module, which is removed with Python 3.12, as we are about to upgrade to Python 3.12 on Arch Linux.

cc @svenstaro @kgizdov (package maintainers for bazel on Arch Linux)

Upstream Python suggests to replace the problematic function in question with

import importlib.util
import importlib.machinery

def load_source(modname, filename):
    loader = importlib.machinery.SourceFileLoader(modname, filename)
    spec = importlib.util.spec_from_file_location(modname, filename, loader=loader)
    module = importlib.util.module_from_spec(spec)
    # The module is always executed and not cached in sys.modules.
    # Uncomment the following line to cache the module.
    # sys.modules[module.__name__] = module
    loader.exec_module(module)
    return module

Which category does this issue belong to?

External Dependency

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

Run this code with Python >= 3.12:

import imp
import unittest
pkg_bzl = imp.load_source(
'pkg_bzl',
'tools/build_defs/pkg/path.bzl')

Which operating system are you running Bazel on?

Arch Linux

What is the output of bazel info release?

7.0.2

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

We build bazel from source: https://gitlab.archlinux.org/archlinux/packaging/packages/bazel/-/blob/34d58f27f8164b5dab8c57669f007022c8b6479a/PKGBUILD

What's the output of git remote get-url origin; git rev-parse HEAD ?

n/a

Is this a regression? If yes, please try to identify the Bazel commit where the bug was introduced.

n/a

Have you found anything relevant by searching the web?

https://docs.python.org/dev/whatsnew/3.12.html#imp

Any other information, logs, or outputs that you want to share?

n/a

@github-actions github-actions bot added the team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. label Mar 1, 2024
@iancha1992 iancha1992 added team-Rules-Python Native rules for Python and removed team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. labels Mar 1, 2024
@cybaol cybaol linked a pull request May 2, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants