mirror of
https://code.forgejo.org/actions/setup-python
synced 2025-03-14 22:26:58 +01:00
feat: support reading mise.toml
This commit is contained in:
parent
19e4675e06
commit
86322ff86a
5 changed files with 70 additions and 4 deletions
35
.github/workflows/test-python.yml
vendored
35
.github/workflows/test-python.yml
vendored
|
@ -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 }}
|
||||
|
|
|
@ -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', () => {
|
||||
|
|
6
dist/setup/index.js
vendored
6
dist/setup/index.js
vendored
|
@ -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) {
|
||||
|
|
|
@ -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:
|
||||
|
@ -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.
|
||||
|
|
10
src/utils.ts
10
src/utils.ts
|
@ -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) {
|
||||
|
|
Loading…
Add table
Reference in a new issue