mirror of
https://github.com/astral-sh/setup-uv.git
synced 2026-04-16 16:40:17 +00:00
chore: normalize venv-path and warn when unused
- Normalize venv-path and trim trailing separators - Improve activation log message - Warn when venv-path is set without activate-environment - Add test coverage for trailing slash + warning
This commit is contained in:
parent
4b51b416f8
commit
45fe5a27c5
5 changed files with 84 additions and 8 deletions
17
dist/save-cache/index.js
generated
vendored
17
dist/save-cache/index.js
generated
vendored
|
|
@ -91079,10 +91079,13 @@ function getVersionFile() {
|
|||
function getVenvPath() {
|
||||
const venvPathInput = core.getInput("venv-path");
|
||||
if (venvPathInput !== "") {
|
||||
if (!exports.activateEnvironment) {
|
||||
core.warning("venv-path is only used when activate-environment is true");
|
||||
}
|
||||
const tildeExpanded = expandTilde(venvPathInput);
|
||||
return resolveRelativePath(tildeExpanded);
|
||||
return normalizePath(resolveRelativePath(tildeExpanded));
|
||||
}
|
||||
return resolveRelativePath(".venv");
|
||||
return normalizePath(resolveRelativePath(".venv"));
|
||||
}
|
||||
function getEnableCache() {
|
||||
const enableCacheInput = core.getInput("enable-cache");
|
||||
|
|
@ -91212,6 +91215,16 @@ function expandTilde(input) {
|
|||
}
|
||||
return input;
|
||||
}
|
||||
function normalizePath(inputPath) {
|
||||
const normalized = node_path_1.default.normalize(inputPath);
|
||||
const root = node_path_1.default.parse(normalized).root;
|
||||
// Remove any trailing path separators, except when the whole path is the root.
|
||||
let trimmed = normalized;
|
||||
while (trimmed.length > root.length && trimmed.endsWith(node_path_1.default.sep)) {
|
||||
trimmed = trimmed.slice(0, -1);
|
||||
}
|
||||
return trimmed;
|
||||
}
|
||||
function resolveRelativePath(inputPath) {
|
||||
const hasNegation = inputPath.startsWith("!");
|
||||
const pathWithoutNegation = hasNegation ? inputPath.substring(1) : inputPath;
|
||||
|
|
|
|||
19
dist/setup/index.js
generated
vendored
19
dist/setup/index.js
generated
vendored
|
|
@ -96532,7 +96532,7 @@ async function activateEnvironment() {
|
|||
if (process.env.UV_NO_MODIFY_PATH !== undefined) {
|
||||
throw new Error("UV_NO_MODIFY_PATH and activate-environment cannot be used together.");
|
||||
}
|
||||
core.info(`Activating python venv at ${inputs_1.venvPath}...`);
|
||||
core.info(`Creating and activating python venv at ${inputs_1.venvPath}...`);
|
||||
await exec.exec("uv", ["venv", inputs_1.venvPath, "--directory", inputs_1.workingDirectory]);
|
||||
let venvBinPath = `${inputs_1.venvPath}${path.sep}bin`;
|
||||
if (process.platform === "win32") {
|
||||
|
|
@ -96759,10 +96759,13 @@ function getVersionFile() {
|
|||
function getVenvPath() {
|
||||
const venvPathInput = core.getInput("venv-path");
|
||||
if (venvPathInput !== "") {
|
||||
if (!exports.activateEnvironment) {
|
||||
core.warning("venv-path is only used when activate-environment is true");
|
||||
}
|
||||
const tildeExpanded = expandTilde(venvPathInput);
|
||||
return resolveRelativePath(tildeExpanded);
|
||||
return normalizePath(resolveRelativePath(tildeExpanded));
|
||||
}
|
||||
return resolveRelativePath(".venv");
|
||||
return normalizePath(resolveRelativePath(".venv"));
|
||||
}
|
||||
function getEnableCache() {
|
||||
const enableCacheInput = core.getInput("enable-cache");
|
||||
|
|
@ -96892,6 +96895,16 @@ function expandTilde(input) {
|
|||
}
|
||||
return input;
|
||||
}
|
||||
function normalizePath(inputPath) {
|
||||
const normalized = node_path_1.default.normalize(inputPath);
|
||||
const root = node_path_1.default.parse(normalized).root;
|
||||
// Remove any trailing path separators, except when the whole path is the root.
|
||||
let trimmed = normalized;
|
||||
while (trimmed.length > root.length && trimmed.endsWith(node_path_1.default.sep)) {
|
||||
trimmed = trimmed.slice(0, -1);
|
||||
}
|
||||
return trimmed;
|
||||
}
|
||||
function resolveRelativePath(inputPath) {
|
||||
const hasNegation = inputPath.startsWith("!");
|
||||
const pathWithoutNegation = hasNegation ? inputPath.substring(1) : inputPath;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue