MCPcopy Create free account
hub / github.com/vercel/vercel / useVirtualEnv

Function useVirtualEnv

packages/python/src/utils.ts:17–43  ·  view source on GitHub ↗
(
  workPath: string,
  env: NodeJS.ProcessEnv,
  systemPython: string
)

Source from the content-addressed store, hash-verified

15}
16
17export function useVirtualEnv(
18 workPath: string,
19 env: NodeJS.ProcessEnv,
20 systemPython: string
21): { pythonCmd: string; venvRoot?: string } {
22 const venvDirs = ['.venv', 'venv'];
23 let pythonCmd = systemPython;
24 for (const venv of venvDirs) {
25 const venvRoot = join(workPath, venv);
26 const binDir =
27 process.platform === 'win32'
28 ? join(venvRoot, 'Scripts')
29 : join(venvRoot, 'bin');
30 const candidates =
31 process.platform === 'win32'
32 ? [join(binDir, 'python.exe'), join(binDir, 'python')]
33 : [join(binDir, 'python3'), join(binDir, 'python')];
34 const found = candidates.find(p => fs.existsSync(p));
35 if (found) {
36 pythonCmd = found;
37 env.VIRTUAL_ENV = venvRoot;
38 env.PATH = `${binDir}${pathDelimiter}${env.PATH || ''}`;
39 return { pythonCmd, venvRoot };
40 }
41 }
42 return { pythonCmd };
43}
44
45export function createVenvEnv(
46 venvPath: string,

Callers 3

startDevServerFunction · 0.90
runPyprojectScriptFunction · 0.85

Calls 2

findMethod · 0.45
existsSyncMethod · 0.45

Tested by

no test coverage detected