pypa / hatch

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

Possible feature: Support .python-version #1126

Open flying-sheep opened 7 months ago

flying-sheep commented 7 months ago

pyenv and Rye both use a .python-version file to define what version they use.

Pros

Hatch could use it as a default for hatch.envs.default.python, and it

  1. would simplify transition from Pyenv/Rye or interoperability with those projects.
  2. Could be used to implement #1097

Cons

  1. .python-version is not a standard
  2. It makes it a bit harder to reason about what version Hatch will default to (see below). I don’t know if this is a problem, as interrogating the used version is easy, and explicitly overriding it is easy, too.

Impact

It would make the fallback chain for the Python version look something like the following

  1. hatch.envs.<env>.overrides.<matching condition>.python
  2. hatch.envs.<env>.python
  3. hatch.envs.default.python (assuming hatch.envs.<env>.template = 'default' or unspecified)
  4. .python-version
  5. minimum version matching project.requires_python
ofek commented 7 months ago

Thank you for expanding on how the resolution would work! I am open to this 🙂

ofek commented 7 months ago

Somewhat unrelated, but would this functionality be useful to you? https://github.com/pypa/hatch/discussions/1124#discussioncomment-7832642

flying-sheep commented 7 months ago

Thank you for expanding on how the resolution would work! I am open to this 🙂

Let’s ask people if they want this. It was just an idea that I had to ease transition. I’m personally committed to Hatch lol

Somewhat unrelated, but would this functionality be useful to you? https://github.com/pypa/hatch/discussions/1124#discussioncomment-7832642

answered there

funkyfuture commented 7 months ago

since the proposed feature adapts one of the many non-standard practices in the ecosystem, i propose to implement this in an Environment Collector plugin.

ketozhang commented 5 months ago

+1 My use case is that I have an application project which requires everyone on the team to be on the same Python version as the one deployed in production. However, my team has not adopted Hatch.

Having .python-version along side hatch.toml would let us enforce a Python version without enforcing Hatch.

project.requires_python can be an alternative, but pyproject.toml is not ideal for project-manager-agnostic application projects (yet).