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

Function addVendorBytecodeWithinCapacity

packages/python/src/index.ts:139–170  ·  view source on GitHub ↗
({
  files,
  depExternalizer,
  vendorDir,
  bytecodeInfo,
  capacity,
}: {
  files: Files;
  depExternalizer: PythonDependencyExternalizer;
  vendorDir: string;
  bytecodeInfo: BytecodeCollectionResult | undefined;
  capacity: number;
})

Source from the content-addressed store, hash-verified

137}
138
139async 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
172interface FrameworkHookContext {
173 pythonEnv: NodeJS.ProcessEnv;

Callers 1

Calls 3

lambdaKnapsackFunction · 0.90
addFilesFunction · 0.85
collectBytecodeFilesMethod · 0.45

Tested by

no test coverage detected