mirror of
https://github.com/actions/setup-python.git
synced 2025-06-25 05:01:09 +02:00
Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
41b7212b16 | |||
878156f1de |
40
README.md
40
README.md
@ -6,17 +6,17 @@
|
|||||||
|
|
||||||
This action sets up a Python environment for use in actions by:
|
This action sets up a Python environment for use in actions by:
|
||||||
|
|
||||||
- optionally installing and adding to PATH a version of Python that is already installed in the tools cache
|
- optionally installing and adding to PATH a version of Python that is already installed in the tools cache.
|
||||||
- downloading, installing and adding to PATH an available version of Python from GitHub Releases ([actions/python-versions](https://github.com/actions/python-versions/releases)) if a specific version is not available in the tools cache
|
- downloading, installing and adding to PATH an available version of Python from GitHub Releases ([actions/python-versions](https://github.com/actions/python-versions/releases)) if a specific version is not available in the tools cache.
|
||||||
- failing if a specific version of Python is not preinstalled or available for download
|
- failing if a specific version of Python is not preinstalled or available for download.
|
||||||
- registering problem matchers for error output
|
- registering problem matchers for error output.
|
||||||
|
|
||||||
# What's new
|
# What's new
|
||||||
|
|
||||||
- Ability to download, install and set up Python packages from `actions/python-versions` that do not come preinstalled on runners
|
- Ability to download, install and set up Python packages from `actions/python-versions` that do not come preinstalled on runners.
|
||||||
- Allows for pinning to a specific patch version of Python without the worry of it ever being removed or changed
|
- Allows for pinning to a specific patch version of Python without the worry of it ever being removed or changed.
|
||||||
- Automatic setup and download of Python packages if using a self-hosted runner
|
- Automatic setup and download of Python packages if using a self-hosted runner.
|
||||||
- Support for pre-release versions of Python
|
- Support for pre-release versions of Python.
|
||||||
|
|
||||||
# Usage
|
# Usage
|
||||||
|
|
||||||
@ -122,14 +122,14 @@ Check out our detailed guide on using [Python with GitHub Actions](https://help.
|
|||||||
|
|
||||||
`setup-python` is able to configure Python from two sources:
|
`setup-python` is able to configure Python from two sources:
|
||||||
|
|
||||||
- Preinstalled versions of Python in the tools cache on GitHub-hosted runners
|
- Preinstalled versions of Python in the tools cache on GitHub-hosted runners.
|
||||||
- For detailed information regarding the available versions of Python that are installed see [Supported software](https://docs.github.com/en/actions/reference/specifications-for-github-hosted-runners#supported-software).
|
- For detailed information regarding the available versions of Python that are installed see [Supported software](https://docs.github.com/en/actions/reference/specifications-for-github-hosted-runners#supported-software).
|
||||||
- For every minor version of Python, expect only the latest patch to be preinstalled.
|
- For every minor version of Python, expect only the latest patch to be preinstalled.
|
||||||
- If `3.8.1` is installed for example, and `3.8.2` is released, expect `3.8.1` to be removed and replaced by `3.8.2` in the tools cache.
|
- If `3.8.1` is installed for example, and `3.8.2` is released, expect `3.8.1` to be removed and replaced by `3.8.2` in the tools cache.
|
||||||
- If the exact patch version doesn't matter to you, specifying just the major and minor version will get you the latest preinstalled patch version. In the previous example, the version spec `3.8` will use the `3.8.2` Python version found in the cache.
|
- If the exact patch version doesn't matter to you, specifying just the major and minor version will get you the latest preinstalled patch version. In the previous example, the version spec `3.8` will use the `3.8.2` Python version found in the cache.
|
||||||
- Downloadable Python versions from GitHub Releases ([actions/python-versions](https://github.com/actions/python-versions/releases))
|
- Downloadable Python versions from GitHub Releases ([actions/python-versions](https://github.com/actions/python-versions/releases)).
|
||||||
- All available versions are listed in the [version-manifest.json](https://github.com/actions/python-versions/blob/main/versions-manifest.json) file.
|
- All available versions are listed in the [version-manifest.json](https://github.com/actions/python-versions/blob/main/versions-manifest.json) file.
|
||||||
- If there is a specific version of Python that is not available, you can open an issue here
|
- If there is a specific version of Python that is not available, you can open an issue here.
|
||||||
|
|
||||||
# Hosted Tool Cache
|
# Hosted Tool Cache
|
||||||
|
|
||||||
@ -174,22 +174,22 @@ If you are experiencing problems while configuring Python on your self-hosted ru
|
|||||||
|
|
||||||
- The Python packages that are downloaded from `actions/python-versions` are originally compiled from source in `/opt/hostedtoolcache/` with the [--enable-shared](https://github.com/actions/python-versions/blob/94f04ae6806c6633c82db94c6406a16e17decd5c/builders/ubuntu-python-builder.psm1#L35) flag, which makes them non-relocatable.
|
- The Python packages that are downloaded from `actions/python-versions` are originally compiled from source in `/opt/hostedtoolcache/` with the [--enable-shared](https://github.com/actions/python-versions/blob/94f04ae6806c6633c82db94c6406a16e17decd5c/builders/ubuntu-python-builder.psm1#L35) flag, which makes them non-relocatable.
|
||||||
- Create an environment variable called `AGENT_TOOLSDIRECTORY` and set it to `/opt/hostedtoolcache`. This controls where the runner downloads and installs tools.
|
- Create an environment variable called `AGENT_TOOLSDIRECTORY` and set it to `/opt/hostedtoolcache`. This controls where the runner downloads and installs tools.
|
||||||
- In the same shell that your runner is using, type `export AGENT_TOOLSDIRECTORY=/opt/hostedtoolcache`
|
- In the same shell that your runner is using, type `export AGENT_TOOLSDIRECTORY=/opt/hostedtoolcache`.
|
||||||
- A more permanent way of setting the environment variable is to create a `.env` file in the same directory as your runner and to add `AGENT_TOOLSDIRECTORY=/opt/hostedtoolcache`. This ensures the variable is always set if your runner is configured as a service.
|
- A more permanent way of setting the environment variable is to create a `.env` file in the same directory as your runner and to add `AGENT_TOOLSDIRECTORY=/opt/hostedtoolcache`. This ensures the variable is always set if your runner is configured as a service.
|
||||||
- Create a directory called `hostedtoolcache` inside `/opt`.
|
- Create a directory called `hostedtoolcache` inside `/opt`.
|
||||||
- The user starting the runner must have write permission to the `/opt/hostedtoolcache` directory. It is not possible to start the Linux runner with `sudo` and the `/opt` directory usually requires root privileges to write to. Check the current user and group that the runner belongs to by typing `ls -l` inside the runners root directory.
|
- The user starting the runner must have write permission to the `/opt/hostedtoolcache` directory. It is not possible to start the Linux runner with `sudo` and the `/opt` directory usually requires root privileges to write to. Check the current user and group that the runner belongs to by typing `ls -l` inside the runners root directory.
|
||||||
- The runner can be granted write access to the `/opt/hostedtoolcache` directory using a few techniques:
|
- The runner can be granted write access to the `/opt/hostedtoolcache` directory using a few techniques:
|
||||||
- The user starting the runner is the owner, and the owner has write permission
|
- The user starting the runner is the owner, and the owner has write permission.
|
||||||
- The user starting the runner is in the owning group, and the owning group has write permission
|
- The user starting the runner is in the owning group, and the owning group has write permission.
|
||||||
- All users have write permission
|
- All users have write permission.
|
||||||
- One quick way to grant access is to change the user and group of `/opt/hostedtoolcache` to be the same as the runners using `chown`
|
- One quick way to grant access is to change the user and group of `/opt/hostedtoolcache` to be the same as the runners using `chown`.
|
||||||
- `sudo chown runner-user:runner-group opt/hostedtoolcache/`
|
- `sudo chown runner-user:runner-group opt/hostedtoolcache/`.
|
||||||
- If your runner is configured as a service and you run into problems, make sure the user that the service is running as is correct. For more information, you can [check the status of your self-hosted runner](https://help.github.com/en/actions/hosting-your-own-runners/configuring-the-self-hosted-runner-application-as-a-service#checking-the-status-of-the-service).
|
- If your runner is configured as a service and you run into problems, make sure the user that the service is running as is correct. For more information, you can [check the status of your self-hosted runner](https://help.github.com/en/actions/hosting-your-own-runners/configuring-the-self-hosted-runner-application-as-a-service#checking-the-status-of-the-service).
|
||||||
|
|
||||||
### Mac
|
### Mac
|
||||||
|
|
||||||
- The same setup that applies to `Linux` also applies to `Mac`, just with a different tools cache directory.
|
- The same setup that applies to `Linux` also applies to `Mac`, just with a different tools cache directory.
|
||||||
- Create a directory called `/Users/runner/hostedtoolcache`
|
- Create a directory called `/Users/runner/hostedtoolcache`.
|
||||||
- Set the `AGENT_TOOLSDIRECTORY` environment variable to `/Users/runner/hostedtoolcache`.
|
- Set the `AGENT_TOOLSDIRECTORY` environment variable to `/Users/runner/hostedtoolcache`.
|
||||||
- Change the permissions of `/Users/runner/hostedtoolcache` so that the runner has write access.
|
- Change the permissions of `/Users/runner/hostedtoolcache` so that the runner has write access.
|
||||||
|
|
||||||
@ -200,8 +200,8 @@ If you are experiencing problems while configuring Python on your self-hosted ru
|
|||||||
|
|
||||||
# License
|
# License
|
||||||
|
|
||||||
The scripts and documentation in this project are released under the [MIT License](LICENSE)
|
The scripts and documentation in this project are released under the [MIT License](LICENSE).
|
||||||
|
|
||||||
# Contributions
|
# Contributions
|
||||||
|
|
||||||
Contributions are welcome! See our [Contributor's Guide](docs/contributors.md)
|
Contributions are welcome! See our [Contributor's Guide](docs/contributors.md).
|
||||||
|
11
dist/index.js
vendored
11
dist/index.js
vendored
@ -6422,6 +6422,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
const path = __importStar(__webpack_require__(622));
|
||||||
const core = __importStar(__webpack_require__(470));
|
const core = __importStar(__webpack_require__(470));
|
||||||
const tc = __importStar(__webpack_require__(533));
|
const tc = __importStar(__webpack_require__(533));
|
||||||
const exec = __importStar(__webpack_require__(986));
|
const exec = __importStar(__webpack_require__(986));
|
||||||
@ -6432,6 +6433,7 @@ const MANIFEST_REPO_NAME = 'python-versions';
|
|||||||
const MANIFEST_REPO_BRANCH = 'main';
|
const MANIFEST_REPO_BRANCH = 'main';
|
||||||
exports.MANIFEST_URL = `https://raw.githubusercontent.com/${MANIFEST_REPO_OWNER}/${MANIFEST_REPO_NAME}/${MANIFEST_REPO_BRANCH}/versions-manifest.json`;
|
exports.MANIFEST_URL = `https://raw.githubusercontent.com/${MANIFEST_REPO_OWNER}/${MANIFEST_REPO_NAME}/${MANIFEST_REPO_BRANCH}/versions-manifest.json`;
|
||||||
const IS_WINDOWS = process.platform === 'win32';
|
const IS_WINDOWS = process.platform === 'win32';
|
||||||
|
const IS_LINUX = process.platform === 'linux';
|
||||||
function findReleaseFromManifest(semanticVersionSpec, architecture) {
|
function findReleaseFromManifest(semanticVersionSpec, architecture) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const manifest = yield tc.getManifestFromRepo(MANIFEST_REPO_OWNER, MANIFEST_REPO_NAME, AUTH, MANIFEST_REPO_BRANCH);
|
const manifest = yield tc.getManifestFromRepo(MANIFEST_REPO_OWNER, MANIFEST_REPO_NAME, AUTH, MANIFEST_REPO_BRANCH);
|
||||||
@ -6443,6 +6445,7 @@ function installPython(workingDirectory) {
|
|||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const options = {
|
const options = {
|
||||||
cwd: workingDirectory,
|
cwd: workingDirectory,
|
||||||
|
env: Object.assign(Object.assign({}, process.env), IS_LINUX && { 'LD_LIBRARY_PATH': path.join(workingDirectory, 'lib') }),
|
||||||
silent: true,
|
silent: true,
|
||||||
listeners: {
|
listeners: {
|
||||||
stdout: (data) => {
|
stdout: (data) => {
|
||||||
@ -6688,6 +6691,7 @@ const installer = __importStar(__webpack_require__(824));
|
|||||||
const core = __importStar(__webpack_require__(470));
|
const core = __importStar(__webpack_require__(470));
|
||||||
const tc = __importStar(__webpack_require__(533));
|
const tc = __importStar(__webpack_require__(533));
|
||||||
const IS_WINDOWS = process.platform === 'win32';
|
const IS_WINDOWS = process.platform === 'win32';
|
||||||
|
const IS_LINUX = process.platform === 'linux';
|
||||||
// Python has "scripts" or "bin" directories where command-line tools that come with packages are installed.
|
// Python has "scripts" or "bin" directories where command-line tools that come with packages are installed.
|
||||||
// This is where pip is, along with anything that pip installs.
|
// This is where pip is, along with anything that pip installs.
|
||||||
// There is a seperate directory for `pip install --user`.
|
// There is a seperate directory for `pip install --user`.
|
||||||
@ -6760,6 +6764,13 @@ function useCpythonVersion(version, architecture) {
|
|||||||
].join(os.EOL));
|
].join(os.EOL));
|
||||||
}
|
}
|
||||||
core.exportVariable('pythonLocation', installDir);
|
core.exportVariable('pythonLocation', installDir);
|
||||||
|
if (IS_LINUX) {
|
||||||
|
const libPath = (process.env.LD_LIBRARY_PATH) ? `:${process.env.LD_LIBRARY_PATH}` : '';
|
||||||
|
const pyLibPath = path.join(installDir, 'lib');
|
||||||
|
if (!libPath.split(':').includes(pyLibPath)) {
|
||||||
|
core.exportVariable('LD_LIBRARY_PATH', pyLibPath + libPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
core.addPath(installDir);
|
core.addPath(installDir);
|
||||||
core.addPath(binDir(installDir));
|
core.addPath(binDir(installDir));
|
||||||
if (IS_WINDOWS) {
|
if (IS_WINDOWS) {
|
||||||
|
@ -13,12 +13,14 @@ In order to avoid uploading `node_modules/` to the repository, we use [vercel/nc
|
|||||||
### Developing
|
### Developing
|
||||||
|
|
||||||
If you're developing locally, you can run
|
If you're developing locally, you can run
|
||||||
```
|
|
||||||
|
```sh
|
||||||
npm install
|
npm install
|
||||||
tsc
|
tsc
|
||||||
ncc build src/setup-python.ts
|
ncc build src/setup-python.ts
|
||||||
```
|
```
|
||||||
Any files generated using `tsc` will be added to `lib/`, however those files also are not uploaded to the repository and are exluded using `.gitignore`.
|
|
||||||
|
Any files generated using `tsc` will be added to `lib/`, however those files also are not uploaded to the repository and are excluded using `.gitignore`.
|
||||||
|
|
||||||
During the commit step, Husky will take care of formatting all files with [Prettier](https://github.com/prettier/prettier) (to run manually, use `npm run format`).
|
During the commit step, Husky will take care of formatting all files with [Prettier](https://github.com/prettier/prettier) (to run manually, use `npm run format`).
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ import * as core from '@actions/core';
|
|||||||
import * as tc from '@actions/tool-cache';
|
import * as tc from '@actions/tool-cache';
|
||||||
|
|
||||||
const IS_WINDOWS = process.platform === 'win32';
|
const IS_WINDOWS = process.platform === 'win32';
|
||||||
|
const IS_LINUX = process.platform === 'linux';
|
||||||
|
|
||||||
// Python has "scripts" or "bin" directories where command-line tools that come with packages are installed.
|
// Python has "scripts" or "bin" directories where command-line tools that come with packages are installed.
|
||||||
// This is where pip is, along with anything that pip installs.
|
// This is where pip is, along with anything that pip installs.
|
||||||
@ -109,6 +110,18 @@ async function useCpythonVersion(
|
|||||||
}
|
}
|
||||||
|
|
||||||
core.exportVariable('pythonLocation', installDir);
|
core.exportVariable('pythonLocation', installDir);
|
||||||
|
|
||||||
|
if (IS_LINUX) {
|
||||||
|
const libPath = process.env.LD_LIBRARY_PATH
|
||||||
|
? `:${process.env.LD_LIBRARY_PATH}`
|
||||||
|
: '';
|
||||||
|
const pyLibPath = path.join(installDir, 'lib');
|
||||||
|
|
||||||
|
if (!libPath.split(':').includes(pyLibPath)) {
|
||||||
|
core.exportVariable('LD_LIBRARY_PATH', pyLibPath + libPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
core.addPath(installDir);
|
core.addPath(installDir);
|
||||||
core.addPath(binDir(installDir));
|
core.addPath(binDir(installDir));
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ const MANIFEST_REPO_BRANCH = 'main';
|
|||||||
export const MANIFEST_URL = `https://raw.githubusercontent.com/${MANIFEST_REPO_OWNER}/${MANIFEST_REPO_NAME}/${MANIFEST_REPO_BRANCH}/versions-manifest.json`;
|
export const MANIFEST_URL = `https://raw.githubusercontent.com/${MANIFEST_REPO_OWNER}/${MANIFEST_REPO_NAME}/${MANIFEST_REPO_BRANCH}/versions-manifest.json`;
|
||||||
|
|
||||||
const IS_WINDOWS = process.platform === 'win32';
|
const IS_WINDOWS = process.platform === 'win32';
|
||||||
|
const IS_LINUX = process.platform === 'linux';
|
||||||
|
|
||||||
export async function findReleaseFromManifest(
|
export async function findReleaseFromManifest(
|
||||||
semanticVersionSpec: string,
|
semanticVersionSpec: string,
|
||||||
@ -35,6 +36,10 @@ export async function findReleaseFromManifest(
|
|||||||
async function installPython(workingDirectory: string) {
|
async function installPython(workingDirectory: string) {
|
||||||
const options: ExecOptions = {
|
const options: ExecOptions = {
|
||||||
cwd: workingDirectory,
|
cwd: workingDirectory,
|
||||||
|
env: {
|
||||||
|
...process.env,
|
||||||
|
...(IS_LINUX && {LD_LIBRARY_PATH: path.join(workingDirectory, 'lib')})
|
||||||
|
},
|
||||||
silent: true,
|
silent: true,
|
||||||
listeners: {
|
listeners: {
|
||||||
stdout: (data: Buffer) => {
|
stdout: (data: Buffer) => {
|
||||||
|
Reference in New Issue
Block a user