hatch icon indicating copy to clipboard operation
hatch copied to clipboard

Hatch doesn't pick up python version when changed in the config

Open nikitajz opened this issue 1 year ago • 2 comments

Issue

When tool.hatch.envs.default.python is specified after the first run (was not before) or amended, hatch keeps using the old version of python. In order to actually apply the change, the old environment should be deleted. It might not be interpreted as a bug per ce, but it's not what is expected intuitively.

How to reproduce

Stage 1: No python version is specified under tool.hatch.*

pyproject.toml:

[project]
requires-python = ">=3.9"
# ...

[tool.hatch.envs.default]
extra-dependencies = [
    "pytest~=7.4.4"
]

Run: hatch run pytest Hatch installs the latest available python version, for example, python=3.12

❯ hatch run pytest
============================================ test session starts ============================================
platform darwin -- Python 3.12.2, pytest-7.4.4, pluggy-1.4.0
...

Stage 2: Specify python version explicitly

pyproject.toml:

# ...

[tool.hatch.envs.default]
python=3.9

#...

Run: hatch run test Expected: Hatch rebuild environment using python=3.9 Actual: Hatch keeps using python=3.12

To use python=3.9 you have to remove existing env manually, for example, hatch env prune

nikitajz avatar Mar 15 '24 11:03 nikitajz