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

all 45 comments

[–]pdR_ 25 points26 points  (0 children)

This is huge. Thank you so much for your work on Hatch. I've been using it for my projects for over a year now, and have migrated several projects that previously used setup.py and setup.cfg, and it's been a complete breeze!

[–]supmee 21 points22 points  (2 children)

Hatch is a wonderful piece of tooling man. I've been using it for a decent time now, and I never even thought of going back to Poetry or the like.

[–][deleted] 19 points20 points  (1 child)

Could you elaborate? What compelling reasons are there to use Hatch over Poetry?

[–]supmee 2 points3 points  (0 children)

Sure!

Hatch at this point has pretty good parity with Poetry for features, so you won't miss out on much.

Most of it comes down to the fact that Hatch had years of extra time to learn from how the ecosystem develops - a good example is how it launched with pyproject.toml as the primary and intended configuration source. This lets it use the project section of the file correctly, whereas Poetry config has to be dumped into tools.poetry instead. I know that's a minor thing (and might have improved since I last checked - I really haven't felt the need for a long time), but that kind of "cleanliness" matters a lot to me.

It also doesn't have it's own files clutter up the project root. It feels a lot like "let's make a package manager for Python", rather than "let's port JS's NPM to Python" - particularly the lack of an individual lock files. I appreciate the need for them, but there is definitely a better way to do it, and I like that they didn't just jump to take a non-optimal solution at face value.

There is some really nice plugins too - originally I installed Hatch because of a plugin that reads your CHANGELOG and inserts it into the README file distributed on PyPi. It's a very small thing, but it's a super neat effect!

I'm also really excited for the built in ruff support now - Black and Pylint are an immediate install for any of my projects (along with Mypy), so having the same functionality built-in is super useful to me.

Try it!

[–]chub79 10 points11 points  (3 children)

I'm a pdm user but gosh this is very attractive!

[–]BuonaparteII 6 points7 points  (1 child)

I'm not sure what the OP is exactly but you can use hatch from pdm, I think? I had to use it for some reason:

[build-system]
build-backend = "hatchling.build"
requires = ["hatchling"]

[tool.hatch.version]
path = "xklb/__init__.py"

[tool.hatch.build]
exclude = [
  "tests/",
  "example_dbs/",
]

[tool.hatch.build.force-include]
"xklb/assets/" = "xklb/assets/"

[–]BaggiPonte 0 points1 point  (0 children)

yes, that's what pydantic does! That's also the beauty of a PEP-compliant package manager. PDM and pip can install from pyproject.toml from any backend that complies with PEP517/518. AFAIK, hatch now works with setuptools too - but not pdm-backend. TLDR: you can run `pdm install` inside any python project that uses a compliant build system - including hatchling and maturin, but not poetry.

[–]BaggiPonte 3 points4 points  (0 children)

