pypa / hatch

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

Is pinning dependencies in the `hatch-test` environments recommended? #1684

Closed eswolinsky3241 closed 3 months ago

eswolinsky3241 commented 3 months ago

Hi, I'm sorry if I'm missing this in the documentation, but I'm looking to understand best practices for the internal hatch- environments, specifically for building applications rather than libraries.

I'm using the hatch-pip-compile plugin to pin my dependencies for my application. My default environment looks like this:

[tool.hatch.envs.default]
type = "pip-compile"
installer = "uv"
pip-compile-resolver = "uv"
pip-compile-args = ["--no-emit-index-url"]
pip-compile-installer = "uv"
lock-filename = "lockfiles/requirements-{env_name}.txt"
python = "3.12"

When I create this environment, I see the lockfiles/requirements-default.txt file as expected.

I think the hatch test command is great in that I don't have to define my own test scripts and dependencies for every project. However, I'd like to pin my dependencies to avoid a future change breaking my tests in CI. I was surprised that using the test command did not generate lockfiles, given that I was expecting the hatch-test* environments to inherit from my default environment configuration, meaning those environments would also be pip-compile environments.

So it seems like maybe the internal environments do not follow the inheritance rule, and I was wondering if there is any guidance on whether I should be separately configuring the hatch-test environment to duplicate the pip-compile` configuration? Or is it preferred to leave the internal environments opinionated, and create my own custom test environment? Thanks in advance!

eswolinsky3241 commented 3 months ago

@ofek Sorry if this question is answered elsewhere, but I was wondering if you had any guidance here? I think I'm a bit confused overall on how hatch is intended to manage dependencies for an application rather than a library. Would it be feasible to add an option to allow the hatch-test environment to inherit settings from default?

ofek commented 3 months ago

Yes, internal environments do not inherit from default so you would have to configure them separately. Thanks for the reminder, I forgot to respond!