mirror of
https://github.com/astral-sh/ruff-action.git
synced 2026-05-12 20:50:14 +02:00
committed by
GitHub
parent
90ea8a399c
commit
deb632007b
@@ -160,6 +160,25 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
env:
|
env:
|
||||||
RUFF_VERSION: ${{ steps.ruff-action.outputs.ruff-version }}
|
RUFF_VERSION: ${{ steps.ruff-action.outputs.ruff-version }}
|
||||||
|
test-default-version-from-pyproject-dependency-groups-with-env-marker:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
- name: Use default version from pyproject.toml with environment marker
|
||||||
|
id: ruff-action
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
src: __tests__/fixtures/python-project
|
||||||
|
version-file: __tests__/fixtures/pyproject-dependency-groups-with-env-marker/pyproject.toml
|
||||||
|
- name: Correct version gets installed
|
||||||
|
run: |
|
||||||
|
if [ "$RUFF_VERSION" != "0.14.11" ]; then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
env:
|
||||||
|
RUFF_VERSION: ${{ steps.ruff-action.outputs.ruff-version }}
|
||||||
test-default-version-from-pyproject-poetry-groups:
|
test-default-version-from-pyproject-poetry-groups:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
@@ -398,6 +417,7 @@ jobs:
|
|||||||
- test-default-version-from-pyproject
|
- test-default-version-from-pyproject
|
||||||
- test-default-version-from-pyproject-dev-group
|
- test-default-version-from-pyproject-dev-group
|
||||||
- test-default-version-from-pyproject-dependency-groups
|
- test-default-version-from-pyproject-dependency-groups
|
||||||
|
- test-default-version-from-pyproject-dependency-groups-with-env-marker
|
||||||
- test-default-version-from-pyproject-poetry-groups
|
- test-default-version-from-pyproject-poetry-groups
|
||||||
- test-default-version-from-pyproject-poetry
|
- test-default-version-from-pyproject-poetry
|
||||||
- test-default-version-from-pyproject-optional-dependencies
|
- test-default-version-from-pyproject-optional-dependencies
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
[project]
|
||||||
|
name = "pyproject-dependency-groups-with-env-marker"
|
||||||
|
version = "0.1.0"
|
||||||
|
description = "Test fixture for issue #256 - environment markers"
|
||||||
|
readme = "README.md"
|
||||||
|
requires-python = ">=3.12"
|
||||||
|
|
||||||
|
[dependency-groups]
|
||||||
|
dev = [
|
||||||
|
"ruff>=0.14 ; python_version >= '3.11'",
|
||||||
|
]
|
||||||
|
|
||||||
|
[build-system]
|
||||||
|
requires = ["hatchling"]
|
||||||
|
build-backend = "hatchling.build"
|
||||||
@@ -13,6 +13,7 @@
|
|||||||
"ignoreUnknown": false,
|
"ignoreUnknown": false,
|
||||||
"includes": [
|
"includes": [
|
||||||
"**",
|
"**",
|
||||||
|
"!**/coverage",
|
||||||
"!**/dist",
|
"!**/dist",
|
||||||
"!**/lib",
|
"!**/lib",
|
||||||
"!**/node_modules",
|
"!**/node_modules",
|
||||||
|
|||||||
+43
-8
@@ -32346,21 +32346,55 @@ var __importStar = (this && this.__importStar) || (function () {
|
|||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
|
exports.findRuffVersionInSpec = findRuffVersionInSpec;
|
||||||
exports.getRuffVersionFromRequirementsFile = getRuffVersionFromRequirementsFile;
|
exports.getRuffVersionFromRequirementsFile = getRuffVersionFromRequirementsFile;
|
||||||
const fs = __importStar(__nccwpck_require__(3024));
|
const fs = __importStar(__nccwpck_require__(3024));
|
||||||
const core = __importStar(__nccwpck_require__(7484));
|
const core = __importStar(__nccwpck_require__(7484));
|
||||||
const toml = __importStar(__nccwpck_require__(7106));
|
const toml = __importStar(__nccwpck_require__(7106));
|
||||||
function getRuffVersionFromAllDependencies(allDependencies) {
|
/**
|
||||||
const ruffVersionDefinition = allDependencies.find((dep) => dep.startsWith("ruff"));
|
* Find ruff version in a dependency specification.
|
||||||
if (ruffVersionDefinition) {
|
* Only handles strings that start with "ruff" (e.g., "ruff==0.9.3").
|
||||||
const match = ruffVersionDefinition.trim().match(/^ruff\s*==\s*([^\s\\]+)/);
|
* Returns undefined for non-ruff dependencies.
|
||||||
|
* Strips environment markers (everything after ';').
|
||||||
|
* Strips leading '==' from exact version specifiers (PEP 440) for downstream compatibility.
|
||||||
|
*
|
||||||
|
* @internal This is exported for testing purposes only.
|
||||||
|
*/
|
||||||
|
function findRuffVersionInSpec(spec) {
|
||||||
|
const trimmedSpec = spec.trim();
|
||||||
|
const fullDepMatch = trimmedSpec.match(/^ruff\s*(.+)$/);
|
||||||
|
let versionSpec;
|
||||||
|
if (fullDepMatch) {
|
||||||
|
versionSpec = fullDepMatch[1];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
// Strip trailing backslash (line continuation)
|
||||||
|
versionSpec = versionSpec.replace(/\\$/, "").trim();
|
||||||
|
// Strip environment markers (everything after ';')
|
||||||
|
const match = versionSpec.match(/^([^;]+)(?:;.*)?$/);
|
||||||
if (match) {
|
if (match) {
|
||||||
core.info(`Found ruff version in requirements file: ${match[1]}`);
|
let version = match[1].trim();
|
||||||
return match[1];
|
if (version) {
|
||||||
|
// Strip leading '==' from exact version specifiers for compatibility with semver
|
||||||
|
if (version.startsWith("==")) {
|
||||||
|
version = version.slice(2);
|
||||||
|
}
|
||||||
|
if (trimmedSpec.includes(";")) {
|
||||||
|
core.warning("Environment markers are ignored. ruff is a standalone tool that works independently of Python version.");
|
||||||
|
}
|
||||||
|
core.info(`Found ruff version in requirements file: ${version}`);
|
||||||
|
return version;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
function getRuffVersionFromAllDependencies(allDependencies) {
|
||||||
|
return allDependencies
|
||||||
|
.map((dep) => findRuffVersionInSpec(dep))
|
||||||
|
.find((version) => version !== undefined);
|
||||||
|
}
|
||||||
function parsePyproject(pyprojectContent) {
|
function parsePyproject(pyprojectContent) {
|
||||||
const pyproject = toml.parse(pyprojectContent);
|
const pyproject = toml.parse(pyprojectContent);
|
||||||
const dependencies = pyproject?.project?.dependencies || [];
|
const dependencies = pyproject?.project?.dependencies || [];
|
||||||
@@ -32381,8 +32415,9 @@ function getRuffVersionFromPoetryGroups(pyproject) {
|
|||||||
return poetryGroups
|
return poetryGroups
|
||||||
.flatMap((group) => Object.entries(group.dependencies))
|
.flatMap((group) => Object.entries(group.dependencies))
|
||||||
.map(([name, spec]) => {
|
.map(([name, spec]) => {
|
||||||
if (name === "ruff" && typeof spec === "string")
|
if (typeof spec === "string") {
|
||||||
return spec;
|
return findRuffVersionInSpec(`${name} ${spec}`);
|
||||||
|
}
|
||||||
return undefined;
|
return undefined;
|
||||||
})
|
})
|
||||||
.find((version) => version !== undefined);
|
.find((version) => version !== undefined);
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
/** @type {import('ts-jest').JestConfigWithTsJest} */
|
||||||
|
module.exports = {
|
||||||
|
collectCoverageFrom: ["src/**/*.ts", "!src/**/*.d.ts"],
|
||||||
|
moduleFileExtensions: ["ts", "js"],
|
||||||
|
preset: "ts-jest",
|
||||||
|
roots: ["<rootDir>/src"],
|
||||||
|
testEnvironment: "node",
|
||||||
|
testMatch: ["**/*.test.ts"],
|
||||||
|
transform: {
|
||||||
|
"^.+\\.ts$": "ts-jest",
|
||||||
|
},
|
||||||
|
};
|
||||||
Generated
+3797
-10
File diff suppressed because it is too large
Load Diff
+12
-3
@@ -10,13 +10,19 @@
|
|||||||
"package": "ncc build -o dist/ruff-action src/ruff-action.ts && ncc build -o dist/update-known-checksums src/update-known-checksums.ts",
|
"package": "ncc build -o dist/ruff-action src/ruff-action.ts && ncc build -o dist/update-known-checksums src/update-known-checksums.ts",
|
||||||
"act": "act pull_request -W .github/workflows/test.yml --container-architecture linux/amd64 -s GITHUB_TOKEN=\"$(gh auth token)\"",
|
"act": "act pull_request -W .github/workflows/test.yml --container-architecture linux/amd64 -s GITHUB_TOKEN=\"$(gh auth token)\"",
|
||||||
"update-known-checksums": "RUNNER_TEMP=known_checksums node dist/update-known-checksums/index.js src/download/checksum/known-checksums.ts \"$(gh auth token)\"",
|
"update-known-checksums": "RUNNER_TEMP=known_checksums node dist/update-known-checksums/index.js src/download/checksum/known-checksums.ts \"$(gh auth token)\"",
|
||||||
"all": "npm ci --ignore-scripts && npm run build && npm run check && npm run package"
|
"test": "jest",
|
||||||
|
"all": "npm ci --ignore-scripts && npm run build && npm run check && npm run test && npm run package"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/astral-sh/ruff-action.git"
|
"url": "git+https://github.com/astral-sh/ruff-action.git"
|
||||||
},
|
},
|
||||||
"keywords": ["actions", "python", "ruff", "action"],
|
"keywords": [
|
||||||
|
"actions",
|
||||||
|
"python",
|
||||||
|
"ruff",
|
||||||
|
"action"
|
||||||
|
],
|
||||||
"author": "@eifinger",
|
"author": "@eifinger",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -26,16 +32,19 @@
|
|||||||
"@octokit/core": "^7.0.3",
|
"@octokit/core": "^7.0.3",
|
||||||
"@octokit/plugin-paginate-rest": "^13.1.1",
|
"@octokit/plugin-paginate-rest": "^13.1.1",
|
||||||
"@octokit/plugin-rest-endpoint-methods": "^16.0.0",
|
"@octokit/plugin-rest-endpoint-methods": "^16.0.0",
|
||||||
"@renovatebot/pep440": "^4.1.0",
|
"@renovatebot/pep440": "^4.2.1",
|
||||||
"smol-toml": "^1.4.1"
|
"smol-toml": "^1.4.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@biomejs/biome": "2.1.4",
|
"@biomejs/biome": "2.1.4",
|
||||||
|
"@types/jest": "^29.5.14",
|
||||||
"@types/js-yaml": "^4.0.9",
|
"@types/js-yaml": "^4.0.9",
|
||||||
"@types/node": "^24.2.1",
|
"@types/node": "^24.2.1",
|
||||||
"@types/semver": "^7.7.0",
|
"@types/semver": "^7.7.0",
|
||||||
"@vercel/ncc": "^0.38.3",
|
"@vercel/ncc": "^0.38.3",
|
||||||
|
"jest": "^29.7.0",
|
||||||
"js-yaml": "^4.1.0",
|
"js-yaml": "^4.1.0",
|
||||||
|
"ts-jest": "^29.2.5",
|
||||||
"typescript": "^5.9.2"
|
"typescript": "^5.9.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,188 @@
|
|||||||
|
import * as core from "@actions/core";
|
||||||
|
import { findRuffVersionInSpec } from "./pyproject";
|
||||||
|
|
||||||
|
jest.mock("@actions/core", () => ({
|
||||||
|
info: jest.fn(),
|
||||||
|
warning: jest.fn(),
|
||||||
|
}));
|
||||||
|
|
||||||
|
describe("findRuffVersionInSpec", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
jest.clearAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("ruff dependency strings", () => {
|
||||||
|
it("should extract version from 'ruff==0.9.3'", () => {
|
||||||
|
const result = findRuffVersionInSpec("ruff==0.9.3");
|
||||||
|
expect(result).toBe("0.9.3");
|
||||||
|
expect(core.info).toHaveBeenCalledWith(
|
||||||
|
"Found ruff version in requirements file: 0.9.3",
|
||||||
|
);
|
||||||
|
expect(core.warning).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should extract version from 'ruff>=0.14'", () => {
|
||||||
|
const result = findRuffVersionInSpec("ruff>=0.14");
|
||||||
|
expect(result).toBe(">=0.14");
|
||||||
|
expect(core.warning).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should extract version from 'ruff ~=1.0.0'", () => {
|
||||||
|
const result = findRuffVersionInSpec("ruff ~=1.0.0");
|
||||||
|
expect(result).toBe("~=1.0.0");
|
||||||
|
expect(core.warning).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should extract version from 'ruff>=0.14,<1.0'", () => {
|
||||||
|
const result = findRuffVersionInSpec("ruff>=0.14,<1.0");
|
||||||
|
expect(result).toBe(">=0.14,<1.0");
|
||||||
|
expect(core.warning).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should extract version from 'ruff>=0.14,<2.0,!=1.5.0'", () => {
|
||||||
|
const result = findRuffVersionInSpec("ruff>=0.14,<2.0,!=1.5.0");
|
||||||
|
expect(result).toBe(">=0.14,<2.0,!=1.5.0");
|
||||||
|
expect(core.warning).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return undefined for non-ruff dependency 'another-dep 0.1.6'", () => {
|
||||||
|
const result = findRuffVersionInSpec("another-dep 0.1.6");
|
||||||
|
expect(result).toBeUndefined();
|
||||||
|
expect(core.info).not.toHaveBeenCalled();
|
||||||
|
expect(core.warning).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return undefined for non-ruff dependency 'another-dep==0.1.6'", () => {
|
||||||
|
const result = findRuffVersionInSpec("another-dep==0.1.6");
|
||||||
|
expect(result).toBeUndefined();
|
||||||
|
expect(core.info).not.toHaveBeenCalled();
|
||||||
|
expect(core.warning).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should strip trailing backslash", () => {
|
||||||
|
const result = findRuffVersionInSpec("ruff==0.9.3 \\");
|
||||||
|
expect(result).toBe("0.9.3");
|
||||||
|
expect(core.info).toHaveBeenCalledWith(
|
||||||
|
"Found ruff version in requirements file: 0.9.3",
|
||||||
|
);
|
||||||
|
expect(core.warning).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should strip trailing backslash with whitespace", () => {
|
||||||
|
const result = findRuffVersionInSpec(" ruff==0.9.3 \\ ");
|
||||||
|
expect(result).toBe("0.9.3");
|
||||||
|
expect(core.warning).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("environment markers", () => {
|
||||||
|
it("should strip python_version environment marker", () => {
|
||||||
|
const result = findRuffVersionInSpec(
|
||||||
|
'ruff>=0.14 ; python_version >= "3.11"',
|
||||||
|
);
|
||||||
|
expect(result).toBe(">=0.14");
|
||||||
|
expect(core.info).toHaveBeenCalledWith(
|
||||||
|
"Found ruff version in requirements file: >=0.14",
|
||||||
|
);
|
||||||
|
expect(core.warning).toHaveBeenCalledWith(
|
||||||
|
"Environment markers are ignored. ruff is a standalone tool that works independently of Python version.",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should strip sys_platform environment marker", () => {
|
||||||
|
const result = findRuffVersionInSpec(
|
||||||
|
"ruff==0.9.3 ; sys_platform == 'linux'",
|
||||||
|
);
|
||||||
|
expect(result).toBe("0.9.3");
|
||||||
|
expect(core.warning).toHaveBeenCalledWith(
|
||||||
|
"Environment markers are ignored. ruff is a standalone tool that works independently of Python version.",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should strip multiple environment markers", () => {
|
||||||
|
const result = findRuffVersionInSpec(
|
||||||
|
'ruff>=0.14 ; python_version >= "3.11" and sys_platform == "linux"',
|
||||||
|
);
|
||||||
|
expect(result).toBe(">=0.14");
|
||||||
|
expect(core.warning).toHaveBeenCalledWith(
|
||||||
|
"Environment markers are ignored. ruff is a standalone tool that works independently of Python version.",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should handle environment markers with multiple constraints", () => {
|
||||||
|
const result = findRuffVersionInSpec(
|
||||||
|
'ruff>=0.14,<1.0 ; python_version >= "3.11"',
|
||||||
|
);
|
||||||
|
expect(result).toBe(">=0.14,<1.0");
|
||||||
|
expect(core.warning).toHaveBeenCalledWith(
|
||||||
|
"Environment markers are ignored. ruff is a standalone tool that works independently of Python version.",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("edge cases", () => {
|
||||||
|
it("should handle whitespace", () => {
|
||||||
|
const result = findRuffVersionInSpec(" ruff >=0.14 ");
|
||||||
|
expect(result).toBe(">=0.14");
|
||||||
|
expect(core.warning).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should handle whitespace with environment markers", () => {
|
||||||
|
const result = findRuffVersionInSpec(
|
||||||
|
" ruff >=0.14 ; python_version >= '3.11' ",
|
||||||
|
);
|
||||||
|
expect(result).toBe(">=0.14");
|
||||||
|
expect(core.warning).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return undefined for empty string", () => {
|
||||||
|
const result = findRuffVersionInSpec("");
|
||||||
|
expect(result).toBeUndefined();
|
||||||
|
expect(core.info).not.toHaveBeenCalled();
|
||||||
|
expect(core.warning).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return undefined for whitespace only", () => {
|
||||||
|
const result = findRuffVersionInSpec(" ");
|
||||||
|
expect(result).toBeUndefined();
|
||||||
|
expect(core.info).not.toHaveBeenCalled();
|
||||||
|
expect(core.warning).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return undefined for just semicolon", () => {
|
||||||
|
const result = findRuffVersionInSpec(";");
|
||||||
|
expect(result).toBeUndefined();
|
||||||
|
expect(core.info).not.toHaveBeenCalled();
|
||||||
|
expect(core.warning).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should handle exact example from issue #256", () => {
|
||||||
|
const result = findRuffVersionInSpec(
|
||||||
|
'ruff>=0.14 ; python_version >= "3.11"',
|
||||||
|
);
|
||||||
|
expect(result).toBe(">=0.14");
|
||||||
|
expect(core.info).toHaveBeenCalledWith(
|
||||||
|
"Found ruff version in requirements file: >=0.14",
|
||||||
|
);
|
||||||
|
expect(core.warning).toHaveBeenCalledWith(
|
||||||
|
"Environment markers are ignored. ruff is a standalone tool that works independently of Python version.",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should handle single-quoted environment markers", () => {
|
||||||
|
const result = findRuffVersionInSpec(
|
||||||
|
"ruff>=0.14 ; python_version >= '3.11'",
|
||||||
|
);
|
||||||
|
expect(result).toBe(">=0.14");
|
||||||
|
expect(core.warning).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should handle double-quoted environment markers", () => {
|
||||||
|
const result = findRuffVersionInSpec(
|
||||||
|
'ruff>=0.14 ; python_version >= "3.11"',
|
||||||
|
);
|
||||||
|
expect(result).toBe(">=0.14");
|
||||||
|
expect(core.warning).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
+48
-11
@@ -2,25 +2,60 @@ import * as fs from "node:fs";
|
|||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
import * as toml from "smol-toml";
|
import * as toml from "smol-toml";
|
||||||
|
|
||||||
function getRuffVersionFromAllDependencies(
|
/**
|
||||||
allDependencies: string[],
|
* Find ruff version in a dependency specification.
|
||||||
): string | undefined {
|
* Only handles strings that start with "ruff" (e.g., "ruff==0.9.3").
|
||||||
const ruffVersionDefinition = allDependencies.find((dep: string) =>
|
* Returns undefined for non-ruff dependencies.
|
||||||
dep.startsWith("ruff"),
|
* Strips environment markers (everything after ';').
|
||||||
);
|
* Strips leading '==' from exact version specifiers (PEP 440) for downstream compatibility.
|
||||||
|
*
|
||||||
|
* @internal This is exported for testing purposes only.
|
||||||
|
*/
|
||||||
|
export function findRuffVersionInSpec(spec: string): string | undefined {
|
||||||
|
const trimmedSpec = spec.trim();
|
||||||
|
|
||||||
if (ruffVersionDefinition) {
|
const fullDepMatch = trimmedSpec.match(/^ruff\s*(.+)$/);
|
||||||
const match = ruffVersionDefinition.trim().match(/^ruff\s*==\s*([^\s\\]+)/);
|
let versionSpec: string;
|
||||||
|
if (fullDepMatch) {
|
||||||
|
versionSpec = fullDepMatch[1];
|
||||||
|
} else {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Strip trailing backslash (line continuation)
|
||||||
|
versionSpec = versionSpec.replace(/\\$/, "").trim();
|
||||||
|
|
||||||
|
// Strip environment markers (everything after ';')
|
||||||
|
const match = versionSpec.match(/^([^;]+)(?:;.*)?$/);
|
||||||
|
|
||||||
if (match) {
|
if (match) {
|
||||||
core.info(`Found ruff version in requirements file: ${match[1]}`);
|
let version = match[1].trim();
|
||||||
return match[1];
|
if (version) {
|
||||||
|
// Strip leading '==' from exact version specifiers for compatibility with semver
|
||||||
|
if (version.startsWith("==")) {
|
||||||
|
version = version.slice(2);
|
||||||
|
}
|
||||||
|
if (trimmedSpec.includes(";")) {
|
||||||
|
core.warning(
|
||||||
|
"Environment markers are ignored. ruff is a standalone tool that works independently of Python version.",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
core.info(`Found ruff version in requirements file: ${version}`);
|
||||||
|
return version;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getRuffVersionFromAllDependencies(
|
||||||
|
allDependencies: string[],
|
||||||
|
): string | undefined {
|
||||||
|
return allDependencies
|
||||||
|
.map((dep) => findRuffVersionInSpec(dep))
|
||||||
|
.find((version) => version !== undefined);
|
||||||
|
}
|
||||||
|
|
||||||
interface Pyproject {
|
interface Pyproject {
|
||||||
project?: {
|
project?: {
|
||||||
dependencies?: string[];
|
dependencies?: string[];
|
||||||
@@ -66,7 +101,9 @@ function getRuffVersionFromPoetryGroups(
|
|||||||
return poetryGroups
|
return poetryGroups
|
||||||
.flatMap((group) => Object.entries(group.dependencies))
|
.flatMap((group) => Object.entries(group.dependencies))
|
||||||
.map(([name, spec]) => {
|
.map(([name, spec]) => {
|
||||||
if (name === "ruff" && typeof spec === "string") return spec;
|
if (typeof spec === "string") {
|
||||||
|
return findRuffVersionInSpec(`${name} ${spec}`);
|
||||||
|
}
|
||||||
return undefined;
|
return undefined;
|
||||||
})
|
})
|
||||||
.find((version) => version !== undefined);
|
.find((version) => version !== undefined);
|
||||||
|
|||||||
Reference in New Issue
Block a user