MCPcopy Index your code
hub / github.com/python/mypy / generate_c

Function generate_c

mypyc/build.py:301–353  ·  view source on GitHub ↗

Drive the actual core compilation step. The groups argument describes how modules are assigned to C extension modules. See the comments on the Groups type in mypyc.emitmodule for details. Returns the C source code, (for debugging) the pretty printed IR, and list of SourceDeps.

(
    sources: list[BuildSource],
    options: Options,
    groups: emitmodule.Groups,
    fscache: FileSystemCache,
    compiler_options: CompilerOptions,
)

Source from the content-addressed store, hash-verified

299
300
301def generate_c(
302 sources: list[BuildSource],
303 options: Options,
304 groups: emitmodule.Groups,
305 fscache: FileSystemCache,
306 compiler_options: CompilerOptions,
307) -> tuple[list[list[tuple[str, str]]], str, list[SourceDep]]:
308 """Drive the actual core compilation step.
309
310 The groups argument describes how modules are assigned to C
311 extension modules. See the comments on the Groups type in
312 mypyc.emitmodule for details.
313
314 Returns the C source code, (for debugging) the pretty printed IR, and list of SourceDeps.
315 """
316 t0 = time.time()
317
318 try:
319 result = emitmodule.parse_and_typecheck(
320 sources, options, compiler_options, groups, fscache
321 )
322 except CompileError as e:
323 emit_messages(options, e.messages, time.time() - t0, serious=(not e.use_stdout))
324 sys.exit(1)
325
326 t1 = time.time()
327 if result.errors:
328 emit_messages(options, result.errors, t1 - t0)
329 sys.exit(1)
330
331 if compiler_options.verbose:
332 print(f"Parsed and typechecked in {t1 - t0:.3f}s")
333
334 errors = Errors(options)
335 modules, ctext, mapper = emitmodule.compile_modules_to_c(
336 result, compiler_options=compiler_options, errors=errors, groups=groups
337 )
338 t2 = time.time()
339 emit_messages(options, errors.new_messages(), t2 - t1)
340 if errors.num_errors:
341 # No need to stop the build if only warnings were emitted.
342 sys.exit(1)
343
344 if compiler_options.verbose:
345 print(f"Compiled to C in {t2 - t1:.3f}s")
346
347 if options.mypyc_annotation_file:
348 generate_annotated_html(options.mypyc_annotation_file, result, modules, mapper)
349
350 # Collect SourceDep dependencies
351 source_deps = sorted(emitmodule.collect_source_dependencies(modules), key=lambda d: d.path)
352
353 return ctext, "\n".join(format_modules(modules)), source_deps
354
355
356def build_using_shared_lib(

Callers 1

mypyc_buildFunction · 0.85

Calls 9

new_messagesMethod · 0.95
ErrorsClass · 0.90
generate_annotated_htmlFunction · 0.90
format_modulesFunction · 0.90
emit_messagesFunction · 0.85
printFunction · 0.85
sortedFunction · 0.85
exitMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…