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

Function getSitePackagesDirs

packages/python/src/install.ts:97–121  ·  view source on GitHub ↗
(pythonBin: string)

Source from the content-addressed store, hash-verified

95}
96
97async function getSitePackagesDirs(pythonBin: string): Promise<string[]> {
98 // Ask the venv's interpreter which directories it adds to sys.path for pure
99 // Python packages and platform-specific packages so we mirror the exact same
100 // paths when mounting `_vendor` in the Lambda bundle.
101 const code = `
102import json
103import sysconfig
104paths = []
105for key in ("purelib", "platlib"):
106 candidate = sysconfig.get_path(key)
107 if candidate and candidate not in paths:
108 paths.append(candidate)
109print(json.dumps(paths))
110`.trim();
111 const { stdout } = await execa(pythonBin, ['-c', code]);
112 try {
113 const parsed = JSON.parse(stdout);
114 if (Array.isArray(parsed)) {
115 return parsed.filter((p): p is string => typeof p === 'string');
116 }
117 } catch (err) {
118 debug('Failed to parse site-packages output', err);
119 }
120 return [];
121}
122
123export async function getVenvSitePackagesDirs(
124 venvPath: string

Callers 1

getVenvSitePackagesDirsFunction · 0.85

Calls 4

debugFunction · 0.90
execaFunction · 0.85
filterMethod · 0.80
parseMethod · 0.45

Tested by

no test coverage detected