-
Notifications
You must be signed in to change notification settings - Fork 929
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The packaging-projects tutorial does not work with hatch #1316
Comments
@LLyaudet Where is the version of your example that reproduces the issue? In other words where is the version of your example project that uses hatchling as build back-end? The link in your post points to a project with setuptools as build back-end. |
@sinoroc Version 1.0.0 was build with hatchling, versions 1.0.1 and 1.1.0 were build with setuptools. Look at the commits history ; there is only 8 commits right now. |
git clone and git checkout to this previous commit and you can reproduce the issue :) |
or if you only want to check the result of install : |
The tutorial works perfectly if you follow it as-is (as recommended). The following line may be misleading:
The example structure uses proper underscores rather than hyphens for the package directory name which conflicts with that statement. Changing your package directory to underscores fixes your issue. |
Thanks for your answer @ofek :). I switched back to hatch and indeed the bug must be only when the name of the directory/module contains hyphens. """ import abcd-1234
from abcd-1234 import something would not work.
import abcd_1234
from abcd_1234 import something
|
Would you be open if I submit a PR to add this warning in the tutorial? |
If your package directory has hyphens, it's also not importable by Python. And I thoroughly tested the tutorial on all four backends, and reported timings for each. ;) |
Hello @henryiii |
If there is any to add, the warning should be that Python import package names must be valid Python identifiers (or whatever the exact rule is) with a link to the rule. I do not think we need to say that it can not contain hyphens. Because then we also need to say it can not contain a dot @LLyaudet If you start a pull request in that sense, I would support it. |
Yes exactly @sinoroc, that's how I phrased it in my issue on pypa hatch, regarding valid Python identifier :
The link is just above @henryiii 's comment. The emphasis on hyphens is just because it is very common. |
I could find the following:
I will try to find some time this week-end to look further for the definition of NAME apart from "Upper case names (NAME) denote tokens in the Grammar/Tokens file" |
@LLyaudet FYI you can use |
The reason this is not happening is that a distribution package that is published to a PyPI project may contain multiple importables with different name. Not just one folder. There may be several importable packages (directories with Python files) and even top-level modules (Python files that end up directly in Obviously, the rules for the PyPI project name, dist name and the installable content are different. The content is what's going to be imported/loaded in runtime, once the dist is installed. And the dist name (tarball or wheel base name) is what matches the PyPI project, as in what people use in |
Hello :) |
Hello,
I hope this is the right place :) after python/cpython#111009
This tutorial
https://packaging.python.org/en/latest/tutorials/packaging-projects/
says:
"this tutorial uses Hatchling by default, but it will work identically with setuptools, Flit, PDM, and others that support the [project] table for metadata."
But it seems it was converted from a tutorial with setuptools.
Hatchling does not seem to work well when the source of the package is in a src/ folder.
My repository here
https://github.com/LLyaudet/django-monkey-patches
demonstrates the problem.
I had to switch from hatch to setuptools to have a wheel that is correct.
Otherwise code was installed in lib/python3.11/site-packages/src/django-monkey-patches instead of lib/python3.11/site-packages/django_monkey_patches.
Best regards,
Laurent Lyaudet
The text was updated successfully, but these errors were encountered: