How does hatch locate python versions? Can it work with pyenv? #642
-
I am stumped trying to figure out how to make hatch work with pyenv. I think I do not understand how hatch tries to locate the available python versions. https://hatch.pypa.io/latest/config/hatch/#python-installations talks about "where to install python versions". This phrasing suggests hatch is going to install python versions on my machine, is that correctly understood? Or this this mean that I could point in this config file to my local pyenv folder and all would be fine? Am a bit hesitant to try as i do not want to mess up my pyenv directory. https://hatch.pypa.io/latest/config/environment/advanced/#python-variables does not tell me how to ensure hatch actually finds the referred pythons. https://hatch.pypa.io/latest/config/environment/overview/#python-version explains that one could also provide absolute paths but that would not be very helpful when setting this in pyproject.toml as I am sharing this with other developers. So hard coding a path is not a great option there. Ideally, hatch would be able to work with pyenv by setting a config setting, providing an env variable, or any other way - but I cannot figure out how... Any input on how to achieve this? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
I can't find any references to Hatch's default environment, ❯ hatch env show
Standalone
┏━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━┓
┃ Name ┃ Type ┃ Dependencies ┃ Scripts ┃
┡━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━┩
│ default │ virtual │ pytest │ cov │
│ │ │ pytest-cov │ no-cov │
└─────────┴─────────┴──────────────┴─────────┘
Matrices
┏━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━┓
┃ Name ┃ Type ┃ Envs ┃ Dependencies ┃ Scripts ┃
┡━━━━━━╇━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━┩
│ test │ virtual │ test.py37 │ pytest │ cov │
│ │ │ test.py38 │ pytest-cov │ no-cov │
│ │ │ test.py39 │ │ │
│ │ │ test.py310 │ │ │
│ │ │ test.py311 │ │ │
└──────┴─────────┴────────────┴──────────────┴─────────┘
❯ hatch env create
Environment `default` is incompatible: cannot locate Python: 3.7
❯ hatch run test.py39:cov
Environment `test.py39` is incompatible: cannot locate Python: 39 However, setting multiple Python versions with Pyenv is possible, and allows ❯ pyenv local 3.8.16 3.9.16 3.10.9 3.11.1 3.7.16
❯ hatch run cov
=================================== test session starts ===================================
platform linux -- Python 3.7.16, pytest-7.2.0, pluggy-1.0.0
rootdir: /tmp/mypkg
plugins: cov-4.0.0
collected 0 items
---------- coverage: platform linux, python 3.7.16-final-0 -----------
Name Stmts Miss Cover Missing
-----------------------------------------------------
src/mypkg/__init__.py 0 0 100%
tests/__init__.py 0 0 100%
-----------------------------------------------------
TOTAL 0 0 100%
================================== no tests ran in 0.01s ==================================
❯ hatch run test.py311:cov
=================================== test session starts ===================================
platform linux -- Python 3.11.1, pytest-7.2.0, pluggy-1.0.0
rootdir: /tmp/mypkg
plugins: cov-4.0.0
collected 0 items
---------- coverage: platform linux, python 3.11.1-final-0 -----------
Name Stmts Miss Cover Missing
-----------------------------------------------------
src/mypkg/__init__.py 0 0 100%
tests/__init__.py 0 0 100%
-----------------------------------------------------
TOTAL 0 0 100%
================================== no tests ran in 0.01s ================================== |
Beta Was this translation helpful? Give feedback.
-
FYI in the documentation I'm going to begin discouraging the use of pyenv now that we have these features: |
Beta Was this translation helpful? Give feedback.
-
In my corporate setting I can manage python with uv, but hatch runs into ssl cert issues I’m not able to resolve. would be nice if one could override the behaviour of hatch to install python and just use paths |
Beta Was this translation helpful? Give feedback.
I can't find any references to
dirs.python
in the codebase outside ofDirConfig
(maybe it's for a planned feature? 🤷🏾♂️).Hatch's default environment,
virtual
usesvirtualenv
to discover python versions, which can't see pyenv's versions: