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

Function pipInstall

packages/python/src/install.ts:402–465  ·  view source on GitHub ↗
(
  pipPath: string,
  uvPath: string | null,
  workPath: string,
  args: string[],
  targetDir?: string
)

Source from the content-addressed store, hash-verified

400}
401
402async function pipInstall(
403 pipPath: string,
404 uvPath: string | null,
405 workPath: string,
406 args: string[],
407 targetDir?: string
408) {
409 const target = targetDir
410 ? join(targetDir, resolveVendorDir())
411 : resolveVendorDir();
412 // See: https://github.com/pypa/pip/issues/4222#issuecomment-417646535
413 //
414 // Disable installing to the Python user install directory, which is
415 // the default behavior on Debian systems and causes error:
416 //
417 // distutils.errors.DistutilsOptionError: can't combine user with
418 // prefix, exec_prefix/home, or install_(plat)base
419 process.env.PIP_USER = '0';
420
421 if (uvPath) {
422 const uvArgs = [
423 'pip',
424 'install',
425 '--no-compile',
426 '--no-cache-dir',
427 '--target',
428 target,
429 ...filterUnsafeUvPipArgs(args),
430 ];
431 const prettyUv = `${uvPath} ${uvArgs.join(' ')}`;
432 debug(`Running "${prettyUv}"...`);
433 try {
434 await execa(uvPath!, uvArgs, {
435 cwd: workPath,
436 env: getProtectedUvEnv(process.env, getUvCacheDir(workPath)),
437 });
438 return;
439 } catch (err) {
440 console.log(`Failed to run "${prettyUv}", falling back to pip`);
441 debug(`error: ${err}`);
442 }
443 }
444
445 const cmdArgs = [
446 'install',
447 '--disable-pip-version-check',
448 '--no-compile',
449 '--no-cache-dir',
450 '--target',
451 target,
452 ...args,
453 ];
454 const pretty = `${pipPath} ${cmdArgs.join(' ')}`;
455 debug(`Running "${pretty}"...`);
456 try {
457 await execa(pipPath, cmdArgs, {
458 cwd: workPath,
459 });

Callers 2

installRequirementFunction · 0.85
installRequirementsFileFunction · 0.85

Calls 8

filterUnsafeUvPipArgsFunction · 0.90
debugFunction · 0.90
getProtectedUvEnvFunction · 0.90
getUvCacheDirFunction · 0.90
resolveVendorDirFunction · 0.85
execaFunction · 0.85
joinMethod · 0.45
logMethod · 0.45

Tested by

no test coverage detected