This commit is contained in:
Nicolas Delaby 2025-03-17 15:43:56 +02:00 committed by GitHub
commit 1d08e8ff28
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 25 additions and 5 deletions

View file

@ -130,6 +130,18 @@ describe('Version from file test', () => {
expect(_fn(pythonVersionFilePath)).toEqual([pythonVersion]); expect(_fn(pythonVersionFilePath)).toEqual([pythonVersion]);
} }
); );
it.each([getVersionInputFromTomlFile, getVersionInputFromFile])(
'Version from poetry with explicit main group pyproject.toml test',
async _fn => {
await io.mkdirP(tempDir);
const pythonVersionFileName = 'pyproject.toml';
const pythonVersionFilePath = path.join(tempDir, pythonVersionFileName);
const pythonVersion = '>=3.7.0';
const pythonVersionFileContent = `[tool.poetry.group.main.dependencies]\npython = "${pythonVersion}"`;
fs.writeFileSync(pythonVersionFilePath, pythonVersionFileContent);
expect(_fn(pythonVersionFilePath)).toEqual([pythonVersion]);
}
);
it.each([getVersionInputFromTomlFile, getVersionInputFromFile])( it.each([getVersionInputFromTomlFile, getVersionInputFromFile])(
'Version undefined', 'Version undefined',
async _fn => { async _fn => {

View file

@ -239,15 +239,23 @@ export function getVersionInputFromTomlFile(versionFile: string): string[] {
if ('project' in pyprojectConfig) { if ('project' in pyprojectConfig) {
// standard project metadata (PEP 621) // standard project metadata (PEP 621)
keys = ['project', 'requires-python']; keys = [['project', 'requires-python']];
} else { } else {
// python poetry // python poetry
keys = ['tool', 'poetry', 'dependencies', 'python']; keys = [
// implicit group main
['tool', 'poetry', 'dependencies', 'python'],
// explicit group main
['tool', 'poetry', 'group', 'main', 'dependencies', 'python']
];
} }
const versions = []; const versions = [];
const version = extractValue(pyprojectConfig, keys); for (const key of keys) {
if (version !== undefined) { const version = extractValue(pyprojectConfig, key);
versions.push(version); if (version !== undefined) {
versions.push(version);
break;
}
} }
core.info(`Extracted ${versions} from ${versionFile}`); core.info(`Extracted ${versions} from ${versionFile}`);