Skip to content

Commit 86322ff

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

File tree

5 files changed

+70
-4
lines changed

5 files changed

+70
-4
lines changed

.github/workflows/test-python.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,41 @@ jobs:
278278
with:
279279
python-version-file: .tool-versions
280280

281+
setup-versions-from-mise-toml-file:
282+
name: Setup ${{ matrix.python }} ${{ matrix.os }} mise.toml file
283+
runs-on: ${{ matrix.os }}
284+
strategy:
285+
fail-fast: false
286+
matrix:
287+
os:
288+
[
289+
macos-latest,
290+
windows-latest,
291+
ubuntu-20.04,
292+
ubuntu-22.04,
293+
macos-13,
294+
ubuntu-latest
295+
]
296+
python: [3.13.0, 3.14.0, 3.15.0]
297+
exclude:
298+
- os: windows-latest
299+
python: graalpy-24.1.2
300+
steps:
301+
- name: Checkout
302+
uses: actions/checkout@v4
303+
304+
- name: build-mise-toml-file ${{ matrix.python }}
305+
run: |
306+
echo '[tools]
307+
python = "${{ matrix.python }}"
308+
' > mise.toml
309+
310+
- name: setup-python using mise.toml ${{ matrix.python }}
311+
id: setup-python-mise-toml
312+
uses: ./
313+
with:
314+
python-version-file: mise.toml
315+
281316
setup-pre-release-version-from-manifest:
282317
name: Setup 3.14.0-alpha.1 ${{ matrix.os }}
283318
runs-on: ${{ matrix.os }}

__tests__/utils.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,18 @@ 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 filePath = path.join(tempDir, 'mise.toml');
225+
const pythonVersion = '3.8.0';
226+
const fileContent = `[tools]\npython = "${pythonVersion}"`;
227+
fs.writeFileSync(filePath, fileContent);
228+
expect(_fn(filePath)).toEqual([pythonVersion]);
229+
}
230+
);
219231
});
220232

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