Support requirements.txt for version-file (#68)

This commit is contained in:
Dave Johansen
2025-02-06 09:41:44 -07:00
committed by GitHub
parent f173943ec8
commit d8f577dec4
5 changed files with 91 additions and 62 deletions
Generated Vendored
+28 -21
View File
@@ -30735,27 +30735,7 @@ exports.getRuffVersionFromPyproject = getRuffVersionFromPyproject;
const fs = __importStar(__nccwpck_require__(3024));
const core = __importStar(__nccwpck_require__(7484));
const toml = __importStar(__nccwpck_require__(7106));
function getRuffVersionFromPyproject(filePath) {
if (!fs.existsSync(filePath)) {
core.warning(`Could not find file: ${filePath}`);
return undefined;
}
const pyprojectContent = fs.readFileSync(filePath, "utf-8");
let pyproject;
try {
pyproject = toml.parse(pyprojectContent);
}
catch (err) {
const message = err.message;
core.warning(`Error while parsing ${filePath}: ${message}`);
return undefined;
}
const dependencies = pyproject?.project?.dependencies || [];
const optionalDependencies = Object.values(pyproject?.project?.["optional-dependencies"] || {}).flat();
const devDependencies = Object.values(pyproject?.["dependency-groups"] || {})
.flat()
.filter((item) => typeof item === "string");
const allDependencies = dependencies.concat(optionalDependencies, devDependencies);
function parseRequirements(allDependencies) {
const ruffVersionDefinition = allDependencies.find((dep) => dep.startsWith("ruff"));
if (ruffVersionDefinition) {
const ruffVersion = ruffVersionDefinition
@@ -30769,6 +30749,33 @@ function getRuffVersionFromPyproject(filePath) {
}
return undefined;
}
function parsePyproject(pyprojectContent) {
const pyproject = toml.parse(pyprojectContent);
const dependencies = pyproject?.project?.dependencies || [];
const optionalDependencies = Object.values(pyproject?.project?.["optional-dependencies"] || {}).flat();
const devDependencies = Object.values(pyproject?.["dependency-groups"] || {})
.flat()
.filter((item) => typeof item === "string");
return parseRequirements(dependencies.concat(optionalDependencies, devDependencies));
}
function getRuffVersionFromPyproject(filePath) {
if (!fs.existsSync(filePath)) {
core.warning(`Could not find file: ${filePath}`);
return undefined;
}
const pyprojectContent = fs.readFileSync(filePath, "utf-8");
if (filePath.endsWith(".txt")) {
return parseRequirements(pyprojectContent.split("\n"));
}
try {
return parsePyproject(pyprojectContent);
}
catch (err) {
const message = err.message;
core.warning(`Error while parsing ${filePath}: ${message}`);
return undefined;
}
}
/***/ }),