diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0b876cc..f61d94d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -430,6 +430,49 @@ jobs: PY shell: bash + test-activate-environment-no-project: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + persist-credentials: false + - name: Create incompatible pyproject.toml + run: | + cat > pyproject.toml <<'EOF' + [project] + name = "test-no-project" + version = "0.1.0" + + [dependency-groups] + dev = [ + "-e file:///${PROJECT_ROOT}/projects/pkg", + ] + EOF + shell: bash + - name: Install latest version with no-project + id: setup-uv + uses: ./ + with: + python-version: 3.13.1t + activate-environment: true + no-project: true + - name: Verify packages can be installed + run: uv pip install pip + shell: bash + - name: Verify output venv is set + run: | + if [ -z "$UV_VENV" ]; then + echo "output venv is not set" + exit 1 + fi + if [ ! -d "$UV_VENV" ]; then + echo "output venv not point to a directory: $UV_VENV" + exit 1 + fi + shell: bash + env: + UV_VENV: ${{ steps.setup-uv.outputs.venv }} + test-debian-unstable: runs-on: ubuntu-latest container: debian:unstable @@ -1057,6 +1100,7 @@ jobs: - test-python-version - test-activate-environment - test-activate-environment-custom-path + - test-activate-environment-no-project - test-debian-unstable - test-musl - test-cache-key-os-version diff --git a/README.md b/README.md index b7bfb1b..5a7be53 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,9 @@ Have a look under [Advanced Configuration](#advanced-configuration) for detailed # Custom path for the virtual environment when using activate-environment (default: .venv in the working directory) venv-path: "" + # Pass --no-project when creating the venv with activate-environment. + no-project: "false" + # The directory to execute all commands in and look for files such as pyproject.toml working-directory: "" diff --git a/action-types.yml b/action-types.yml index 61335a0..804f0e7 100644 --- a/action-types.yml +++ b/action-types.yml @@ -11,6 +11,8 @@ inputs: type: boolean venv-path: type: string + no-project: + type: boolean working-directory: type: string checksum: diff --git a/action.yml b/action.yml index 8882beb..5ae9eca 100644 --- a/action.yml +++ b/action.yml @@ -18,6 +18,9 @@ inputs: venv-path: description: "Custom path for the virtual environment when using activate-environment. Defaults to '.venv' in the working directory." default: "" + no-project: + description: "Pass --no-project when creating the venv with activate-environment." + default: "false" working-directory: description: "The directory to execute all commands in and look for files such as pyproject.toml" default: ${{ github.workspace }} diff --git a/dist/save-cache/index.cjs b/dist/save-cache/index.cjs index 60bdd2c..7e7c9a7 100644 --- a/dist/save-cache/index.cjs +++ b/dist/save-cache/index.cjs @@ -62968,6 +62968,7 @@ function loadInputs() { const versionFile = getVersionFile(workingDirectory); const pythonVersion = getInput("python-version"); const activateEnvironment = getBooleanInput("activate-environment"); + const noProject = getBooleanInput("no-project"); const venvPath = getVenvPath(workingDirectory, activateEnvironment); const checksum = getInput("checksum"); const enableCache = getEnableCache(); @@ -63004,6 +63005,7 @@ function loadInputs() { ignoreEmptyWorkdir, ignoreNothingToCache, manifestFile, + noProject, pruneCache: pruneCache2, pythonDir, pythonVersion, diff --git a/dist/setup/index.cjs b/dist/setup/index.cjs index 731ea2b..724871c 100644 --- a/dist/setup/index.cjs +++ b/dist/setup/index.cjs @@ -96970,6 +96970,7 @@ function loadInputs() { const versionFile = getVersionFile(workingDirectory); const pythonVersion = getInput("python-version"); const activateEnvironment2 = getBooleanInput("activate-environment"); + const noProject = getBooleanInput("no-project"); const venvPath = getVenvPath(workingDirectory, activateEnvironment2); const checksum = getInput("checksum"); const enableCache = getEnableCache(); @@ -97006,6 +97007,7 @@ function loadInputs() { ignoreEmptyWorkdir, ignoreNothingToCache, manifestFile, + noProject, pruneCache, pythonDir, pythonVersion, @@ -97385,13 +97387,17 @@ async function activateEnvironment(inputs) { ); } info(`Creating and activating python venv at ${inputs.venvPath}...`); - await exec("uv", [ + const venvArgs = [ "venv", inputs.venvPath, "--directory", inputs.workingDirectory, "--clear" - ]); + ]; + if (inputs.noProject) { + venvArgs.push("--no-project"); + } + await exec("uv", venvArgs); let venvBinPath = `${inputs.venvPath}${path16.sep}bin`; if (process.platform === "win32") { venvBinPath = `${inputs.venvPath}${path16.sep}Scripts`; diff --git a/src/setup-uv.ts b/src/setup-uv.ts index 33d9d9b..2957541 100644 --- a/src/setup-uv.ts +++ b/src/setup-uv.ts @@ -218,13 +218,17 @@ async function activateEnvironment(inputs: SetupInputs): Promise { } core.info(`Creating and activating python venv at ${inputs.venvPath}...`); - await exec.exec("uv", [ + const venvArgs = [ "venv", inputs.venvPath, "--directory", inputs.workingDirectory, "--clear", - ]); + ]; + if (inputs.noProject) { + venvArgs.push("--no-project"); + } + await exec.exec("uv", venvArgs); let venvBinPath = `${inputs.venvPath}${path.sep}bin`; if (process.platform === "win32") { diff --git a/src/utils/inputs.ts b/src/utils/inputs.ts index be8ce83..551144c 100644 --- a/src/utils/inputs.ts +++ b/src/utils/inputs.ts @@ -22,6 +22,7 @@ export interface SetupInputs { versionFile: string; pythonVersion: string; activateEnvironment: boolean; + noProject: boolean; venvPath: string; checksum: string; enableCache: boolean; @@ -49,6 +50,7 @@ export function loadInputs(): SetupInputs { const versionFile = getVersionFile(workingDirectory); const pythonVersion = core.getInput("python-version"); const activateEnvironment = core.getBooleanInput("activate-environment"); + const noProject = core.getBooleanInput("no-project"); const venvPath = getVenvPath(workingDirectory, activateEnvironment); const checksum = core.getInput("checksum"); const enableCache = getEnableCache(); @@ -87,6 +89,7 @@ export function loadInputs(): SetupInputs { ignoreEmptyWorkdir, ignoreNothingToCache, manifestFile, + noProject, pruneCache, pythonDir, pythonVersion,