Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: support reading version from mise.toml #1051

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/test-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,41 @@ jobs:
with:
python-version-file: .tool-versions

setup-versions-from-mise-toml-file:
name: Setup ${{ matrix.python }} ${{ matrix.os }} mise.toml file
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
[
macos-latest,
windows-latest,
ubuntu-20.04,
ubuntu-22.04,
macos-13,
ubuntu-latest
]
python: [3.13.0, 3.14.0, 3.15.0]
exclude:
- os: windows-latest
python: graalpy-24.1.2
steps:
- name: Checkout
uses: actions/checkout@v4

- name: build-mise-toml-file ${{ matrix.python }}
run: |
echo '[tools]
python = "${{ matrix.python }}"
' > mise.toml

- name: setup-python using mise.toml ${{ matrix.python }}
id: setup-python-mise-toml
uses: ./
with:
python-version-file: mise.toml

setup-pre-release-version-from-manifest:
name: Setup 3.14.0-alpha.1 ${{ matrix.os }}
runs-on: ${{ matrix.os }}
Expand Down
12 changes: 12 additions & 0 deletions __tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,18 @@ describe('Version from file test', () => {
expect(_fn(toolVersionFilePath)).toEqual(['3.14t-dev']);
}
);

it.each([getVersionInputFromTomlFile, getVersionInputFromFile])(
'Version from mise.toml',
async _fn => {
await io.mkdirP(tempDir);
const filePath = path.join(tempDir, 'mise.toml');
const pythonVersion = '3.8.0';
const fileContent = `[tools]\npython = "${pythonVersion}"`;
fs.writeFileSync(filePath, fileContent);
expect(_fn(filePath)).toEqual([pythonVersion]);
}
);
});

describe('getNextPageUrl', () => {
Expand Down
6 changes: 5 additions & 1 deletion dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -100726,10 +100726,14 @@ function getVersionInputFromTomlFile(versionFile) {
// standard project metadata (PEP 621)
keys = ['project', 'requires-python'];
}
else {
else if ('tool' in pyprojectConfig) {
// python poetry
keys = ['tool', 'poetry', 'dependencies', 'python'];
}
else if ('tools' in pyprojectConfig) {
// mise
keys = ['tools', 'python'];
}
const versions = [];
const version = extractValue(pyprojectConfig, keys);
if (version !== undefined) {
Expand Down
11 changes: 10 additions & 1 deletion docs/advanced-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ jobs:

`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.

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

```yaml
steps:
Expand Down Expand Up @@ -309,6 +309,15 @@ steps:
- run: python my_script.py
```

```yaml
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version-file: 'mise.toml' # Read python version from a file mise.toml
- run: python my_script.py
```

## Check latest version

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.
Expand Down
10 changes: 8 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,15 +235,21 @@ export function getVersionInputFromTomlFile(versionFile: string): string[] {
pyprojectFile = pyprojectFile.replace(/\r\n/g, '\n');

const pyprojectConfig = toml.parse(pyprojectFile);
let keys = [];
let keys: string[] = [];

if ('project' in pyprojectConfig) {
// standard project metadata (PEP 621)
keys = ['project', 'requires-python'];
} else {
}
else if ('tool' in pyprojectConfig) {
// python poetry
keys = ['tool', 'poetry', 'dependencies', 'python'];
}
else if ('tools' in pyprojectConfig){
// mise
keys = ['tools', 'python']
}

const versions = [];
const version = extractValue(pyprojectConfig, keys);
if (version !== undefined) {
Expand Down