Skip to content

hatch build stopped working with hooks in 1.16.0 #2139

@subnix

Description

@subnix

We use the hatch-protobuf plugin to generate protobuf stubs with the following configuration:

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.hatch.build.hooks.protobuf]
dependencies = [
    "hatch-protobuf~=0.4.0",
    "grpcio-tools",
    "mypy-protobuf",
    "protobuf",
]

However, starting from version 1.16.0, the hatch build command generates an error:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/venv/test/eTJI2Zoc/hatch-build/lib/python3.11/site-packages/hatchling/__main__.py", line 6, in <module>
    sys.exit(hatchling())
             ^^^^^^^^^^^
  File "/venv/test/eTJI2Zoc/hatch-build/lib/python3.11/site-packages/hatchling/cli/__init__.py", line 26, in hatchling
    command(**kwargs)
  File "/venv/test/eTJI2Zoc/hatch-build/lib/python3.11/site-packages/hatchling/cli/build/__init__.py", line 82, in build_impl
    for artifact in builder.build(
  File "/venv/test/eTJI2Zoc/hatch-build/lib/python3.11/site-packages/hatchling/builders/plugin/interface.py", line 118, in build
    configured_build_hooks = self.get_build_hooks(directory)
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/test/eTJI2Zoc/hatch-build/lib/python3.11/site-packages/hatchling/builders/plugin/interface.py", line 388, in get_build_hooks
    raise UnknownPluginError(message)
hatchling.plugin.exceptions.UnknownPluginError: Unknown build hook: protobuf

Other hatch commands, such as run, fmt, and test, as well as direct installation via pip, work correctly. It's likely that hatch doesn't install hook-level dependencies into a build environment.

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