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

Function discoverPythonPackage

packages/python-analysis/src/manifest/package.ts:227–311  ·  view source on GitHub ↗
({
  entrypointDir,
  rootDir,
}: {
  entrypointDir: string;
  rootDir: string;
})

Source from the content-addressed store, hash-verified

225 * // pkg.requiresPython contains Python version constraints
226 */
227export 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

Callers 2

discoverPackageFunction · 0.90
package.test.tsFile · 0.90

Calls 10

normalizePathFunction · 0.90
isSubpathFunction · 0.90
loadPythonConfigsFunction · 0.85
loadPythonManifestFunction · 0.85
computeRequiresPythonFunction · 0.85
findWorkspaceManifestForFunction · 0.85
filterMethod · 0.80
pushMethod · 0.65
keysMethod · 0.45
valuesMethod · 0.45

Tested by

no test coverage detected