hatch-mypyc icon indicating copy to clipboard operation
hatch-mypyc copied to clipboard

README should clarify hatch.toml vs pyproject.toml (was "include / exclude don't actually work")

Open dhdaines opened this issue 4 months ago • 1 comments

To reproduce:

$ hatch init mypyc-example
$ cd mypyc-example
$ cat > mypyc-example/src/mypyc_example/bad.py
def foo(bar: str):                                                                                                                                                                                          
    return bar + 42               
$ cat >> pyproject.toml
[tool.hatch.build.hooks.mypyc]                                                                        
dependencies = ["hatch-mypyc"]
                                                                                                      
[build.targets.wheel.hooks.mypyc]
exclude = [
    "src/mypyc_example/bad.py",
]
$ hatch build
────────────────────────────────────────────────────────────────────────────────────────────────── sdist ───────────────────────────────────────────────────────────────────────────────────────────────────
dist/mypyc_example-0.0.1.tar.gz
────────────────────────────────────────────────────────────────────────────────────────────────── wheel ───────────────────────────────────────────────────────────────────────────────────────────────────
Traceback (most recent call last):
  File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/home/dhdaines/.local/share/hatch/env/virtual/mypyc-example/2DCSMF07/mypyc-example-build/lib/python3.10/site-packages/hatchling/__main__.py", line 6, in <module>
    sys.exit(hatchling())
  File "/home/dhdaines/.local/share/hatch/env/virtual/mypyc-example/2DCSMF07/mypyc-example-build/lib/python3.10/site-packages/hatchling/cli/__init__.py", line 26, in hatchling
    command(**kwargs)
  File "/home/dhdaines/.local/share/hatch/env/virtual/mypyc-example/2DCSMF07/mypyc-example-build/lib/python3.10/site-packages/hatchling/cli/build/__init__.py", line 82, in build_impl
    for artifact in builder.build(
  File "/home/dhdaines/.local/share/hatch/env/virtual/mypyc-example/2DCSMF07/mypyc-example-build/lib/python3.10/site-packages/hatchling/builders/plugin/interface.py", line 147, in build
    build_hook.initialize(version, build_data)
  File "/home/dhdaines/.local/share/hatch/env/virtual/mypyc-example/2DCSMF07/mypyc-example-build/lib/python3.10/site-packages/hatch_mypyc/plugin.py", line 338, in initialize
    raise Exception(f'Error while invoking Mypyc:\n{process.stdout.decode("utf-8")}')
Exception: Error while invoking Mypyc:
src/mypyc_example/bad.py:2: error: Unsupported operand types for + ("str" and "int")  [operator]

dhdaines avatar Aug 20 '25 14:08 dhdaines

Oh. This is a documentation bug, it should be tool.hatch.build.targets.wheel.hooks.mypyc (what a mouthful!!) when using pyproject.toml.

It would be good to make this clearer in the README for dunces like me.

dhdaines avatar Aug 20 '25 14:08 dhdaines