Skip to content

Commit 3a78503

Browse files
committed
Support reading python version from mise config
1 parent 9a7ac94 commit 3a78503

File tree

3 files changed

+41
-14
lines changed

3 files changed

+41
-14
lines changed

__tests__/utils.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,18 @@ describe('Version from file test', () => {
126126
expect(_fn(pythonVersionFilePath)).toEqual([pythonVersion]);
127127
}
128128
);
129+
it.each([getVersionInputFromTomlFile, getVersionInputFromFile])(
130+
'Version from mise .mise.toml test',
131+
async _fn => {
132+
await io.mkdirP(tempDir);
133+
const pythonVersionFileName = '.mise.toml';
134+
const pythonVersionFilePath = path.join(tempDir, pythonVersionFileName);
135+
const pythonVersion = '3.7.0';
136+
const pythonVersionFileContent = `[tools]\npython = "${pythonVersion}"`;
137+
fs.writeFileSync(pythonVersionFilePath, pythonVersionFileContent);
138+
expect(_fn(pythonVersionFilePath)).toEqual([pythonVersion]);
139+
}
140+
);
129141
it.each([getVersionInputFromTomlFile, getVersionInputFromFile])(
130142
'Version undefined',
131143
async _fn => {

dist/setup/index.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91859,19 +91859,25 @@ function getVersionInputFromTomlFile(versionFile) {
9185991859
core.debug(`Trying to resolve version form ${versionFile}`);
9186091860
const pyprojectFile = fs_1.default.readFileSync(versionFile, 'utf8');
9186191861
const pyprojectConfig = toml.parse(pyprojectFile);
91862-
let keys = [];
91862+
let keyPaths = [];
9186391863
if ('project' in pyprojectConfig) {
9186491864
// standard project metadata (PEP 621)
91865-
keys = ['project', 'requires-python'];
91865+
keyPaths = [['project', 'requires-python']];
9186691866
}
9186791867
else {
91868-
// python poetry
91869-
keys = ['tool', 'poetry', 'dependencies', 'python'];
91868+
keyPaths = [
91869+
// python poetry
91870+
['tool', 'poetry', 'dependencies', 'python'],
91871+
// mise
91872+
['tools', 'python']
91873+
];
9187091874
}
9187191875
const versions = [];
91872-
const version = extractValue(pyprojectConfig, keys);
91873-
if (version !== undefined) {
91874-
versions.push(version);
91876+
for (const keys of keyPaths) {
91877+
const value = extractValue(pyprojectConfig, keys);
91878+
if (value !== undefined) {
91879+
versions.push(value);
91880+
}
9187591881
}
9187691882
core.info(`Extracted ${versions} from ${versionFile}`);
9187791883
const rawVersions = Array.from(versions, version => version.split(',').join(' '));

src/utils.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -226,19 +226,28 @@ export function getVersionInputFromTomlFile(versionFile: string): string[] {
226226

227227
const pyprojectFile = fs.readFileSync(versionFile, 'utf8');
228228
const pyprojectConfig = toml.parse(pyprojectFile);
229-
let keys = [];
229+
230+
let keyPaths = [];
230231

231232
if ('project' in pyprojectConfig) {
232233
// standard project metadata (PEP 621)
233-
keys = ['project', 'requires-python'];
234+
keyPaths = [['project', 'requires-python']];
234235
} else {
235-
// python poetry
236-
keys = ['tool', 'poetry', 'dependencies', 'python'];
236+
keyPaths = [
237+
// python poetry
238+
['tool', 'poetry', 'dependencies', 'python'],
239+
// mise
240+
['tools', 'python']
241+
];
237242
}
243+
238244
const versions = [];
239-
const version = extractValue(pyprojectConfig, keys);
240-
if (version !== undefined) {
241-
versions.push(version);
245+
246+
for (const keys of keyPaths) {
247+
const value = extractValue(pyprojectConfig, keys);
248+
if (value !== undefined) {
249+
versions.push(value);
250+
}
242251
}
243252

244253
core.info(`Extracted ${versions} from ${versionFile}`);

0 commit comments

Comments
 (0)