hatch
hatch copied to clipboard
Environment "path" does not support context formatting
When defining the "path" setting in an environment, it should I think be possible to use context formatting. For example, the {env_name}
and {python}
variables are not interpolated.
Steps to reproduce:
pyproject.toml
[tool.hatch.envs.venv]
path = ".venv/{python}"
[[tool.hatch.envs.venv.matrix]]
python = ["3.7", "3.8", "3.9", "3.10", "3.11"]
hatch env find venv.py3.8
Expected:
/path/to/project/dir/.venv/3.8
Actual
/path/to/project/dir/{python}
{matrix:python}
https://hatch.pypa.io/latest/config/environment/advanced/#context-formatting
This is not working with my current configuration, with hatch 1.7.0
Oddly this does work in the scripts section
[tool.hatch.envs.venv.scripts]
display = "echo {matrix:python}"
oh that option I think just doesn't support context formatting. can you explain what you are trying to do?
I am trying to set the default location for virtual environments to be in the project dir, so that I can easily use hatch environments with IDEs
I understand this can be set using the [dirs.env]
in the hatch configuration, but I wanted to be able to set this on a project level
What is the process for overriding config parameters that are shown in hatch config show
?
Oddly enough adding various parameters to a hatch.toml
in user home, and also in project root dir, is not working.
Similarly, setting the following in pyproject.toml
is also not working for me?
[tool.hatch]
shell = "foo"
there is no way to do that at the project level, which I think makes sense because developers would want control over where potentially large directories are located
I can add this as a feature if you really want
Ah I see. Makes sense yeah.
I think it would make more sense to support context formatting in the env path
option. What do you think?
It would be nice if we can use home:uri
variable as well
That works already.
This is not working, am I doing something wrong?
[tool.hatch.envs.default]
path = "{home:uri}/.virtualenvs"
Sorry, I meant to say for options that support context formatting it works. This option still does not but I will fix that soon.
Am I understanding correctly that this is a particular case of the environment config
dictionary not supporting context formatting?
If that is so, I have a different use case where context formatting would be helpful. I am trying to use hatch-conda, which has a command
option where you specify one of "conda"
, "mamba"
, or "micromamba"
. It would be helpful to be able to use context formatting here so I could use "mamba"
for local development and "micromamba"
for CI, controlled by environment variables.
Implementing that particular request would be up to the plugin author.
@ofek from following the code, it seems like plugin-specific config options still go through EnvironmentInterface.config
.
https://github.com/pypa/hatch/blob/cfa05386f9dc4a029462a23a38d0885176efbaac/src/hatch/env/plugin/interface.py#L158-L165
Wouldn't both path
and these other plugin-specific config options all end up supporting context formatting if the config
property there returns config values with context formatting?
True I guess I could do every option, although I'm thinking about if that is desirable in every circumstance. What do you think?
Also looking for support of conditional formatting for path
key. Currently I have to do like this:
[tool.hatch.envs.py38]
path = ".venvs/py38"
python = "3.8"
[tool.hatch.envs.py39]
path = ".venvs/py39"
python = "3.9"
[tool.hatch.envs.py310]
path = ".venvs/py310"
python = "3.10"