Skip to content

Commit dc748d3

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

File tree

4 files changed

+36
-4
lines changed

4 files changed

+36
-4
lines changed

__tests__/utils.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,19 @@ describe('Version from file test', () => {
216216
expect(_fn(toolVersionFilePath)).toEqual(['3.14t-dev']);
217217
}
218218
);
219+
220+
it.each([getVersionInputFromTomlFile, getVersionInputFromFile])(
221+
'Version from mise.toml',
222+
async _fn => {
223+
await io.mkdirP(tempDir);
224+
const fileName = 'mise.toml';
225+
const filePath = path.join(tempDir, fileName);
226+
const pythonVersion = '3.8.0';
227+
const fileContent = `[tools]\npython = "${pythonVersion}"`;
228+
fs.writeFileSync(filePath, fileContent);
229+
expect(_fn(filePath)).toEqual([pythonVersion]);
230+
}
231+
);
219232
});
220233

221234
describe('getNextPageUrl', () => {

dist/setup/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100726,10 +100726,14 @@ function getVersionInputFromTomlFile(versionFile) {
100726100726
// standard project metadata (PEP 621)
100727100727
keys = ['project', 'requires-python'];
100728100728
}
100729-
else {
100729+
else if ('tool' in pyprojectConfig) {
100730100730
// python poetry
100731100731
keys = ['tool', 'poetry', 'dependencies', 'python'];
100732100732
}
100733+
else if ('tools' in pyprojectConfig) {
100734+
// mise
100735+
keys = ['tools', 'python'];
100736+
}
100733100737
const versions = [];
100734100738
const version = extractValue(pyprojectConfig, keys);
100735100739
if (version !== undefined) {

docs/advanced-usage.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ jobs:
280280

281281
`setup-python` action can read Python or PyPy version from a version file. `python-version-file` input is used for specifying the path to the version file. If the file that was supplied to `python-version-file` input doesn't exist, the action will fail with error.
282282

283-
>In case both `python-version` and `python-version-file` inputs are supplied, the `python-version-file` input will be ignored due to its lower priority. The .tool-versions file supports version specifications in accordance with asdf standards, adhering to Semantic Versioning ([semver](https://semver.org)).
283+
>In case both `python-version` and `python-version-file` inputs are supplied, the `python-version-file` input will be ignored due to its lower priority. The .tool-versions file supports version specifications in accordance with asdf standards, adhering to Semantic Versioning ([semver](https://semver.org)). The `mise.toml` file supports version specifications in accordance with [mise](https://mise.jdx.dev/configuration.html) standards.
284284

285285
```yaml
286286
steps:
@@ -309,6 +309,15 @@ steps:
309309
- run: python my_script.py
310310
```
311311

312+
```yaml
313+
steps:
314+
- uses: actions/checkout@v4
315+
- uses: actions/setup-python@v5
316+
with:
317+
python-version-file: 'mise.toml' # Read python version from a file mise.toml
318+
- run: python my_script.py
319+
```
320+
312321
## Check latest version
313322

314323
The `check-latest` flag defaults to `false`. Use the default or set `check-latest` to `false` if you prefer stability and if you want to ensure a specific `Python or PyPy` version is always used.

src/utils.ts

Lines changed: 8 additions & 2 deletions
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

237237
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)