Skip to content

The use of importlib.util after importing just importlib breaks hatchling version and plugins #1221

@krassowski

Description

@krassowski

importlib.util is used in get_source_meta() method here:

spec = importlib.util.spec_from_file_location(os.path.splitext(path)[0], path) # type: ignore
module = importlib.util.module_from_spec(spec) # type: ignore

but instead of importing importlib.util just importlib is imported:

def get_version_data(self) -> dict:
import importlib

This often works if some other package has already imported importlib.utils, but there is no guarantee that it will work, and it does not work on a clean Python 3.11 installation. See this discussion: https://discuss.python.org/t/python3-11-importlib-no-longer-exposes-util/25641

JupyterLab Ci got hit by this recently in: jupyterlab/jupyterlab#15692

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions