make sandbox venv support more robust, allowing arbitrary venv path, and ignoring venv outside workdir (instead of erroring out) (#254)
This commit is contained in:
parent
3a1abb07bf
commit
cfdbea4dc2
|
@ -231,18 +231,11 @@ export async function start_sandbox(sandbox: string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if VIRTUAL_ENV is set, require that it is workdir/.venv
|
// copy VIRTUAL_ENV if under working directory
|
||||||
// then mount-replace it with sandbox.venv under project settings directory
|
// also mount-replace VIRTUAL_ENV directory with <project_settings>/sandbox.venv
|
||||||
// this helps avoid host binaries in sandbox and lets uv work seamlessly w/o requiring --active flag
|
// sandbox can then set up this new VIRTUAL_ENV directory using sandbox.bashrc (see below)
|
||||||
// sandbox must be ready to set up an empty .venv directory via sandbox.{Dockerfile,bashrc}
|
// directory will be empty if not set up, which is still preferable to having host binaries
|
||||||
if (process.env.VIRTUAL_ENV) {
|
if (process.env.VIRTUAL_ENV?.startsWith(workdir)) {
|
||||||
const workdirVenvPath = path.join(workdir, '.venv');
|
|
||||||
if (workdirVenvPath !== process.env.VIRTUAL_ENV) {
|
|
||||||
console.error(
|
|
||||||
`ERROR: VIRTUAL_ENV '${process.env.VIRTUAL_ENV}' is not supported; should be ${workdirVenvPath}`,
|
|
||||||
);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
const sandboxVenvPath = path.resolve(
|
const sandboxVenvPath = path.resolve(
|
||||||
SETTINGS_DIRECTORY_NAME,
|
SETTINGS_DIRECTORY_NAME,
|
||||||
'sandbox.venv',
|
'sandbox.venv',
|
||||||
|
@ -250,7 +243,8 @@ export async function start_sandbox(sandbox: string) {
|
||||||
if (!fs.existsSync(sandboxVenvPath)) {
|
if (!fs.existsSync(sandboxVenvPath)) {
|
||||||
fs.mkdirSync(sandboxVenvPath, { recursive: true });
|
fs.mkdirSync(sandboxVenvPath, { recursive: true });
|
||||||
}
|
}
|
||||||
args.push('--volume', `${sandboxVenvPath}:${workdirVenvPath}`);
|
args.push('--volume', `${sandboxVenvPath}:${process.env.VIRTUAL_ENV}`);
|
||||||
|
args.push('--env', `VIRTUAL_ENV=${process.env.VIRTUAL_ENV}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy additional environment variables from SANDBOX_ENV
|
// copy additional environment variables from SANDBOX_ENV
|
||||||
|
|
Loading…
Reference in New Issue