Add support for reading the ruff version from Poetry groups (#127)

Not sure if this is a desired feature since this was requested already
(https://github.com/astral-sh/ruff-action/issues/40#issuecomment-2581207691)
without any sort of response.
Unfortunately Poetry doesn't yet support PEP 735
(https://github.com/python-poetry/poetry/issues/9751) and it doesn't
make sense to add ruff as a project dependency.
This commit is contained in:
Simon Berger
2025-04-27 14:37:48 +02:00
committed by GitHub
parent 719c6e52c1
commit 400ab365db
7 changed files with 82 additions and 10 deletions
Generated Vendored
+14 -1
View File
@@ -30933,7 +30933,20 @@ function parsePyproject(pyprojectContent) {
const devDependencies = Object.values(pyproject?.["dependency-groups"] || {})
.flat()
.filter((item) => typeof item === "string");
return getRuffVersionFromAllDependencies(dependencies.concat(optionalDependencies, devDependencies));
return (getRuffVersionFromAllDependencies(dependencies.concat(optionalDependencies, devDependencies)) || getRuffVersionFromPoetryGroups(pyproject));
}
function getRuffVersionFromPoetryGroups(pyproject) {
// Special handling for Poetry until it supports PEP 735
// See: <https://github.com/python-poetry/poetry/issues/9751>
const poetryGroups = Object.values(pyproject?.tool?.poetry?.group || {});
return poetryGroups
.flatMap((group) => Object.entries(group.dependencies))
.map(([name, spec]) => {
if (name === "ruff" && typeof spec === "string")
return spec;
return undefined;
})
.find((version) => version !== undefined);
}
function getRuffVersionFromRequirementsFile(filePath) {
if (!fs.existsSync(filePath)) {