({
entrypointDir,
rootDir,
}: {
entrypointDir: string;
rootDir: string;
})
| 225 | * // pkg.requiresPython contains Python version constraints |
| 226 | */ |
| 227 | export async function discoverPythonPackage({ |
| 228 | entrypointDir, |
| 229 | rootDir, |
| 230 | }: { |
| 231 | entrypointDir: string; |
| 232 | rootDir: string; |
| 233 | }): Promise<PythonPackage> { |
| 234 | const entrypointPath = normalizePath(entrypointDir); |
| 235 | const rootPath = normalizePath(rootDir); |
| 236 | let prefix = path.relative(rootPath, entrypointPath); |
| 237 | if (prefix.startsWith('..')) { |
| 238 | throw new PythonAnalysisError({ |
| 239 | message: 'Entrypoint directory outside of repository root', |
| 240 | code: 'PYTHON_INVALID_ENTRYPOINT_PATH', |
| 241 | }); |
| 242 | } |
| 243 | const manifests: PythonManifest[] = []; |
| 244 | let configs: PythonConfigs[] = []; |
| 245 | |
| 246 | for (;;) { |
| 247 | const prefixConfigs = await loadPythonConfigs(rootPath, prefix); |
| 248 | if (Object.keys(prefixConfigs).length !== 0) { |
| 249 | configs.push(prefixConfigs); |
| 250 | } |
| 251 | |
| 252 | const prefixManifest = await loadPythonManifest(rootPath, prefix); |
| 253 | if (prefixManifest != null) { |
| 254 | manifests.push(prefixManifest); |
| 255 | if (prefixManifest.isRoot) { |
| 256 | break; |
| 257 | } |
| 258 | } |
| 259 | if (prefix === '' || prefix === '.') { |
| 260 | break; |
| 261 | } |
| 262 | prefix = path.dirname(prefix); |
| 263 | } |
| 264 | |
| 265 | let entrypointManifest: PythonManifest | undefined; |
| 266 | let workspaceManifest: PythonManifest | undefined; |
| 267 | let workspaceLockFile: PythonLockFile | undefined; |
| 268 | |
| 269 | if (manifests.length === 0) { |
| 270 | // No Python manifests detected in the repo, but .python-version |
| 271 | // may still specify a version constraint. |
| 272 | const requiresPython = computeRequiresPython(undefined, undefined, configs); |
| 273 | return { |
| 274 | configs, |
| 275 | requiresPython, |
| 276 | }; |
| 277 | } else { |
| 278 | entrypointManifest = manifests[0]; |
| 279 | const entrypointWorkspaceManifest = findWorkspaceManifestFor( |
| 280 | entrypointManifest, |
| 281 | manifests |
| 282 | ); |
| 283 | workspaceManifest = entrypointWorkspaceManifest; |
| 284 | // Propagate workspace lock file from workspace root manifest |
no test coverage detected