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

Function includedRouter

src/resolution/frameworks/python.ts:411–430  ·  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

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

Callers 1

postExtractFunction · 0.85

Calls 3

resolveImportPathFunction · 0.90
hasMethod · 0.80
getImportMappingsMethod · 0.80

Tested by

no test coverage detected