(pythonBin: string)
| 95 | } |
| 96 | |
| 97 | async 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 = ` |
| 102 | import json |
| 103 | import sysconfig |
| 104 | paths = [] |
| 105 | for key in ("purelib", "platlib"): |
| 106 | candidate = sysconfig.get_path(key) |
| 107 | if candidate and candidate not in paths: |
| 108 | paths.append(candidate) |
| 109 | print(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 | |
| 123 | export async function getVenvSitePackagesDirs( |
| 124 | venvPath: string |
no test coverage detected