4
New to Python packaging? Avoid hatch
(danpassaro.dev)
Welcome to the Python community on the programming.dev Lemmy instance!
Past
November 2023
October 2023
July 2023
August 2023
September 2023
ah that probably explains why I didn't have this problem, same reason why I don't like global gitignores
It takes about 30 seconds of reading the documentation to find this.
Actually working out the right configuration for your project is likely going to take you more than 30 seconds. And finding the documentation for how to do this is only quick if you know exactly where to look and what to look for. When you invoke
pyproject-buildit's not clear that hatch is the piece of the puzzle that's causing unexpected files to wind up in your sdist.And this is still more config and overhead than simply choosing a build backend with more sensible default behavior like uv_build.
Please, you've wasted a lot of time writing the article without bothering to read documentation (it's mentioned in both python guide and on the hatchling page), which takes one click and like three paragraphs down, and uv_build requires to use uv and not everyone likes it or wants to use it. Anyway reading documentation is far more important for beginners than automagical tools that supposedly solve all the problems in the world.
? I linked directly to the documentation I read, and that's how I wound up using hatch in the first place. Did you read my article...? Reading the official Python documentation is what led to me uploading my
.jjfolder and a gitignored.envfile to PyPI and writing this post. And writing the post was not a waste of time.That's fine. I'm sure there are other build backends that work similarly to uv_build and only grab what's needed to distribute your library. The point isn't that everyone needs to use uv_build, the point is that hatch has surprising and imo dangerous default behavior.
You see, I've actually read your article, you even linked to the hatchling site yourself. It takes little effort. Demonstration
This doesn't explain that hatch will package everything in the project directory by default. As a new user making a package, why would you think to look for hatch configuration options?
I mentioned in the article (maybe you don't read that carefully?) that hatch can be configured to do what you need, but if you're just following the packaging guide, which doesn't mention this behavior or provide any kind of heads up to new users, you won't be aware that it is going to even try to look at a directory like
.jj. And why would it? I wouldn't expect a compiler or a tool like Maven to look at files that aren't needed to build the project. Why does hatch?Your demonstration just shows if you're already aware of the problem and you know the cause of the problem, you can find a solution. I say as much in the article and agree with the point. The point of my article is this is surprising default behavior and it's better to just use a tool that has sensible defaults.
I wouldn't try to follow hunches on how tool that has extensive and accessible documentation works, your novice is a strawman that has expectations but unable to do anything for some reason. So he should completely change the workflow.
Nothing personal, I liked your article in general, but pretending that default is all there is isn't great way to frame it, you could have linked relevant documentation and provided a snippet on how it should be done instead of dismissing it entirely, because default doesn't meet your expectations
Even if you're using git or hg for version control you'll probably wind up with more in your sdist than you need: things like
uv.lock,Justfile, or the contents of yourtests/dir might not be harmful, but they bloat your sdist and don't really belong there, and hatch will package them up with your source code unless you explicitly configure it not to.you just need
only-includehttps://hatch.pypa.io/1.13/config/build/#explicit-selection
it's easier than changing build backends
and a lot of times
tests/(anddocs/) are included with source code in an sdist format - https://discuss.python.org/t/should-sdists-include-docs-and-tests/14578Interesting discussion, thanks for the link! I side with pf_moore there; when I think of distributing a library I think of shipping only the library code itself and none of the supporting files, although I can understand the argument to include things like
tests/anddocs/.That said, if you haven't already tailored your project for hatch, configuring
only-includeis more work than switching to a build backend that just bundles source modules by default. With the right config hatch can do what you like, and I can understand existing users sticking with it, but for newbies I think it's really risky to suggest a build backend that grabs everything it finds in the working directory and packages it up for PyPI. It's just surprising and dangerous default behavior imo.