From a3f221d01cc7e69ff35538370ad37e7a0785c25a Mon Sep 17 00:00:00 2001 From: Kevin Stillhammer Date: Fri, 13 Dec 2024 21:13:41 +0100 Subject: [PATCH] Auto activate venv when python-version is set --- .github/workflows/test.yml | 3 +-- dist/setup/index.js | 19 ++++++++++++++----- src/setup-uv.ts | 12 ++++++++++-- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 54b97f3..5fe94b5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -155,5 +155,4 @@ jobs: if [ "$UV_PYTHON" != "${{ matrix.python-version }}" ]; then exit 1 fi - - run: uv sync - working-directory: __tests__/fixtures/uv-project + - run: uv pip install --python=${{ matrix.python-version }} -i https://pypi.anaconda.org/scientific-python-nightly-wheels/simple cython diff --git a/dist/setup/index.js b/dist/setup/index.js index 96300d5..db8ecfd 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -99204,6 +99204,7 @@ const download_version_1 = __nccwpck_require__(8255); const restore_cache_1 = __nccwpck_require__(7772); const platforms_1 = __nccwpck_require__(8361); const inputs_1 = __nccwpck_require__(9612); +const exec = __importStar(__nccwpck_require__(5236)); function run() { return __awaiter(this, void 0, void 0, function* () { const platform = (0, platforms_1.getPlatform)(); @@ -99219,7 +99220,7 @@ function run() { addUvToPath(setupResult.uvDir); addToolBinToPath(); setToolDir(); - setupPython(); + yield setupPython(); addMatchers(); setCacheDir(inputs_1.cacheLocalPath); core.setOutput("uv-version", setupResult.version); @@ -99285,10 +99286,18 @@ function setToolDir() { } } function setupPython() { - if (inputs_1.pythonVersion !== "") { - core.exportVariable("UV_PYTHON", inputs_1.pythonVersion); - core.info(`Set UV_PYTHON to ${inputs_1.pythonVersion}`); - } + return __awaiter(this, void 0, void 0, function* () { + if (inputs_1.pythonVersion !== "") { + core.exportVariable("UV_PYTHON", 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); + } + }); } function setCacheDir(cacheLocalPath) { core.exportVariable("UV_CACHE_DIR", cacheLocalPath); diff --git a/src/setup-uv.ts b/src/setup-uv.ts index f95babc..fe78a6c 100644 --- a/src/setup-uv.ts +++ b/src/setup-uv.ts @@ -23,6 +23,7 @@ import { toolDir, version, } from "./utils/inputs"; +import * as exec from "@actions/exec"; async function run(): Promise { const platform = getPlatform(); @@ -46,7 +47,7 @@ async function run(): Promise { addUvToPath(setupResult.uvDir); addToolBinToPath(); setToolDir(); - setupPython(); + await setupPython(); addMatchers(); setCacheDir(cacheLocalPath); @@ -125,10 +126,17 @@ function setToolDir(): void { } } -function setupPython(): void { +async function setupPython(): Promise { if (pythonVersion !== "") { core.exportVariable("UV_PYTHON", 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); } }