Take Python version from the .python-version file
Description
Why do I have to specify the target-version when I already have a .python-version file?
When I am running a Python application (not a library that will be published), then .python-version should be enough I would think. requires-python becomes mostly useless, and target-version also seems kinda redundant? But when I remove both of those then ruff will complain to me.
Related: https://github.com/astral-sh/ruff/issues/4464
Supporting .python-version as a fallback does make sense for applications when neither target-version or project.requires-python is specified.
But I'm still somewhat hesitant to add this because it does mean that Ruff now has to probe one extra file when discovering a file's configuration. We also need to be careful about how this plays with inherited configurations, user level configurations, and extended configurations.
Yea that makes sense, I understand the hesitation. It's just a bit annoying that when I upgrade to a newer Python version that I have to change this in multiple places.
Actually, now that I think about it.. maybe I should just get rid of .python-version, and only use requires-python? I know uv likes to use .python-version, but it's not required, is it? Simply set requires-python to "==3.13.*" and I should be sure that 3.13 is used, both by uv and by ruff.
You could but it seems to be sort of an anti-pattern. See the conversation in https://github.com/astral-sh/uv/issues/11624#issuecomment-2669110520
I have a mono repo with over 100+ Python projects. I am hoping to add target-version.
Currently each subfolder has a .python-version (no requires-python) and .ruff.toml and if have something like
target-version = "py314"
extend = "../.ruff.toml"
target-version = "py313"
extend = "../.ruff.toml"
Renovate can bump .python-version, however, it cannot bump corresponding target-version in .ruff.toml in each subfolder.
It would be great to support .python-version as a fallback. Thanks! ☺️