| 43 | } |
| 44 | |
| 45 | async function uvToRequirements(pluginInstance) { |
| 46 | const { servicePath, options, serverless, log, progress } = pluginInstance |
| 47 | |
| 48 | if (!options.useUv) return |
| 49 | |
| 50 | const moduleProjectPath = servicePath |
| 51 | const uvLockPath = path.join(moduleProjectPath, 'uv.lock') |
| 52 | if (!fse.existsSync(uvLockPath)) return |
| 53 | |
| 54 | let generateRequirementsProgress |
| 55 | if (progress && log) { |
| 56 | generateRequirementsProgress = progress.get( |
| 57 | 'python-generate-requirements-uv', |
| 58 | ) |
| 59 | generateRequirementsProgress.update( |
| 60 | 'Generating requirements.txt from uv.lock', |
| 61 | ) |
| 62 | log.info('Generating requirements.txt from uv.lock') |
| 63 | } else { |
| 64 | serverless.cli.log('Generating requirements.txt from uv.lock...') |
| 65 | } |
| 66 | |
| 67 | try { |
| 68 | await getUvVersion(pluginInstance) |
| 69 | fse.ensureDirSync(path.join(servicePath, '.serverless')) |
| 70 | const outPath = path.join(servicePath, '.serverless', 'requirements.txt') |
| 71 | const args = [ |
| 72 | 'export', |
| 73 | '--no-dev', |
| 74 | '--frozen', |
| 75 | '--no-hashes', |
| 76 | '--no-emit-project', |
| 77 | '-o', |
| 78 | outPath, |
| 79 | ...(options.uvOptionalDependencies.length |
| 80 | ? options.uvOptionalDependencies.flatMap((group) => ['--extra', group]) |
| 81 | : []), |
| 82 | ...(options.uvWithGroups.length |
| 83 | ? options.uvWithGroups.flatMap((group) => ['--group', group]) |
| 84 | : []), |
| 85 | ...(options.uvWithoutGroups.length |
| 86 | ? options.uvWithoutGroups.flatMap((group) => ['--no-group', group]) |
| 87 | : []), |
| 88 | ...(options.uvOnlyGroups.length |
| 89 | ? options.uvOnlyGroups.flatMap((group) => ['--only-group', group]) |
| 90 | : []), |
| 91 | ] |
| 92 | |
| 93 | await spawn('uv', args, { cwd: moduleProjectPath }) |
| 94 | } finally { |
| 95 | generateRequirementsProgress && generateRequirementsProgress.remove() |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | export { uvToRequirements, getUvVersion } |