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

Function ensureUvProject

packages/python/src/install.ts:260–400  ·  view source on GitHub ↗
({
  workPath,
  rootDir,
  venvPath,
  pythonPackage,
  pythonVersion,
  uv,
  requireBinaryWheels = false,
  cachedLockPath,
}: EnsureUvProjectParams)

Source from the content-addressed store, hash-verified

258}
259
260export async function ensureUvProject({
261 workPath,
262 rootDir,
263 venvPath,
264 pythonPackage,
265 pythonVersion,
266 uv,
267 requireBinaryWheels = false,
268 cachedLockPath,
269}: EnsureUvProjectParams): Promise<UvProjectInfo> {
270 const { manifestType } = detectInstallSource(pythonPackage, rootDir);
271 const manifest = pythonPackage.manifest;
272
273 let projectDir: string;
274 let pyprojectPath: string;
275 let lockPath: string | null = null;
276 let lockFileProvidedByUser = false;
277
278 if (manifestType === 'uv.lock' || manifestType === 'pylock.toml') {
279 // User provided a lock file
280 lockFileProvidedByUser = true;
281 // Lock file exists - use it directly
282 const lockFile =
283 pythonPackage.manifest?.lockFile ?? pythonPackage.workspaceLockFile;
284 if (!lockFile) {
285 throw new Error(
286 `Expected lock file path to be resolved, but it was null`
287 );
288 }
289 lockPath = join(rootDir, lockFile.path);
290 // Project dir is where the lock file is located
291 projectDir = dirname(lockPath);
292 pyprojectPath = join(projectDir, 'pyproject.toml');
293
294 if (!fs.existsSync(pyprojectPath)) {
295 throw new Error(
296 `Expected "pyproject.toml" next to "${lockFile.kind}" in "${projectDir}"`
297 );
298 }
299 console.log(`Installing required dependencies from ${lockFile.kind}...`);
300 } else if (manifest) {
301 // Manifest exists (native pyproject.toml or converted from Pipfile/requirements.txt)
302 projectDir = join(rootDir, dirname(manifest.path));
303 pyprojectPath = join(rootDir, manifest.path);
304
305 // Log the original source for user clarity
306 const originKind = manifest.origin?.kind;
307 if (originKind === PythonManifestConvertedKind.Pipfile) {
308 console.log('Installing required dependencies from Pipfile...');
309 } else if (originKind === PythonManifestConvertedKind.PipfileLock) {
310 console.log('Installing required dependencies from Pipfile.lock...');
311 } else if (
312 originKind === PythonManifestConvertedKind.RequirementsTxt ||
313 originKind === PythonManifestConvertedKind.RequirementsIn
314 ) {
315 console.log(
316 `Installing required dependencies from ${manifest.origin?.path ?? 'requirements.txt'}...`
317 );

Callers 1

buildFunction · 0.90

Calls 7

stringifyManifestFunction · 0.90
createMinimalManifestFunction · 0.90
detectInstallSourceFunction · 0.85
restoreCachedLockFunction · 0.85
existsSyncMethod · 0.45
logMethod · 0.45
lockMethod · 0.45

Tested by

no test coverage detected