Skip to content

Commit f2859da

Browse files
authored
Respect UV_NO_MODIFY_PATH (#603)
Fixes: #519
1 parent f9c6974 commit f2859da

File tree

7 files changed

+96
-12
lines changed

7 files changed

+96
-12
lines changed

.github/workflows/test.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,29 @@ jobs:
7272
env:
7373
UVX_PATH: ${{ steps.setup-uv.outputs.uvx-path }}
7474

75+
test-uv-no-modify-path:
76+
runs-on: ubuntu-latest
77+
steps:
78+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
79+
with:
80+
persist-credentials: false
81+
- name: Install with UV_NO_MODIFY_PATH set
82+
id: setup-uv
83+
uses: ./
84+
env:
85+
UV_NO_MODIFY_PATH: true
86+
- run: "${UV_PATH}" sync
87+
working-directory: __tests__/fixtures/uv-project
88+
shell: bash
89+
env:
90+
UV_PATH: ${{ steps.setup-uv.outputs.uv-path }}
91+
- name: uv is not on PATH
92+
run: |
93+
if command -v uv; then
94+
echo "uv should not be on PATH"
95+
exit 1
96+
fi
97+
7598
test-specific-version:
7699
runs-on: ubuntu-latest
77100
strategy:
@@ -755,6 +778,7 @@ jobs:
755778
needs:
756779
- lint
757780
- test-default-version
781+
- test-uv-no-modify-path
758782
- test-specific-version
759783
- test-latest-version
760784
- test-from-working-directory-version

dist/save-cache/index.js

Lines changed: 18 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/setup/index.js

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

dist/update-known-versions/index.js

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

src/save-cache.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
STATE_CACHE_KEY,
77
STATE_CACHE_MATCHED_KEY,
88
} from "./cache/restore-cache";
9+
import { STATE_UV_PATH } from "./utils/constants";
910
import {
1011
cacheLocalPath,
1112
enableCache,
@@ -91,7 +92,8 @@ async function pruneCache(): Promise<void> {
9192
const execArgs = ["cache", "prune", "--ci"];
9293

9394
core.info("Pruning cache...");
94-
await exec.exec("uv", execArgs, options);
95+
const uvPath = core.getState(STATE_UV_PATH);
96+
await exec.exec(uvPath, execArgs, options);
9597
}
9698

9799
run();

src/setup-uv.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
resolveVersion,
1010
tryGetFromToolCache,
1111
} from "./download/download-version";
12+
import { STATE_UV_PATH } from "./utils/constants";
1213
import {
1314
activateEnvironment as activateEnvironmentInput,
1415
addProblemMatchers,
@@ -163,18 +164,31 @@ async function determineVersion(
163164

164165
function addUvToPathAndOutput(cachedPath: string): void {
165166
core.setOutput("uv-path", `${cachedPath}${path.sep}uv`);
167+
core.saveState(STATE_UV_PATH, `${cachedPath}${path.sep}uv`);
166168
core.setOutput("uvx-path", `${cachedPath}${path.sep}uvx`);
167-
core.addPath(cachedPath);
168-
core.info(`Added ${cachedPath} to the path`);
169+
if (process.env.UV_NO_MODIFY_PATH !== undefined) {
170+
core.info("UV_NO_MODIFY_PATH is set, not modifying PATH");
171+
} else {
172+
core.addPath(cachedPath);
173+
core.info(`Added ${cachedPath} to the path`);
174+
}
169175
}
170176

171177
function addToolBinToPath(): void {
172178
if (toolBinDir !== undefined) {
173179
core.exportVariable("UV_TOOL_BIN_DIR", toolBinDir);
174180
core.info(`Set UV_TOOL_BIN_DIR to ${toolBinDir}`);
175-
core.addPath(toolBinDir);
176-
core.info(`Added ${toolBinDir} to the path`);
181+
if (process.env.UV_NO_MODIFY_PATH !== undefined) {
182+
core.info(`UV_NO_MODIFY_PATH is set, not adding ${toolBinDir} to path`);
183+
} else {
184+
core.addPath(toolBinDir);
185+
core.info(`Added ${toolBinDir} to the path`);
186+
}
177187
} else {
188+
if (process.env.UV_NO_MODIFY_PATH !== undefined) {
189+
core.info("UV_NO_MODIFY_PATH is set, not adding user local bin to path");
190+
return;
191+
}
178192
if (process.env.XDG_BIN_HOME !== undefined) {
179193
core.addPath(process.env.XDG_BIN_HOME);
180194
core.info(`Added ${process.env.XDG_BIN_HOME} to the path`);
@@ -204,6 +218,11 @@ function setupPython(): void {
204218

205219
async function activateEnvironment(): Promise<void> {
206220
if (activateEnvironmentInput) {
221+
if (process.env.UV_NO_MODIFY_PATH !== undefined) {
222+
throw new Error(
223+
"UV_NO_MODIFY_PATH and activate-environment cannot be used together.",
224+
);
225+
}
207226
const execArgs = ["venv", ".venv", "--directory", workingDirectory];
208227

209228
core.info("Activating python venv...");

src/utils/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export const REPO = "uv";
22
export const OWNER = "astral-sh";
33
export const TOOL_CACHE_NAME = "uv";
4+
export const STATE_UV_PATH = "uv-path";

0 commit comments

Comments
 (0)