hatch icon indicating copy to clipboard operation
hatch copied to clipboard

Hatch environments support PEP735 dependency-groups

Open djcopley opened this issue 9 months ago • 1 comments

Closes #754 Closes #1852

djcopley avatar Feb 28 '25 20:02 djcopley

@ofek have you put any further thought into this? I was VERY suprised to find out that Hatch did not support this PEP and was thus incompatible with uv and pixi, as others have mentioned. I would be happy to contribute if it is labor that is blocking this; if it's more of an administration, your thoughts on whether or not this will be something that Hatch plans to support would be very appreciated!

schlich avatar Jun 08 '25 13:06 schlich

Greetings all,

I want this feature very much in hatch. I'm willing to put in the necessary work like others above, but that does not seem the blocker here. In any case, please let us know how we can contribute.

Midnighter avatar Sep 02 '25 10:09 Midnighter

Hi friends 👋🏻 it would be really helpful to include this PR in a future release if possible! We are using both development and optional dependencies in our packaging template. Being able to define dependencies and development devs in a standard TOML format that is not Hatch specific, but then use those in Hatch environments, would make the user experience much simpler and smoother as they learn about and use dependencies!

lwasser avatar Nov 03 '25 23:11 lwasser

I have some free time to work on this this week. It seems like this hasn't had any sort of resolution. I personally am a fan of the current implementation, but feel free to weigh in. I think it would be great to get this merged.

djcopley avatar Nov 04 '25 01:11 djcopley

Please describe the current implementation at a high level as well as a brief description of the comment you mentioned. This needs to be rebased as well. I plan to merge this by Monday right after #2073.

ofek avatar Nov 04 '25 01:11 ofek

So I propose that we change hatch to actually collect the list of defined dependency groups and merge it with the list of hatch envs (each dependency group implicitly defines a hatch env, and each hatch env implicitly installs its corresponding dependency group). ofek should weigh in here.

Explicit is better than implicit. I do not think it is the right approach to make these implicit mappings. Implicit mappings like this become brittle over time and prone to breakages from changes.

cjames23 avatar Nov 05 '25 01:11 cjames23

Explicit is better than implicit. I do not think it is the right approach to make these implicit mappings. Implicit mappings like this become brittle over time and prone to breakages from changes.

I fully agree with this. Additionally, I want to be able to use dependency groups much like extras/features today. That means, I want to define custom environments where I choose one or more groups of dependencies.

Midnighter avatar Nov 05 '25 08:11 Midnighter

@ofek rebased.

Please describe the current implementation at a high level

This PR integrates PEP 735 dependency groups into hatch environments similarly to the existing "features" (optional dependencies) implementation. Users can specify an array of dependency groups to compose requirements for a hatch environment.

high level as well as a brief description of the comment you mentioned

@flying-sheep was advocating for an alternate behavior where dependency groups would be treated as de facto hatch environments. For example, a doc dependency group would implicitly be a hatch environment. It isn't how I personally want to use this feature, and I prefer an approach that allows me to organize my dependency groups orthogonally to my environments; however, I don't want to straw-man his argument so I recommend reading the last 2 or 3 comments in that thread if you have time.

djcopley avatar Nov 06 '25 06:11 djcopley

I’m totally fine if you don’t go this route. I get now that some dependency groups might only exist as a building block for others (which in turn define a full environment for some purpose), and there is no way to know which are which, so automatically defining a hatch env for every group doesn’t make sense.

flying-sheep avatar Nov 06 '25 09:11 flying-sheep

@ofek these changes look good to me. I think once the branch conflicts resolution is done we can merge this as well and maybe release this and workspace environments at the same time.

Thanks everyone for the patience while Ofek and I worked through the PR for workspace environments!

cjames23 avatar Nov 07 '25 23:11 cjames23

@ofek this is up-to-date

djcopley avatar Nov 11 '25 00:11 djcopley

Thanks a lot for this contribution Daniel!

ofek avatar Nov 12 '25 00:11 ofek

This is huge! Thank you all for the work on it here ✨

lwasser avatar Nov 12 '25 21:11 lwasser

Seems like we missed typing:

https://github.com/pypa/hatch/issues/2114

flying-sheep avatar Nov 27 '25 15:11 flying-sheep