pypa / hatch

Modern, extensible Python project management
https://hatch.pypa.io/latest/
MIT License
6.1k stars 309 forks source link

There is no option to install the project with --no-deps or equivalent #1733

Open TurbineJoshua opened 2 months ago

TurbineJoshua commented 2 months ago

I am currently working on a suite of Python projects where conflicting dependencies are to be expected. For example, we have a wheel that is depending on numpy==1.24.0 and a wheel that is depending on numpy==1.26.4. The way we've been approaching this is to generate an expanded_requirements.txt by installing each of the explicit dependencies in requirements.txt into a clean virtual environment using --dry-run and recording the returned dependencies into the expanded_requirements.txt file. In our hatch.toml we are defining:

[metadata.hooks.requirements_txt]
files = ["requirements.txt", "expanded_requirements.txt"]

The high-level idea is that the developer can then go through the expanded_requirements.txt and resolve conflicts. For example, delete the line referring to numpy==1.26.4 and confirm that the tests pass using numpy==1.24.0. Then, when the wheel is created, or environments are created, the --no-deps flag can be used with either pip or uv pip to install the dependencies explicitly listed in requirements.txt and expanded_requirements.txt.

However, when hatch goes to install the project, there is no way to specify --no-deps. Therefore, when I go to try and create the types or hatch-test environments, I see errors around the conflicting dependencies that would normally arise from trying to install the explicitly required packages.

I have attempted adding a uv.toml with:

[pip]
no-deps = true

This does correctly disable dependency expansion, but this ends up breaking the installation of hatch's infrastructure packages in the backends.

I think what I would like is either:

For example, if I add skip-install = true to the [envs.hatch-test], then I am able to correctly load the shell. Once I'm in the shell, I can run uv pip install --no-deps -r requirements.txt -r expanded_requirements.txt to install all of the dependencies correctly. I thought of using this command in the post-install-commands, but it looks like none of install, pre-install-commands or post-install-commands are executed when skip-install is specified.

I am happy to help with a PR, but would love some feedback from the community (@ofek) on the best way to proceed. Thank you for your time!

TurbineJoshua commented 2 months ago

I have solved this, for now, by using:

[envs.hatch-test]
skip-install = true

[envs.hatch-test.scripts]
"install-deps" = "uv pip install --no-deps -r requirements.txt -r expanded_requirements.txt ."