hatch icon indicating copy to clipboard operation
hatch copied to clipboard

Hatch fails silently if package in src and [tool.hatch.build.targets.wheel] doesn't include src

Open jennirinker opened this issue 1 year ago • 3 comments

Hello,

I had some students run across this issue with hatch and thought I would report it.

MWE

This zip file contains a very simple package and pyproject.toml. Installing with an editable install reproduces the error.

testhatch.zip

What happens

If you do not include src/ in [packages] = ... under [tool.hatch.build.targets.wheel], after calling pip install -e . the output says

...
Building wheels for collected packages: simplepackage
  Building editable for simplepackage (pyproject.toml) ... done
  Created wheel for simplepackage: filename=simplepackage-0.0.1-py3-none-any.whl size=998 sha256=193f2efa296761c169ce7b1cba141e5edf89c9bf1d25697e3ac6533aac4cc424
  Stored in directory: C:\Users\rink\AppData\Local\Temp\pip-ephem-wheel-cache-xfc5teew\wheels\be\9d\ee\451fbd846fde98a0e155357426af1bdde9d5af8c907fb62d58
Successfully built simplepackage
Installing collected packages: simplepackage
Successfully installed simplepackage-0.0.1

which implies a successful installation of the package. However, if you try to import the package, you get a ModuleNotFound error.

What I would expect to happen

My preference would be that hatch adheres to the Python packaging standard, which is that it looks for the package either in the top-level directory or in a directory called src. I.e., I shouldn't have to include src in the packages path to hatch.

If that's infeasible/undesired, then it would be nice if there were at least a warning or error from hatch that the package was not actually installed correctly.

jennirinker avatar Mar 26 '25 20:03 jennirinker

@jennirinker If I omit the tool.hatch.build.targets.wheel table entirely, the package is included automatically. Why have you included this table?

If I include tool.hatch.build.targets.wheel and the include key under it, Hatch seems to behave like how only-include is documented: it only includes the paths I explicitly list, omitting the package under src/.

sanmai-NL avatar Apr 03 '25 07:04 sanmai-NL

include seems to require sources for it to strip off the leading src/ directory path component.

I didn't get this from the documentation, and I couldn't find a complete reference of the configuration keys, beyond the tutorial-style manual.

sanmai-NL avatar Apr 03 '25 07:04 sanmai-NL

As to "why" the tool.hatch.build.targets.wheel was added: to be honest, I also don't know why my students added it. The example pyproject.toml I gave them did not have the extra table. So I'm not sure what their thought process was.

But I thought I would report it anyway, in case it revealed a weird edge case you wanted to test.

jennirinker avatar Apr 03 '25 08:04 jennirinker