pypa / hatch

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

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

Open nikitajz opened 7 months ago

nikitajz commented 7 months ago

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 commented 7 months ago

Seems loosely related https://github.com/pypa/hatch/issues/1097 and https://github.com/pypa/hatch/issues/1126

a-reich commented 3 months ago

+1 to this - it tripped me up because the docs say “dependencies are automatically synced” each time the environment is used, but it didn’t occur to me that this would mean only package dependencies and not python version.