pypa / pypa/hatch

`hatch build` stopped working with hooks in 1.16.0

Open
#2,139 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
7.2k
Forks
462
Avg merge
19h 36m
Merged PRs (30d)
10

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure with the shown build-system configuration and hatch build. Start in hatchling/builders/plugin/interface.py, especially get_build_hooks, and follow the build path from hatchling/cli/build/__init__.py. Done means the protobuf hook is discovered in the build environment and the sample project builds successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
build-system, cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.