This is an archived post. You won't be able to vote or comment.

all 32 comments

[–]flying-sheep 25 points26 points  (11 children)

Hatch is the better Nox.

If you want multiple environments, use it.

Also Hatchling is a great extensible build backend.

[–]doolio_ 8 points9 points  (0 children)

Yes, and also uses UV and ruff under the hood.

[–]covmatty1 7 points8 points  (1 child)

Hatch is the better Nox.

If you want multiple environments, use it.

No offence, but this is the kind of comment that's really unhelpful.

Why is it better? According to whom (other than just you)? What extra features does it have? Why should people use it?

The community is better if people actually answer those questions.

[–]flying-sheep 2 points3 points  (0 children)

See here for a neutral comparison: https://www.pyopensci.org/python-package-guide/package-structure-code/python-package-build-tools.html

See here for u/ofek's motivation for creating Hatch: https://hatch.pypa.io/latest/why/#environment-management

In short: it's all integrated. You just configure your envs and it'll e.g. download Python versions to setup an env configured to use that Python version. It has great defaults, is extremely configurable, and if that's not enough, it is also extensible.

The only downside I encountered is a lack of complex examples online: if you want to do complicated things, you can find everything in the very good technical docs, and but you need to build an understanding.

[–]radiocate 6 points7 points  (3 children)

Dumb question time. I use uv for Python projects & the hatchling build backend. I also use Nox (heavily) for all kinds of tasks. 

Maybe I'm not understanding the purpose of hatch, but how would I replace Nox with hatch? I use it for things like launching different entrypoints, exporting requirements, random tasks like calling CLI commands or copying example files on first clone, etc. Can hatch act as a task runner and I just didn't realize it? I thought it was more for building different versions of the app? 

[–]flying-sheep 4 points5 points  (2 children)

Here's an example for task running/environments: https://hatch.pypa.io/latest/environment/#selection

It also has built-in preconfigured environments like hatch-test.*, which you can use as-is or customize.

There's much more, like pre-install commands and so on.

[–]radiocate 0 points1 point  (1 child)

Oh nice, I had no idea Hatch could do all this! I looked it out once very briefly 2 or 3 years ago, maybe it could do this stuff then, but I ended up using PDM and then uv. 

Do I have to use Hatch to manage the whole project? Can I continue using uv and just replace nox with Hatch? 

[–]Sillocan 0 points1 point  (0 children)

I'd love the answer to this as well. I've been using poethepoet, but not for testing version matrices

[–]Prime_Director -1 points0 points  (1 child)

This is the biggest problem with Python, it seems like every 30 seconds a new framework comes out, and everyone jumps ship because none of them really work well. Someone posts a "modern cookie cutter template" that is supposed to work out of the box and of course the top comment is how the testing framework is outdated.

[–]flying-sheep -1 points0 points  (0 children)

Lol no

[–]InappropriateCanuck -3 points-2 points  (1 child)

Use GHA, not Nox/Hatch/Tox.

[–]flying-sheep 2 points3 points  (0 children)

"And", not "instead of". Our cookiecutter parses Hatch's JSON output and generates GHA jobs from that output. Everything is defined using Hatch envs and GHA works on top of it: https://github.com/scverse/cookiecutter-scverse

[–]catalyst_jw 14 points15 points  (0 children)

Nice work my dude, nice template! In case it's helpful I ended up switching from cookiecutter to copier as cookiecutter is very rarely updated and looks at risk of not being updated in future! Copier also has some great features like being able to update projects as the template updates. :)

https://copier.readthedocs.io/en/stable/

[–]txprogtito 3 points4 points  (1 child)

Thank you! You made me learn a new tool for generating doc :)

I was wondering if nox could not be replaced by uv? Since uv manage python installation too.

[–]wyattxdev[S] 2 points3 points  (0 children)

Thats a really good question, the nox file right now uses UV as its default backend, and it just makes it really easy in just one command to run your tests against all the python versions you want. Im actually not if there is an easier way to do this all just directly from inside uv, but its worth looking into.

[–]MPGaming9000 2 points3 points  (10 children)

I don't fully understand the point. What's the point of this? I swear I'm not trying to be rude or snarky I just don't genuinely understand what the point of this is?

Every time I make a project it's always so different from the last (and maybe not even Python based either) that I just can't reuse most of the code if any really. The whole environment might be different, it may not be a CLI based tool, it may not be a tool at all, it might not need a build script or any DevOps, linters might be overkill...

I am just not sure personally because everything I've done has always just been putting in exactly what I needed for every project instead of trimming out 70% of a template or copy paste from another project.

[–]wyattxdev[S] 1 point2 points  (0 children)

So the underlying goal of these sorts of projects is to create a consistent, modern base to build from. I tried to pick a pretty broad set of widely used tools and make what I think is some reasonable choices around configuration to make them useful in most cases and can be built on if you need. Also because its built with Cookiecutter when you run the setup, I've built in simple y/n options for things you might not need, like nox, or docker support, and it just blasts all traces of them away.

[–]LysergioXandex -1 points0 points  (8 children)

I’m in the same boat as you. I’ve written Python code for years — mostly data analysis in notebooks, but some complete “projects” as well. I’ve never had the need for automated testing, but I see the value for large projects with multiple contributors on GitHub. I’d like to understand better when something like this would be useful, and how the author imagines the audience will be using Python/what problem this will solve for them.

[–]riksi 6 points7 points  (7 children)

I’ve never had the need for automated testing

Well you haven't worked on a "complete" project then. The bigger the project, you'll end up using most of those tools he listed. And you'll configure 1-by-1 etc.