Skip to content

Install multiple python versions #567

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

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fixing comments
  • Loading branch information
dmitry-shibanov committed Dec 15, 2022
commit 0130854fbce1e6e72eb4288a218c75f33c3401c3
13 changes: 9 additions & 4 deletions .github/workflows/test-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ jobs:
}
$pythonVersion
shell: pwsh
setup-python-multiple-versions:

setup-python-multiple-python-versions:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
Expand All @@ -207,13 +208,17 @@ jobs:
- name: Setup Python and check latest
uses: ./
with:
python-version: ${{ matrix.python-version }}
python-version: |
3.7
3.8
3.9
3.10
check-latest: true
- name: Validate version
run: |
$pythonVersion = (python --version)
if ("$pythonVersion" -NotMatch "${{ matrix.python-version }}"){
Write-Host "The current version is $pythonVersion; expected version is ${{ matrix.python-version }}"
if ("$pythonVersion" -NotMatch "3.10"){
Write-Host "The current version is $pythonVersion; expected version is 3.10"
exit 1
}
$pythonVersion
Expand Down
31 changes: 12 additions & 19 deletions dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66867,31 +66867,31 @@ function cacheDependencies(cache, pythonVersion) {
});
}
function resolveVersionInput() {
let version = core.getMultilineInput('python-version');
let versions = core.getMultilineInput('python-version');
let versionFile = core.getInput('python-version-file');
if (version.length && versionFile) {
if (versions.length && versionFile) {
core.warning('Both python-version and python-version-file inputs are specified, only python-version will be used.');
}
if (version.length) {
return version;
if (versions.length) {
return versions;
}
if (versionFile) {
if (!fs_1.default.existsSync(versionFile)) {
throw new Error(`The specified python version file at: ${versionFile} doesn't exist.`);
}
version = fs_1.default.readFileSync(versionFile, 'utf8');
const version = fs_1.default.readFileSync(versionFile, 'utf8');
core.info(`Resolved ${versionFile} as ${version}`);
return version;
return [version];
}
utils_1.logWarning("Neither 'python-version' nor 'python-version-file' inputs were supplied. Attempting to find '.python-version' file.");
versionFile = '.python-version';
if (fs_1.default.existsSync(versionFile)) {
version = fs_1.default.readFileSync(versionFile, 'utf8');
const version = fs_1.default.readFileSync(versionFile, 'utf8');
core.info(`Resolved ${versionFile} as ${version}`);
return version;
return [version];
}
utils_1.logWarning(`${versionFile} doesn't exist.`);
return version;
return versions;
}
function run() {
var _a;
Expand All @@ -66904,20 +66904,13 @@ function run() {
}
core.debug(`Python is expected to be installed into ${process.env['RUNNER_TOOL_CACHE']}`);
try {
let versions;
const resolvedVersionInput = resolveVersionInput();
const versions = resolveVersionInput();
const checkLatest = core.getBooleanInput('check-latest');
if (Array.isArray(resolvedVersionInput)) {
versions = resolvedVersionInput;
}
else {
versions = [resolvedVersionInput];
}
if (versions.length) {
let pythonVersion = '';
const arch = core.getInput('architecture') || os.arch();
const updateEnvironment = core.getBooleanInput('update-environment');
for (const version of versions) {
const arch = core.getInput('architecture') || os.arch();
const updateEnvironment = core.getBooleanInput('update-environment');
if (isPyPyVersion(version)) {
const installed = yield finderPyPy.findPyPyVersion(version, arch, updateEnvironment, checkLatest);
pythonVersion = `${installed.resolvedPyPyVersion}-${installed.resolvedPythonVersion}`;
Expand Down
57 changes: 57 additions & 0 deletions docs/advanced-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
- [Using the python-version input](advanced-usage.md#using-the-python-version-input)
- [Specifying a Python version](advanced-usage.md#specifying-a-python-version)
- [Specifying a PyPy version](advanced-usage.md#specifying-a-pypy-version)
- [Specifying multiple Python and PyPy versions](advanced-usage.md#specifying-multiple-python/pypy-version)
- [Matrix Testing](advanced-usage.md#matrix-testing)
- [Using the python-version-file input](advanced-usage.md#using-the-python-version-file-input)
- [Check latest version](advanced-usage.md#check-latest-version)
Expand Down Expand Up @@ -132,6 +133,62 @@ jobs:
```
More details on PyPy syntax can be found in the [Available versions of PyPy](#pypy) section.

### Specifying multiple Python/PyPy version
The python-version input can get multiple python/pypy versions. The last specified version will be used as a default one.

Download and set up multiple Python versions:

```yaml
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: |
3.8
3.9
3.10
- run: python my_script.py
```

Download and set up multiple PyPy versions:

```yaml
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: |
pypy-3.7-v7.3.x
pypy3.9-nightly
pypy3.8
- run: python my_script.py
```

Download and set up multiple Python/PyPy versions:

```yaml
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: |
3.8
3.9
pypy3.9-nightly
pypy3.8
3.10
- run: python my_script.py
```

### Matrix Testing

Using `setup-python` it's possible to use [matrix syntax](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstrategymatrix) to install several versions of Python or PyPy:
Expand Down
33 changes: 13 additions & 20 deletions src/setup-python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ async function cacheDependencies(cache: string, pythonVersion: string) {
await cacheDistributor.restoreCache();
}

function resolveVersionInput(): string | string[] {
let version: string | string[] = core.getMultilineInput('python-version');
function resolveVersionInput() {
let versions = core.getMultilineInput('python-version');
let versionFile = core.getInput('python-version-file');

if (version.length && versionFile) {
if (versions.length && versionFile) {
core.warning(
'Both python-version and python-version-file inputs are specified, only python-version will be used.'
);
}

if (version.length) {
return version;
if (versions.length) {
return versions;
}

if (versionFile) {
Expand All @@ -42,24 +42,24 @@ function resolveVersionInput(): string | string[] {
`The specified python version file at: ${versionFile} doesn't exist.`
);
}
version = fs.readFileSync(versionFile, 'utf8');
const version = fs.readFileSync(versionFile, 'utf8');
core.info(`Resolved ${versionFile} as ${version}`);
return version;
return [version];
}

logWarning(
"Neither 'python-version' nor 'python-version-file' inputs were supplied. Attempting to find '.python-version' file."
);
versionFile = '.python-version';
if (fs.existsSync(versionFile)) {
version = fs.readFileSync(versionFile, 'utf8');
const version = fs.readFileSync(versionFile, 'utf8');
core.info(`Resolved ${versionFile} as ${version}`);
return version;
return [version];
}

logWarning(`${versionFile} doesn't exist.`);

return version;
return versions;
}

async function run() {
Expand All @@ -75,21 +75,14 @@ async function run() {
`Python is expected to be installed into ${process.env['RUNNER_TOOL_CACHE']}`
);
try {
let versions: string[];
const resolvedVersionInput = resolveVersionInput();
const versions = resolveVersionInput();
const checkLatest = core.getBooleanInput('check-latest');

if (Array.isArray(resolvedVersionInput)) {
versions = resolvedVersionInput as string[];
} else {
versions = [resolvedVersionInput as string];
}

if (versions.length) {
let pythonVersion = '';
const arch: string = core.getInput('architecture') || os.arch();
const updateEnvironment = core.getBooleanInput('update-environment');
for (const version of versions) {
const arch: string = core.getInput('architecture') || os.arch();
const updateEnvironment = core.getBooleanInput('update-environment');
if (isPyPyVersion(version)) {
const installed = await finderPyPy.findPyPyVersion(
version,
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy