MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / includedRouter

Function includedRouter

src/resolution/frameworks/python.ts:410–429  ·  view source on GitHub ↗

* The file and variable an `include_router` argument names: `items.router` * through the module's import, `items_router` through an alias import, or a * router defined in the same file.

(
  expr: string,
  file: string,
  local: Map<string, string>,
  context: ResolutionContext
)

Source from the content-addressed store, hash-verified

408 * router defined in the same file.
409 */
410function includedRouter(
411 expr: string,
412 file: string,
413 local: Map<string, string>,
414 context: ResolutionContext
415): { file: string; variable: string } | null {
416 const segs = expr.split('.');
417 const head = segs[0]!;
418 if (segs.length === 1 && local.has(head)) return { file, variable: head };
419 const mapping = context.getImportMappings(file, 'python').find((im) => im.localName === head);
420 if (!mapping) return null;
421 if (segs.length > 1) {
422 // `items.router`: `items` is a module — `from app.api.routes import items`.
423 const moduleFile = resolveImportPath(`${mapping.source}.${mapping.exportedName}`, file, 'python', context) ?? resolveImportPath(mapping.source, file, 'python', context);
424 return moduleFile ? { file: moduleFile, variable: segs[segs.length - 1]! } : null;
425 }
426 // `items_router`: `from .items import router as items_router`.
427 const moduleFile = resolveImportPath(mapping.source, file, 'python', context);
428 return moduleFile ? { file: moduleFile, variable: mapping.exportedName } : null;
429}
430
431interface DecoratorRouteOpts {
432 decoratorRegex: RegExp;

Callers 1

postExtractFunction · 0.85

Calls 3

resolveImportPathFunction · 0.90
hasMethod · 0.80
getImportMappingsMethod · 0.80

Tested by

no test coverage detected