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

Function pythonStarExports

src/resolution/import-resolver.ts:1192–1226  ·  view source on GitHub ↗
(filePath: string, context: ResolutionContext)

Source from the content-addressed store, hash-verified

1190const pythonStarExportMemos = new WeakMap<ResolutionContext, Map<string, Set<string> | null>>();
1191
1192function pythonStarExports(filePath: string, context: ResolutionContext): Set<string> | null {
1193 let memo = pythonStarExportMemos.get(context);
1194 if (!memo) {
1195 memo = new Map();
1196 pythonStarExportMemos.set(context, memo);
1197 }
1198 if (memo.has(filePath)) return memo.get(filePath)!;
1199 let names: Set<string> | null = null;
1200 const content = context.readFile(filePath);
1201 if (content && content.includes('__all__')) {
1202 // Locate every statement that builds `__all__` on blanked source (so a
1203 // docstring mention is ignored), then read the literals from the original
1204 // at the same offsets. Only a list written out in full is trusted: one
1205 // assembled from other names (`__all__ = fields_all + [...]`,
1206 // `__all__.extend(...)`) is unknown, and falls back to the public names.
1207 const code = stripCommentsForRegex(content, 'python');
1208 let literal = true;
1209 const collected = new Set<string>();
1210 for (const m of code.matchAll(/^[ \t]*__all__\b[ \t]*(\.|\+=|=|:[^=\n]*=)?[ \t]*(.?)/gm)) {
1211 const open = m.index! + m[0].length - 1;
1212 const bracket = m[2];
1213 const close = bracket === '[' ? code.indexOf(']', open) : bracket === '(' ? code.indexOf(')', open) : -1;
1214 const assigns = m[1] !== undefined && m[1] !== '.';
1215 const tail = close < 0 ? '' : code.slice(close + 1, code.indexOf('\n', close) < 0 ? undefined : code.indexOf('\n', close));
1216 if (!assigns || close < 0 || tail.trim() !== '') {
1217 literal = false;
1218 break;
1219 }
1220 for (const lit of content.slice(open, close).matchAll(/["']([A-Za-z_]\w*)["']/g)) collected.add(lit[1]!);
1221 }
1222 if (literal && collected.size > 0) names = collected;
1223 }
1224 memo.set(filePath, names);
1225 return names;
1226}
1227
1228function pythonStarAllows(filePath: string, name: string, context: ResolutionContext): boolean {
1229 const names = pythonStarExports(filePath, context);

Callers 1

pythonStarAllowsFunction · 0.85

Calls 6

stripCommentsForRegexFunction · 0.90
hasMethod · 0.80
getMethod · 0.65
readFileMethod · 0.65
setMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected