ruff: FA102 errors eventhough requires-python in pyproject.toml is ">=3.12"
I have the following (standard) directory layout:
├── src
│ └── packagename
│ └── ...
├── pyproject.toml
└── ruff.toml
Part from my pyproject.toml:
[project]
name = "packagename"
requires-python = ">=3.12"
My complete ruff.toml:
src = ["src"]
[format]
skip-magic-trailing-comma = true
line-ending = "lf"
[lint]
select = ["ALL"]
ignore = ["ANN101", "D203", "D213", "S320"]
Ruff version: 0.3.0, run with the command ruff check in the directory of pyproject.toml.
In the rule FA102, it is mentioned:
This rule respects the target-version setting. For example, if your project targets Python 3.10 and above, adding from future import annotations does not impact your ability to leverage PEP 604-style unions (e.g., to convert Optional[str] to str | None). As such, this rule will only flag such usages if your project targets Python 3.9 or below.
In the documentation of target-version it is mentioned that requires-python in pyproject.toml is preferred over the target-version option in ruff.toml.
If I add target-version = "py312" to my ruff.toml, then there are no FA102 errors.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 3
- Comments: 26 (18 by maintainers)
Commits related to this issue
- These keys must be kept in sync If `ruff.toml` exists, the `requires-python` key is currently not taken into account - not in `pyproject.toml` and even less in `setup.cfg`. See: https://github.com/a... — committed to DimitriPapadopoulos/skeleton by DimitriPapadopoulos 3 years ago
- These keys must be kept in sync If `ruff.toml` exists, the `requires-python` key is currently not taken into account - not in `pyproject.toml` and even less in `setup.cfg`. See: https://github.com/a... — committed to DimitriPapadopoulos/skeleton by DimitriPapadopoulos 3 years ago
- Include pyproject.toml in ruff.toml. Closes jaraco/skeleton#119. Workaround for astral-sh/ruff#10299. — committed to jaraco/skeleton by jaraco 2 years ago
- Use extend for proper workaround. Closes #152 Workaround for astral-sh/ruff#10299 — committed to jaraco/skeleton by jaraco 2 years ago
- Use extend for proper workaround. Closes jaraco/skeleton#152 Workaround for astral-sh/ruff#10299 — committed to jaraco/skeleton by jaraco 2 years ago
- Work around `ruff` issue The minimum Python version is Python 3.8. From `pyproject.toml`: requires-python = ">=3.8" However, `ruff.toml` shadows `pyproject.toml`, prompting ruff to use its default ... — committed to DimitriPapadopoulos/hatch by DimitriPapadopoulos 2 years ago
- ruff: no need for target-version anymore, it can extract from pyproject.toml see https://github.com/astral-sh/ruff/issues/10299 which is resolved now — committed to karlicoss/pymplate by karlicoss 2 years ago
- ruff: no need for target-version anymore, it can extract from pyproject.toml see https://github.com/astral-sh/ruff/issues/10299 which is resolved now — committed to karlicoss/pymplate by karlicoss 2 years ago
Is this solved by https://github.com/astral-sh/ruff/pull/16319 ?
You can use
per-file-target-versionorextendwithtarget-version@Winand whether you want to open a new issue depends on your goal:
We should probably do the same as for uv and what’s planned for Red Knot.
If there’s both a
ruff.tomlandpyproject.toml, use theruff.tomlbut fallback to thepyproject.toml’srequires-pythonif thetarget-versionis left unspecified.I’d like to make the case that ruff should not be relying on declared configuration and should instead rely on the core metadata for the package. Although
pyproject.tomlis a standard for a source distribution to declare metadata, it’s not (and should not) be required that the package’s metadata be declared through pyproject.toml. As an extreme example, the coherent build system doesn’t require any pyproject.toml and instead derives all of the metadata (including theRequires-Pythondeclaration) from environmental state, specifically the tags on the CPython repository in GitHub.For this reason, the supported/required Python versions for a Coherent project or any other build system that dynamically or programmatically generates that metadata field won’t have a declaration in the
pyproject.tomlnorruff.toml.There are other build backends that produce “dynamic” values for various metadata fields, so addressing just the Requires-Python field will leave those fields unaddressed.
There’s clear value for projects in not having to statically manifest all of their metadata in source code (and maintain that state, possibly shared across or even diverging within many projects).
My recommendation would be for Ruff to generate the package metadata through the PEP 517
prepare_metadata_for_build_wheelhook and then read theRequires-Pythonfield.I know this approach can be potentially expensive (and for Coherent projects is currently very expensive, but that’s largely the backend’s problem), so it may be necessary to cache the value (or the metadata) for extended periods.
This approach would have added benefits that other core metadata can be resolved by ruff, even when it’s dynamic.
Such an approach would sidestep workarounds like
extend = "pyproject.toml"or duplicating the metadata in two files and would honor the essential metadata of the package.