MCPcopy
hub / github.com/PyGithub/PyGithub / index

Method index

scripts/openapi.py:2251–2403  ·  view source on GitHub ↗
(
        self, github_path: str, spec_file: str | None, index_filename: str, check_verbs: bool, dry_run: bool
    )

Source from the content-addressed store, hash-verified

2249 return True
2250
2251 def index(
2252 self, github_path: str, spec_file: str | None, index_filename: str, check_verbs: bool, dry_run: bool
2253 ) -> bool:
2254 import multiprocessing
2255
2256 config = {}
2257 config_file = Path(github_path) / "openapi.index.json"
2258 if config_file.exists():
2259 with config_file.open("r") as r:
2260 ignored_schemas = json.load(r).get("ignored OpenAPI schemas", [])
2261 config["ignored_schemas"] = ignored_schemas
2262
2263 files = [f for f in listdir(github_path) if isfile(join(github_path, f)) and f.endswith(".py")]
2264 print(f"Indexing {len(files)} Python files")
2265
2266 # index files in parallel
2267 with multiprocessing.Manager() as manager:
2268 classes = manager.dict()
2269 paths = manager.list()
2270 if check_verbs and not config_file.exists():
2271 raise RuntimeError(f"Cannot check verbs without config: {config_file}")
2272 indexer = IndexFileWorker(classes, config_file, paths, check_verbs)
2273 with multiprocessing.Pool() as pool:
2274 pool.map(indexer.index_file, iterable=[join(github_path, file) for file in files])
2275 classes = dict(classes)
2276 paths = merge_paths(paths)
2277
2278 # construct inheritance list
2279 while self.extend_inheritance(classes):
2280 pass
2281
2282 # propagate ids of base classes to derived classes
2283 while self.propagate_ids(classes):
2284 pass
2285
2286 # construct class_to_descendants
2287 class_to_descendants = {}
2288 for name, descendant in classes.items():
2289 for cls in descendant.get("inheritance", []):
2290 if cls not in class_to_descendants:
2291 class_to_descendants[cls] = []
2292 class_to_descendants[cls].append(name)
2293 class_to_descendants = {cls: sorted(descendants) for cls, descendants in class_to_descendants.items()}
2294
2295 # add schemas of base classes to derived classes
2296 for name, clazz in sorted(classes.items(), key=lambda v: v[0]):
2297 schemas = clazz.get("schemas")
2298 if not schemas:
2299 continue
2300
2301 for derived in class_to_descendants.get(name, []):
2302 if derived in classes:
2303 derived_schemas = classes[derived].get("inherited_schemas", [])
2304 for schema in schemas:
2305 if schema not in derived_schemas:
2306 derived_schemas.append(schema)
2307 classes[derived]["inherited_schemas"] = derived_schemas
2308

Callers 5

create_classMethod · 0.95
mainMethod · 0.95
get_schemaMethod · 0.80
get_base_classesFunction · 0.80

Calls 11

extend_inheritanceMethod · 0.95
propagate_idsMethod · 0.95
get_spec_typesMethod · 0.95
PathClass · 0.85
IndexFileWorkerClass · 0.85
merge_pathsFunction · 0.85
openMethod · 0.80
getMethod · 0.80
loadMethod · 0.80
dumpMethod · 0.80
readMethod · 0.45

Tested by

no test coverage detected