({
files,
depExternalizer,
vendorDir,
bytecodeInfo,
capacity,
}: {
files: Files;
depExternalizer: PythonDependencyExternalizer;
vendorDir: string;
bytecodeInfo: BytecodeCollectionResult | undefined;
capacity: number;
})
| 137 | } |
| 138 | |
| 139 | async function addVendorBytecodeWithinCapacity({ |
| 140 | files, |
| 141 | depExternalizer, |
| 142 | vendorDir, |
| 143 | bytecodeInfo, |
| 144 | capacity, |
| 145 | }: { |
| 146 | files: Files; |
| 147 | depExternalizer: PythonDependencyExternalizer; |
| 148 | vendorDir: string; |
| 149 | bytecodeInfo: BytecodeCollectionResult | undefined; |
| 150 | capacity: number; |
| 151 | }): Promise<number> { |
| 152 | if (!bytecodeInfo || bytecodeInfo.totalSize <= 0 || capacity <= 0) { |
| 153 | return capacity; |
| 154 | } |
| 155 | |
| 156 | if (bytecodeInfo.totalSize <= capacity) { |
| 157 | addFiles(files, bytecodeInfo.files); |
| 158 | return capacity - bytecodeInfo.totalSize; |
| 159 | } |
| 160 | |
| 161 | const selectedPkgs = lambdaKnapsack(bytecodeInfo.perItemSizes, capacity); |
| 162 | if (selectedPkgs.length === 0) return capacity; |
| 163 | |
| 164 | const selectedBytecode = await depExternalizer.collectBytecodeFiles({ |
| 165 | vendorDirName: vendorDir, |
| 166 | includePackages: selectedPkgs, |
| 167 | }); |
| 168 | addFiles(files, selectedBytecode.files); |
| 169 | return capacity - selectedBytecode.totalSize; |
| 170 | } |
| 171 | |
| 172 | interface FrameworkHookContext { |
| 173 | pythonEnv: NodeJS.ProcessEnv; |
no test coverage detected