pypa / hatch

Modern, extensible Python project management
https://hatch.pypa.io/latest/
MIT License
6.11k stars 310 forks source link

Hatch requires depricated ImpImporter in 3.12 #1625

Closed icfly2 closed 4 months ago

icfly2 commented 4 months ago

I have some projects with pyproject.toml where I run the tests with:

[tool.hatch.envs.test.scripts]
base = "pytest {args}"
integration = "pytest --integration {args}" 

if I include 3.12 in the test matrix the tests fail to launch as I get the error:

──────────────────────────────────────── test.py3.12 ─────────────────────────────────────────
ERROR: Exception:
Traceback (most recent call last):
  File "/home/icfly/.local/share/hatch/env/virtual/aa-utils-base/LOz-b2sA/test.py3.12/lib/python3.12/site-packages/pip/_internal/cli/base_command.py", line 160, in exc_logging_wrapper
    status = run_func(*args)
             ^^^^^^^^^^^^^^^
  File "/home/icfly/.local/share/hatch/env/virtual/aa-utils-base/LOz-b2sA/test.py3.12/lib/python3.12/site-packages/pip/_internal/cli/req_command.py", line 247, in wrapper
    return func(self, options, args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/icfly/.local/share/hatch/env/virtual/aa-utils-base/LOz-b2sA/test.py3.12/lib/python3.12/site-packages/pip/_internal/commands/install.py", line 326, in run
    session = self.get_default_session(options)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/icfly/.local/share/hatch/env/virtual/aa-utils-base/LOz-b2sA/test.py3.12/lib/python3.12/site-packages/pip/_internal/cli/req_command.py", line 98, in get_default_session
    self._session = self.enter_context(self._build_session(options))
                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/icfly/.local/share/hatch/env/virtual/aa-utils-base/LOz-b2sA/test.py3.12/lib/python3.12/site-packages/pip/_internal/cli/req_command.py", line 125, in _build_session
    session = PipSession(
              ^^^^^^^^^^^
  File "/home/icfly/.local/share/hatch/env/virtual/aa-utils-base/LOz-b2sA/test.py3.12/lib/python3.12/site-packages/pip/_internal/network/session.py", line 343, in __init__
    self.headers["User-Agent"] = user_agent()
                                 ^^^^^^^^^^^^
  File "/home/icfly/.local/share/hatch/env/virtual/aa-utils-base/LOz-b2sA/test.py3.12/lib/python3.12/site-packages/pip/_internal/network/session.py", line 175, in user_agent
    setuptools_dist = get_default_environment().get_distribution("setuptools")
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/icfly/.local/share/hatch/env/virtual/aa-utils-base/LOz-b2sA/test.py3.12/lib/python3.12/site-packages/pip/_internal/metadata/importlib/_envs.py", line 188, in get_distribution
    return next(matches, None)
           ^^^^^^^^^^^^^^^^^^^
  File "/home/rum/.local/share/hatch/env/virtual/aa-utils-base/LOz-b2sA/test.py3.12/lib/python3.12/site-packages/pip/_internal/metadata/importlib/_envs.py", line 183, in <genexpr>
    matches = (
              ^
  File "/home/icfly/.local/share/hatch/env/virtual/aa-utils-base/LOz-b2sA/test.py3.12/lib/python3.12/site-packages/pip/_internal/metadata/base.py", line 612, in iter_all_distributions
    for dist in self._iter_distributions():
  File "/home/icfly/.local/share/hatch/env/virtual/aa-utils-base/LOz-b2sA/test.py3.12/lib/python3.12/site-packages/pip/_internal/metadata/importlib/_envs.py", line 176, in _iter_distributions
    for dist in finder.find_eggs(location):
  File "/home/icfly/.local/share/hatch/env/virtual/aa-utils-base/LOz-b2sA/test.py3.12/lib/python3.12/site-packages/pip/_internal/metadata/importlib/_envs.py", line 144, in find_eggs
    yield from self._find_eggs_in_dir(location)
  File "/home/icfly/.local/share/hatch/env/virtual/aa-utils-base/LOz-b2sA/test.py3.12/lib/python3.12/site-packages/pip/_internal/metadata/importlib/_envs.py", line 111, in _find_eggs_in_dir
    from pip._vendor.pkg_resources import find_distributions
  File "/home/icfly/.local/share/hatch/env/virtual/aa-utils-base/LOz-b2sA/test.py3.12/lib/python3.12/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2164, in <module>
    register_finder(pkgutil.ImpImporter, find_on_path)
                    ^^^^^^^^^^^^^^^^^^^
AttributeError: module 'pkgutil' has no attribute 'ImpImporter'. Did you mean: 'zipimporter'?

while if i run:

python3.12 -m venv env
source env/bin/activate.fish
pip install .
pip install pytest
pytest

the tests complete successfully.

❯ hatch --version
Hatch, version 1.12.0

I've tried this on a range of machines with different projects, including a clean fresh new one.

All on WSL2 with ubuntu.

icfly2 commented 4 months ago

Removing hatch envs, reinstalling hatch and deleting all pycache and all references to previous binaries fixes this.

So just clean up the system very thoroughly and this goes away.