8000 feat: support reading mise.toml · actions/setup-python@d3afba6 · GitHub
[go: up one dir, main page]

Skip to content

Commit d3afba6

Browse files
committed
feat: support reading mise.toml
1 parent 19e4675 commit d3afba6

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

__tests__/data/mise.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[tools]
2+
python = "3.8.0"

__tests__/utils.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,18 @@ describe('Version from file test', () => {
130130
expect(_fn(pythonVersionFilePath)).toEqual([pythonVersion]);
131131
}
132132
);
133+
it.each([getVersionInputFromTomlFile, getVersionInputFromFile])(
134+
'Version from mise mise.tml test',
135+
async _fn => {
136+
await io.mkdirP(tempDir);
137+
const pythonVersionFileName = 'mise.toml';
138+
const pythonVersionFilePath = path.join(tempDir, pythonVersionFileName);
139+
const pythonVersion = '3.8.0';
140+
const pythonVersionFileContent = `[tools]\npython = "${pythonVersion}"`;
141+
fs.writeFileSync(pythonVersionFilePath, pythonVersionFileContent);
142+
expect(_fn(pythonVersionFilePath)).toEqual([pythonVersion]);
143+
}
144+
);
133145
it.each([getVersionInputFromTomlFile, getVersionInputFromFile])(
134146
'Version undefined',
135147
async _fn => {

src/utils.ts

Lines changed: 8 additions & 2 deletions
237
Original file line numberDiff line numberDiff line change
@@ -235,15 +235,21 @@ export function getVersionInputFromTomlFile(versionFile: string): string[] {
235235
pyprojectFile = pyprojectFile.replace(/\r\n/g, '\n');
236236

237
const pyprojectConfig = toml.parse(pyprojectFile);
238-
let keys = [];
238+
let keys: string[] = [];
239239

240240
if ('project' in pyprojectConfig) {
241241
// standard project metadata (PEP 621)
242242
keys = ['project', 'requires-python'];
243-
} else {
243+
}
244+
else if ('tool' in pyprojectConfig) {
244245
// python poetry
245246
keys = ['tool', 'poetry', 'dependencies', 'python'];
246247
}
248+
else if ('tools' in pyprojectConfig){
249+
// mise
250+
keys = ['tools', 'python']
251+
}
252+
247253
const versions = [];
248254
const version = extractValue(pyprojectConfig, keys);
249255
if (version !== undefined) {

0 commit comments

Comments
 (0)
0