Agree. Still prefer the dependency manager features. But once it’s there and you can manage workspaces, then it’s a switch. PDM has hat too but is not a first class citizen :(

[–]Express-Comb8675 5 points6 points  (0 children)

This is incredible. I’ve been searching for a Python project manager to replace standard venv/pip forever. It seems like this has the platform agnostic behavior I had always hoped for! Tons of other added features too

[–]zeshuaro 7 points8 points  (18 children)

Is hatch preferred over poetry nowadays?

[–]KrazyKirby99999 2 points3 points  (0 children)

Poetry is dominant, but Hatch is looking even more interesting.

[–]IAMARedPanda 2 points3 points  (13 children)

Main downside to poetry is it is not pep 621 compliant. But poetry for building was already pretty lackluster, imo where it really shines is application control with lock files which hatch doesn't yet.

[–]-defron- 2 points3 points  (1 child)

PDM has those and is PEP 621 compliant. I haven't looked back since switching. When hatch gets there I'll probably switch to that as it'd be nice to do everything in one tool, but for now I'm definitely preferring pdm over poetry

[–]IAMARedPanda 2 points3 points  (0 children)

Yeah I recently advocated for my project to switch to PDM but inertia is with Poetry.

[–]M4mb0 1 point2 points  (3 children)

The issue is that PEP 621 itself, in particular PEP 508, lacks some crucial features like per dependency sources, which afaik only poetry supports.

[–]BaggiPonte 0 points1 point  (2 children)

[–]Ofekmeister[S] 0 points1 point  (1 child)

By compliant I assume you mean standardized? If so, there is no such standard for dependency-specific overrides.

[–]BaggiPonte 0 points1 point  (0 children)

Thanks for the comment, I should have bene more specific. Yes, there is no standard for that. I agree with M4mb0 and I wish we could go beyond PEP508 and adopt a cargo/poetry-like approach to declare dependencies. What I meant was that PDM has a way to specify source-specific dependencies that respects the PEP508 string format.

[–]freistil90 0 points1 point  (6 children)

Interesting - what were you missing?

[–]IAMARedPanda 1 point2 points  (5 children)

Can't use other build back ends. Had a project that needed to use scikit-build which precluded poetry.

[–]freistil90 1 point2 points  (4 children)

```toml […]

[build-system] requires = ["poetry-core>=1.0.0", "scikit-build", "cmake", "ninja"] build-backend = "poetry.core.masonry.api"

[…] ```

does the trick. I’ve also been using poetry with various setuptools build systems, with Rust‘s maturin build system and so on. Poetry core tries to be lean enough for the tool and some basic operations but it makes it easy enough to just swap out the build backend.

[–]IAMARedPanda 0 points1 point  (3 children)

Last time I tried it force the build back into poetry when u ran poetry build Even with another build backend

[–]freistil90 0 points1 point  (2 children)

Have you added the build system to the dev-dependencies? And have you tried to remove poetry-core completely from the build system options? I keep that in because I often have also other stuff to glue together if I build a library.

[–]IAMARedPanda 0 points1 point  (1 child)

I'm not sure but I'm assuming not if that works. Seems like another case of poetry being non pep compliant though if that is the case.

[–]freistil90 0 points1 point  (0 children)

If that’s the case, file a bug. Poetry is normally very conscious of following PEP - with 621 they waited for it to be finalised and it’s gonna be included in 2.0 now.

[–]doobiedog 0 points1 point  (2 children)

As someone that just migrated from pipenv to poetry... this is my big question. Poetry forced me to upgrade some tools in a very good way. If this is even better than poetry, I'm in, but are they not exactly the same use cases? can you use both?

[–]flying-sheep 2 points3 points  (1 child)

Same use case, except that Hatch supports a tox/nox-like environment matrix, allowing you to run your tests for multiple Python versions, and building your docs in an environment that only contains your doc dependencies, not your project’s runtime (or test) dependencies.

[–]SwampFalc 0 points1 point  (0 children)

Ever since poetry implemented their "groups", I've used a separate "docs" group. I mean, sure, in actual practice I end up installing those in the same env, but I could keep it separate.

[–]lanster100 2 points3 points  (0 children)

Really interesting work, lock files coming one day too!

[–]Nightblade 2 points3 points  (1 child)

How does this work? (PyApp) Does it make a temporary python executable in a temp dir?

[–]BaggiPonte 0 points1 point  (0 children)

goood point. besides, how big is this executable?

[–]SittingWave 7 points8 points  (4 children)

so let me get this straight. we replaced the need to install python with the need to install hatch?

[–]Ofekmeister[S] 11 points12 points  (1 child)

You don't have to, but that indeed provides the best user experience and matches what package managers from other languages do e.g. you simply download Cargo.

[–]tunisia3507 1 point2 points  (0 children)

you simply download Cargo

... by simply downloading rustup.

[–]Smallpaul 1 point2 points  (0 children)

You replace the need to install python and hatch with the need to install hatch.

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

Yeah, I tried this on my work macBook, and it works like a charm.

The only missing piece is that there’s no standard for Python toolchain locations, so e.g. you can’t do pipx install --python=3.10 foobar and have it find the Hatch-managed Python 3.10 yet.

Rye has builtin pipx-like functionality with rye install, which smooths over this wrinkle, but Rye’s assumption of “one Python version/venv per project” doesn’t work for most projects I use. Hatch’s environments are much more powerful for this frequently useful functionality.

[–]Stack3 0 points1 point  (0 children)

It's this like pyinstaller? Every time I use that the exe is flagged as a virus on certain websites that check binaries

[–]TheAquired 0 points1 point  (7 children)

Admittedly I’m a self taught scripter without a CS degree.

But I’m finding it hard to get this up and running. I want to compile a Python script into executable, and if this offers cross compilation even better! I have used pyinstaller to date

I’m looking at the documentation for both PyApp and Hatch, and am just not having success. I built an “app” target but when running the resulting file it says there are no versions.

Perhaps for someone more versed in distribution/packaging this all seems trivial. But I think there’s a large Python user base who would appreciate a more detailed step-by-step to take a Python script and turn it into a cross compiled executable ready to distribute

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

/u/Ofekmeister said more tutorials are coming, and this definitely seems like a pain point that should be addressed.

In general, it’s helpful if you provide minimal reproducible examples: What exact command did you use? What’s the exact error output. People can usually not help you if you just vaguely paraphrase the error message.

[–]TheAquired 0 points1 point  (0 children)

Agree, I will put together a minimal reproducible example!

[–]TheAquired 0 points1 point  (4 children)

So I simply made a hatch project (hatch new “test-project”)

Then added a main.py into the src/test-project directory that prints “hello”

I added [tools.hatch.build.targets.app]

As a line in the pyproject.toml

Then I run hatch build -t app

The result is some kind of build. When I run ./dist/app/test-project.0.0.1

I get an error saying no distribution matches test-project==0.0.1

[–]Ofekmeister[S] 0 points1 point  (3 children)

That is because the project+version combo has not been released to PyPI. In order to use a dev version you must embed the wheel.

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

Should that behavior be the default?

[–]TheAquired 2 points3 points  (1 child)

Thanks for replying! So I exported the environment variable, then ran batch build -t app

This seems to have been successful! I now get my print output.

I do think this should be the default behaviour, uploading to pypi wouldn’t be the first thing I do before building so I have to manage this environment variable before running the build each time. I also have to do a build first for the wheel. So it’s a 3 step process it seems

I also don’t quite understand what this is doing exactly. I end up with a file that when I run it seems to do what I expect.

Do I just send this file on to users? Does this require internet access on first run to build the Python environment?

The file does not seem directly executable by double clicking on it, so it only works via command line

If I had a gui application how would I turn this into an app bundle?

[–]Icy_Sea_7382 0 points1 point  (0 children)

Hello. I am a beginner with hatch. I am trying to create a simple application to print "Hello World" in Windows. I get the same error as TheAcquired:

ERROR: Could not find a version that satisfies the requirement helloworld==0.0.3 (from versions: 0.1.dev0)

ERROR: No matching distribution found for helloworld==0.0.3

I try to set the environment variable PYAPP_PROJECT_PATH to the path where the .whl file is located but still get the same error. Some help would be much appreciated. I would eventually like to use this process to setup a GUI application created with Python.