Skip to content

Commit b3e97d2

Browse files
authored
Add input no-project in combination with activate-environment (#856)
Closes: #854
1 parent 7dd591d commit b3e97d2

File tree

8 files changed

+71
-4
lines changed

8 files changed

+71
-4
lines changed

.github/workflows/test.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,49 @@ jobs:
430430
PY
431431
shell: bash
432432

433+
test-activate-environment-no-project:
434+
runs-on: ubuntu-latest
435+
steps:
436+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
437+
with:
438+
persist-credentials: false
439+
- name: Create incompatible pyproject.toml
440+
run: |
441+
cat > pyproject.toml <<'EOF'
442+
[project]
443+
name = "test-no-project"
444+
version = "0.1.0"
445+
446+
[dependency-groups]
447+
dev = [
448+
"-e file:///${PROJECT_ROOT}/projects/pkg",
449+
]
450+
EOF
451+
shell: bash
452+
- name: Install latest version with no-project
453+
id: setup-uv
454+
uses: ./
455+
with:
456+
python-version: 3.13.1t
457+
activate-environment: true
458+
no-project: true
459+
- name: Verify packages can be installed
460+
run: uv pip install pip
461+
shell: bash
462+
- name: Verify output venv is set
463+
run: |
464+
if [ -z "$UV_VENV" ]; then
465+
echo "output venv is not set"
466+
exit 1
467+
fi
468+
if [ ! -d "$UV_VENV" ]; then
469+
echo "output venv not point to a directory: $UV_VENV"
470+
exit 1
471+
fi
472+
shell: bash
473+
env:
474+
UV_VENV: ${{ steps.setup-uv.outputs.venv }}
475+
433476
test-debian-unstable:
434477
runs-on: ubuntu-latest
435478
container: debian:unstable
@@ -1057,6 +1100,7 @@ jobs:
10571100
- test-python-version
10581101
- test-activate-environment
10591102
- test-activate-environment-custom-path
1103+
- test-activate-environment-no-project
10601104
- test-debian-unstable
10611105
- test-musl
10621106
- test-cache-key-os-version

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ Have a look under [Advanced Configuration](#advanced-configuration) for detailed
6262
# Custom path for the virtual environment when using activate-environment (default: .venv in the working directory)
6363
venv-path: ""
6464
65+
# Pass --no-project when creating the venv with activate-environment.
66+
no-project: "false"
67+
6568
# The directory to execute all commands in and look for files such as pyproject.toml
6669
working-directory: ""
6770

action-types.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ inputs:
1111
type: boolean
1212
venv-path:
1313
type: string
14+
no-project:
15+
type: boolean
1416
working-directory:
1517
type: string
1618
checksum:

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ inputs:
1818
venv-path:
1919
description: "Custom path for the virtual environment when using activate-environment. Defaults to '.venv' in the working directory."
2020
default: ""
21+
no-project:
22+
description: "Pass --no-project when creating the venv with activate-environment."
23+
default: "false"
2124
working-directory:
2225
description: "The directory to execute all commands in and look for files such as pyproject.toml"
2326
default: ${{ github.workspace }}

dist/save-cache/index.cjs

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/setup/index.cjs

Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/setup-uv.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,17 @@ async function activateEnvironment(inputs: SetupInputs): Promise<void> {
218218
}
219219

220220
core.info(`Creating and activating python venv at ${inputs.venvPath}...`);
221-
await exec.exec("uv", [
221+
const venvArgs = [
222222
"venv",
223223
inputs.venvPath,
224224
"--directory",
225225
inputs.workingDirectory,
226226
"--clear",
227-
]);
227+
];
228+
if (inputs.noProject) {
229+
venvArgs.push("--no-project");
230+
}
231+
await exec.exec("uv", venvArgs);
228232

229233
let venvBinPath = `${inputs.venvPath}${path.sep}bin`;
230234
if (process.platform === "win32") {

src/utils/inputs.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export interface SetupInputs {
2222
versionFile: string;
2323
pythonVersion: string;
2424
activateEnvironment: boolean;
25+
noProject: boolean;
2526
venvPath: string;
2627
checksum: string;
2728
enableCache: boolean;
@@ -49,6 +50,7 @@ export function loadInputs(): SetupInputs {
4950
const versionFile = getVersionFile(workingDirectory);
5051
const pythonVersion = core.getInput("python-version");
5152
const activateEnvironment = core.getBooleanInput("activate-environment");
53+
const noProject = core.getBooleanInput("no-project");
5254
const venvPath = getVenvPath(workingDirectory, activateEnvironment);
5355
const checksum = core.getInput("checksum");
5456
const enableCache = getEnableCache();
@@ -87,6 +89,7 @@ export function loadInputs(): SetupInputs {
8789
ignoreEmptyWorkdir,
8890
ignoreNothingToCache,
8991
manifestFile,
92+
noProject,
9093
pruneCache,
9194
pythonDir,
9295
pythonVersion,

0 commit comments

Comments
 (0)