mirror of
https://github.com/actions/setup-python.git
synced 2025-06-28 05:33:47 +00:00
Support reading python version from mise config
This commit is contained in:
parent
29a37be0a3
commit
9e32ee01fa
3 changed files with 69 additions and 16 deletions
29
dist/setup/index.js
vendored
29
dist/setup/index.js
vendored
|
@ -92090,6 +92090,9 @@ function getOSInfo() {
|
|||
});
|
||||
}
|
||||
exports.getOSInfo = getOSInfo;
|
||||
function isString(value) {
|
||||
return typeof value === 'string' || value instanceof String;
|
||||
}
|
||||
/**
|
||||
* Extract a value from an object by following the keys path provided.
|
||||
* If the value is present, it is returned. Otherwise undefined is returned.
|
||||
|
@ -92100,9 +92103,12 @@ function extractValue(obj, keys) {
|
|||
if (keys.length > 1 && value !== undefined) {
|
||||
return extractValue(value, keys.slice(1));
|
||||
}
|
||||
else {
|
||||
else if (isString(value)) {
|
||||
return value;
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return;
|
||||
|
@ -92122,19 +92128,26 @@ function getVersionInputFromTomlFile(versionFile) {
|
|||
// Normalize the line endings in the pyprojectFile
|
||||
pyprojectFile = pyprojectFile.replace(/\r\n/g, '\n');
|
||||
const pyprojectConfig = toml.parse(pyprojectFile);
|
||||
let keys = [];
|
||||
let keyPaths = [];
|
||||
if ('project' in pyprojectConfig) {
|
||||
// standard project metadata (PEP 621)
|
||||
keys = ['project', 'requires-python'];
|
||||
keyPaths = [['project', 'requires-python']];
|
||||
}
|
||||
else {
|
||||
// python poetry
|
||||
keys = ['tool', 'poetry', 'dependencies', 'python'];
|
||||
keyPaths = [
|
||||
// python poetry
|
||||
['tool', 'poetry', 'dependencies', 'python'],
|
||||
// mise
|
||||
['tools', 'python'],
|
||||
['tools', 'python', 'version']
|
||||
];
|
||||
}
|
||||
const versions = [];
|
||||
const version = extractValue(pyprojectConfig, keys);
|
||||
if (version !== undefined) {
|
||||
versions.push(version);
|
||||
for (const keys of keyPaths) {
|
||||
const value = extractValue(pyprojectConfig, keys);
|
||||
if (value !== undefined) {
|
||||
versions.push(value);
|
||||
}
|
||||
}
|
||||
core.info(`Extracted ${versions} from ${versionFile}`);
|
||||
const rawVersions = Array.from(versions, version => version.split(',').join(' '));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue