({
workPath,
rootDir,
venvPath,
pythonPackage,
pythonVersion,
uv,
requireBinaryWheels = false,
cachedLockPath,
}: EnsureUvProjectParams)
| 258 | } |
| 259 | |
| 260 | export 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 | ); |
no test coverage detected