pypa / hatch

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

ModuleNotFoundError: No module named 'hatchling.dep' with hatchling 1.26.0 #1793

Closed jdicioccio closed 2 weeks ago

jdicioccio commented 2 weeks ago

With the just-released 1.26.0, I'm getting the following error when using 'hatch run'

╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /usr/local/lib/python3.13/site-packages/hatch/cli/__init__.py:221 in main                        │
│                                                                                                  │
│   218                                                                                            │
│   219 def main():  # no cov                                                                      │
│   220 │   try:                                                                                   │
│ ❱ 221 │   │   hatch(prog_name='hatch', windows_expand_args=False)                                │
│   222 │   except Exception:  # noqa: BLE001                                                      │
│   223 │   │   import sys                                                                         │
│   224                                                                                            │
│                                                                                                  │
│ /usr/local/lib/python3.13/site-packages/click/core.py:1157 in __call__                           │
│                                                                                                  │
│ /usr/local/lib/python3.13/site-packages/click/core.py:1078 in main                               │
│                                                                                                  │
│ /usr/local/lib/python3.13/site-packages/click/core.py:1688 in invoke                             │
│                                                                                                  │
│ /usr/local/lib/python3.13/site-packages/click/core.py:1434 in invoke                             │
│                                                                                                  │
│ /usr/local/lib/python3.13/site-packages/click/core.py:783 in invoke                              │
│                                                                                                  │
│ /usr/local/lib/python3.13/site-packages/click/decorators.py:33 in new_func                       │
│                                                                                                  │
│ /usr/local/lib/python3.13/site-packages/hatch/cli/run/__init__.py:147 in run                     │
│                                                                                                  │
│   144 │   elif not env_name:                                                                     │
│   145 │   │   env_name = 'system'                                                                │
│   146 │                                                                                          │
│ ❱ 147 │   ctx.invoke(                                                                            │
│   148 │   │   run_command,                                                                       │
│   149 │   │   args=[command, *final_args],                                                       │
│   150 │   │   env_names=[env_name],                                                              │
│                                                                                                  │
│ /usr/local/lib/python3.13/site-packages/click/core.py:783 in invoke                              │
│                                                                                                  │
│ /usr/local/lib/python3.13/site-packages/click/decorators.py:45 in new_func                       │
│                                                                                                  │
│ /usr/local/lib/python3.13/site-packages/hatch/cli/env/run.py:134 in run                          │
│                                                                                                  │
│   131 │   elif not matrix_selected and (included_variables or excluded_variables):               │
│   132 │   │   app.abort(f'Variable selection is unsupported for non-matrix environments: {", "   │
│   133 │                                                                                          │
│ ❱ 134 │   for context in app.runner_context(                                                     │
│   135 │   │   environments,                                                                      │
│   136 │   │   ignore_compat=ignore_compat or matrix_selected,                                    │
│   137 │   │   display_header=matrix_selected,                                                    │
│                                                                                                  │
│ /usr/local/lib/python3.13/site-packages/hatch/cli/application.py:224 in runner_context           │
│                                                                                                  │
│   221 │   │   │   │   context = ExecutionContext(environment)                                    │
│   222 │   │   │   │   yield context                                                              │
│   223 │   │   │   │                                                                              │
│ ❱ 224 │   │   │   │   self.prepare_environment(environment)                                      │
│   225 │   │   │   │   with EnvVars(context.env_vars):                                            │
│   226 │   │   │   │   │   self.run_shell_commands(context)                                       │
│   227                                                                                            │
│                                                                                                  │
│ /usr/local/lib/python3.13/site-packages/hatch/cli/application.py:143 in prepare_environment      │
│                                                                                                  │
│   140 │   │   │   │   │   │   )                                                                  │
│   141 │   │                                                                                      │
│   142 │   │   with environment.app_status_dependency_state_check():                              │
│ ❱ 143 │   │   │   new_dep_hash = environment.dependency_hash()                                   │
│   144 │   │                                                                                      │
│   145 │   │   current_dep_hash = self.env_metadata.dependency_hash(environment)                  │
│   146 │   │   if new_dep_hash != current_dep_hash:                                               │
│                                                                                                  │
│ /usr/local/lib/python3.13/site-packages/hatch/env/plugin/interface.py:667 in dependency_hash     │
│                                                                                                  │
│    664 │   │   """                                                                               │
│    665 │   │   from hatch.utils.dep import hash_dependencies                                     │
│    666 │   │                                                                                     │
│ ❱  667 │   │   return hash_dependencies(self.dependencies_complex)                               │
│    668 │                                                                                         │
│    669 │   @contextmanager                                                                       │
│    670 │   def app_status_creation(self):                                                        │
│                                                                                                  │
│ /usr/local/lib/python3.13/site-packages/hatch/env/plugin/interface.py:316 in                     │
│ dependencies_complex                                                                             │
│                                                                                                  │
│    313 │   │   │   if (not self.skip_install and self.dev_mode) or self.features:                │
│    314 │   │   │   │   from hatch.utils.dep import get_project_dependencies_complex              │
│    315 │   │   │   │                                                                             │
│ ❱  316 │   │   │   │   dependencies_complex, optional_dependencies_complex = get_project_depend  │
│    317 │   │   │   │                                                                             │
│    318 │   │   │   │   if not self.skip_install and self.dev_mode:                               │
│    319 │   │   │   │   │   all_dependencies_complex.extend(dependencies_complex.values())        │
│                                                                                                  │
│ /usr/local/lib/python3.13/site-packages/hatch/utils/dep.py:40 in                                 │
│ get_project_dependencies_complex                                                                 │
│                                                                                                  │
│   37 def get_project_dependencies_complex(                                                       │
│   38 │   environment: EnvironmentInterface,                                                      │
│   39 ) -> tuple[dict[str, Requirement], dict[str, dict[str, Requirement]]]:                      │
│ ❱ 40 │   from hatchling.dep.core import dependencies_in_sync                                     │
│   41 │                                                                                           │
│   42 │   dependencies_complex = {}                                                               │
│   43 │   optional_dependencies_complex = {}                                                      │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
ModuleNotFoundError: No module named 'hatchling.dep'
afourney commented 2 weeks ago

Yes. Me too for hatch test , hatch run types:check, and hatch build as well.

juntyr commented 2 weeks ago

+1

dycw commented 2 weeks ago

+1

inimaz commented 2 weeks ago

Same here! If it helps, as a workaround I fixed the version to the previous hatchling pip install hatch==1.13.0 hatchling==1.25.0 and everything back to normal.

potiuk commented 2 weeks ago

Same with airflow. Pinning to hatchling 1.25.0 fixes the issue

juntyr commented 2 weeks ago

Unfortunately in my case I don't control the dependency on hatchlings so I can't pin it directly. Is there something akin to a global constraints file for pip?

Ideally, 1.26.0 would be yanked or a patch for hatch released asap.

DimitriPapadopoulos commented 2 weeks ago

The hatch-v1.13.0 tag still contains the following code:

https://github.com/pypa/hatch/blob/4e3c515bb15fd5533ced963c70308e2a271905d9/src/hatch/utils/dep.py#L37-L40

DimitriPapadopoulos commented 2 weeks ago

https://github.com/pypa/hatch/pull/1582 / adba0033f7a85185c6bca0923ac62e9c73e9796e removed the above code and predates 28bfe354ff23e387a40126b0ead18e3f0e9e3751. Yet, it didn't make it into hatch-v1.13.0. What happened?

DimitriPapadopoulos commented 2 weeks ago

The hatch-v1.13.x branch was forked from the master branch too early as far as I can see, and misses most recent changes that are necessary to hatchling 1.26.0, including #1582 / adba0033f7a85185c6bca0923ac62e9c73e9796e.

I think the hatch-v1.13.0 tag should have been applied to the master branch on 28bfe354ff23e387a40126b0ead18e3f0e9e3751, instead it has been applied to the spurious hatch-v1.13.x branch on 4e3c515bb15fd5533ced963c70308e2a271905d9.

The solution is indeed to:

ofek commented 2 weeks ago

Sorry about that everybody!

1582 / adba003 removed the above code and predates 28bfe35. Yet, it didn't make it into hatch-v1.13.0. What happened?

I have a branch for that minor release because there was a bunch of stuff on master that was not yet ready to be released and it was important to ship support for Python 3.13.

potiuk commented 2 weeks ago

Thanks for a quick fix @ofek . How about yanking 1.26.0 ? I think it's generally broken, so might be good to yank it

ofek commented 2 weeks ago

It's broken in relation to Hatch only, no?

potiuk commented 2 weeks ago

Yes. That's what we saw - it broke whe we installed hatch, but our packages seemeed to be build correctly. So yes - there is no "strong" need to yank it, but I guess it's no harm either.

ofek commented 2 weeks ago

True, yanked! https://pypi.org/project/hatchling/1.26.0/