Open kassett opened 3 months ago
You can have a base environment that you can use as a template that all environments may inherit from.
Is there documentation for this -- I haven't seen this yet?
Hey Ofek So actually I think that this doesn't exactly solve my use case. I want to set PYTHONPATH in each environment. Using a template is great, but that template cannot apply to the default environment, which is really a shame. Any ideas on how to fix this?
Can you give me two example environments and the expected value of that variable?
Yes of course. I have a default environment, which I would like to include the lint and test features, and then I have lint and test environments, which have different dependencies. I would like all of these environment export a PYTHONPATH and a few other environment variables. I could use the default environment as a template, but then I would be importing features that I don't want.
I'm trying to understand what the value of that variable would be in order to provide you accurate configuration.
[tool.hatch.envs.default]
dev-mode = true
python = "3.12"
features = [
"dev"
]
[tool.hatch.envs.default.env-vars]
PYTHONPATH = "backend"
[tool.hatch.envs.deploy]
dev-mode = true
python = "3.12"
In this case, I would like the PYTHONPATH to be exported in all environments AND I would like to use the default environment as an environment that has ALL features. Having a template that could be used for the default environment seems like the best course of action.
There is also a feature request to support .env
files; would that help?
Yeah I mean I'm specifically trying to avoid that, I think a more elegant solution would be something like
[tool.hatch.envs.*.env-vars]
Hey Ofek,
Was wondering what you think of this feature? I can add it.
I would love that, thanks! It would be part of this configuration table: https://github.com/pypa/hatch/blob/a27473d478299060327b52a85c22aa038171c376/src/hatch/project/config.py#L37
[tool.hatch.env]
What do you think of this? https://github.com/pypa/hatch/pull/1390 Or do you want just a "env-vars" under tool.hatch.env
It would also be great if the environment variables applied to the hatch-test env. It is currently not possible to set PIP_EXTRA_INDEX_URL
for the hatch test
command, which seems to ignore the variable set in the global environment.
The workaround is
[tool.hatch.envs.test]
description = "Testing with pytest"
type = "pip-compile"
lock-filename = "requirements/requirements-test-lock.txt"
template = "hatch-test"
[tool.hatch.envs.test.env-vars]
PIP_EXTRA_INDEX_URL = "https://privaterepo.com/simple"
The test environment does not inherit from anything so you must put all of your configuration within that i.e. in your example change the name to hatch-test
and it should work.
Can we add support for adding environment variables to all environments in a central place?