mirror of
https://github.com/astral-sh/setup-uv.git
synced 2025-02-07 17:46:10 +08:00
parent
85aa0bf0c1
commit
dd578776bb
20
.github/workflows/test.yml
vendored
20
.github/workflows/test.yml
vendored
@ -143,17 +143,27 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
python-version: ["3.12", "3.13t"]
|
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: Install latest version
|
- name: Install latest version
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
python-version: ${{ matrix.python-version }}
|
python-version: 3.13.1t
|
||||||
- name: Verify UV_PYTHON is set to correct version
|
- name: Verify UV_PYTHON is set to correct version
|
||||||
run: |
|
run: |
|
||||||
if [ "$UV_PYTHON" != "${{ matrix.python-version }}" ]; then
|
echo "$UV_PYTHON"
|
||||||
|
if [ "$UV_PYTHON" != "3.13.1t" ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
- run: uv sync
|
shell: bash
|
||||||
working-directory: __tests__/fixtures/uv-project
|
- name: Verify packages can be installed
|
||||||
|
run: uv pip install --python=3.13.1t pip
|
||||||
|
shell: bash
|
||||||
|
- name: Verify python version is correct
|
||||||
|
run: |
|
||||||
|
python --version
|
||||||
|
if [ "$(python --version)" != "Python 3.13.1" ]; then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
shell: bash
|
||||||
|
13
README.md
13
README.md
@ -72,15 +72,20 @@ to install the latest version that satisfies the range.
|
|||||||
|
|
||||||
### Python version
|
### Python version
|
||||||
|
|
||||||
You can use the input `python-version` to set the environment variable `UV_PYTHON` for the rest
|
You can use the input `python-version` to
|
||||||
of your workflow.
|
|
||||||
|
- set the environment variable `UV_PYTHON` for the rest of your workflow
|
||||||
|
- create a new virtual environment with the specified python version
|
||||||
|
- activate the virtual environment for the rest of your workflow
|
||||||
|
|
||||||
This will override any python version specifications in `pyproject.toml` and `.python-version`
|
This will override any python version specifications in `pyproject.toml` and `.python-version`
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- name: Install the latest version of uv and set the python version to 3.12
|
- name: Install the latest version of uv and set the python version to 3.13t
|
||||||
uses: astral-sh/setup-uv@v4
|
uses: astral-sh/setup-uv@v4
|
||||||
with:
|
with:
|
||||||
python-version: "3.12"
|
python-version: 3.13t
|
||||||
|
- run: uv pip install --python=3.13t pip
|
||||||
```
|
```
|
||||||
|
|
||||||
You can combine this with a matrix to test multiple python versions:
|
You can combine this with a matrix to test multiple python versions:
|
||||||
|
@ -14,8 +14,7 @@ inputs:
|
|||||||
required: false
|
required: false
|
||||||
github-token:
|
github-token:
|
||||||
description:
|
description:
|
||||||
"Used to increase the rate limit when retrieving versions and downloading
|
"Used to increase the rate limit when retrieving versions and downloading uv."
|
||||||
uv."
|
|
||||||
required: false
|
required: false
|
||||||
default: ${{ github.token }}
|
default: ${{ github.token }}
|
||||||
enable-cache:
|
enable-cache:
|
||||||
|
17
dist/setup/index.js
generated
vendored
17
dist/setup/index.js
generated
vendored
@ -99236,6 +99236,7 @@ const download_version_1 = __nccwpck_require__(8255);
|
|||||||
const restore_cache_1 = __nccwpck_require__(7772);
|
const restore_cache_1 = __nccwpck_require__(7772);
|
||||||
const platforms_1 = __nccwpck_require__(8361);
|
const platforms_1 = __nccwpck_require__(8361);
|
||||||
const inputs_1 = __nccwpck_require__(9612);
|
const inputs_1 = __nccwpck_require__(9612);
|
||||||
|
const exec = __importStar(__nccwpck_require__(5236));
|
||||||
function run() {
|
function run() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const platform = (0, platforms_1.getPlatform)();
|
const platform = (0, platforms_1.getPlatform)();
|
||||||
@ -99251,7 +99252,7 @@ function run() {
|
|||||||
addUvToPath(setupResult.uvDir);
|
addUvToPath(setupResult.uvDir);
|
||||||
addToolBinToPath();
|
addToolBinToPath();
|
||||||
setToolDir();
|
setToolDir();
|
||||||
setupPython();
|
yield setupPython();
|
||||||
addMatchers();
|
addMatchers();
|
||||||
setCacheDir(inputs_1.cacheLocalPath);
|
setCacheDir(inputs_1.cacheLocalPath);
|
||||||
core.setOutput("uv-version", setupResult.version);
|
core.setOutput("uv-version", setupResult.version);
|
||||||
@ -99317,10 +99318,24 @@ function setToolDir() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
function setupPython() {
|
function setupPython() {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
if (inputs_1.pythonVersion !== "") {
|
if (inputs_1.pythonVersion !== "") {
|
||||||
core.exportVariable("UV_PYTHON", inputs_1.pythonVersion);
|
core.exportVariable("UV_PYTHON", inputs_1.pythonVersion);
|
||||||
core.info(`Set UV_PYTHON to ${inputs_1.pythonVersion}`);
|
core.info(`Set UV_PYTHON to ${inputs_1.pythonVersion}`);
|
||||||
|
const options = {
|
||||||
|
silent: !core.isDebug(),
|
||||||
|
};
|
||||||
|
const execArgs = ["venv", "--python", inputs_1.pythonVersion];
|
||||||
|
core.info("Activating python venv...");
|
||||||
|
yield exec.exec("uv", execArgs, options);
|
||||||
|
let venvBinPath = ".venv/bin";
|
||||||
|
if (process.platform === "win32") {
|
||||||
|
venvBinPath = ".venv/Scripts";
|
||||||
}
|
}
|
||||||
|
core.addPath(venvBinPath);
|
||||||
|
core.exportVariable("VIRTUAL_ENV", venvBinPath);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
function setCacheDir(cacheLocalPath) {
|
function setCacheDir(cacheLocalPath) {
|
||||||
core.exportVariable("UV_CACHE_DIR", cacheLocalPath);
|
core.exportVariable("UV_CACHE_DIR", cacheLocalPath);
|
||||||
|
@ -23,6 +23,7 @@ import {
|
|||||||
toolDir,
|
toolDir,
|
||||||
version,
|
version,
|
||||||
} from "./utils/inputs";
|
} from "./utils/inputs";
|
||||||
|
import * as exec from "@actions/exec";
|
||||||
|
|
||||||
async function run(): Promise<void> {
|
async function run(): Promise<void> {
|
||||||
const platform = getPlatform();
|
const platform = getPlatform();
|
||||||
@ -46,7 +47,7 @@ async function run(): Promise<void> {
|
|||||||
addUvToPath(setupResult.uvDir);
|
addUvToPath(setupResult.uvDir);
|
||||||
addToolBinToPath();
|
addToolBinToPath();
|
||||||
setToolDir();
|
setToolDir();
|
||||||
setupPython();
|
await setupPython();
|
||||||
addMatchers();
|
addMatchers();
|
||||||
setCacheDir(cacheLocalPath);
|
setCacheDir(cacheLocalPath);
|
||||||
|
|
||||||
@ -125,10 +126,24 @@ function setToolDir(): void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupPython(): void {
|
async function setupPython(): Promise<void> {
|
||||||
if (pythonVersion !== "") {
|
if (pythonVersion !== "") {
|
||||||
core.exportVariable("UV_PYTHON", pythonVersion);
|
core.exportVariable("UV_PYTHON", pythonVersion);
|
||||||
core.info(`Set UV_PYTHON to ${pythonVersion}`);
|
core.info(`Set UV_PYTHON to ${pythonVersion}`);
|
||||||
|
const options: exec.ExecOptions = {
|
||||||
|
silent: !core.isDebug(),
|
||||||
|
};
|
||||||
|
const execArgs = ["venv", "--python", pythonVersion];
|
||||||
|
|
||||||
|
core.info("Activating python venv...");
|
||||||
|
await exec.exec("uv", execArgs, options);
|
||||||
|
|
||||||
|
let venvBinPath = ".venv/bin";
|
||||||
|
if (process.platform === "win32") {
|
||||||
|
venvBinPath = ".venv/Scripts";
|
||||||
|
}
|
||||||
|
core.addPath(venvBinPath);
|
||||||
|
core.exportVariable("VIRTUAL_ENV", venvBinPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user