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

Function compile_modules_to_c

mypyc/codegen/emitmodule.py:515–552  ·  view source on GitHub ↗

Compile Python module(s) to the source of Python C extension modules. This generates the source code for the "shared library" module for each group. The shim modules are generated in mypyc.build. Each shared library module provides, for each module in its group, a PyCapsule containi

(
    result: BuildResult, compiler_options: CompilerOptions, errors: Errors, groups: Groups
)

Source from the content-addressed store, hash-verified

513
514
515def compile_modules_to_c(
516 result: BuildResult, compiler_options: CompilerOptions, errors: Errors, groups: Groups
517) -> tuple[ModuleIRs, list[FileContents], Mapper]:
518 """Compile Python module(s) to the source of Python C extension modules.
519
520 This generates the source code for the "shared library" module
521 for each group. The shim modules are generated in mypyc.build.
522 Each shared library module provides, for each module in its group,
523 a PyCapsule containing an initialization function.
524 Additionally, it provides a capsule containing an export table of
525 pointers to all the group's functions and static variables.
526
527 Arguments:
528 result: The BuildResult from the mypy front-end
529 compiler_options: The compilation options
530 errors: Where to report any errors encountered
531 groups: The groups that we are compiling. See documentation of Groups type above.
532
533 Returns the IR of the modules and a list containing the generated files for each group.
534 """
535 # Construct a map from modules to what group they belong to
536 group_map = {source.module: lib_name for group, lib_name in groups for source in group}
537 mapper = Mapper(group_map)
538
539 # Sometimes when we call back into mypy, there might be errors.
540 # We don't want to crash when that happens.
541 result.manager.errors.set_file(
542 "<mypyc>", module=None, scope=None, options=result.manager.options
543 )
544
545 modules = compile_modules_to_ir(result, mapper, compiler_options, errors)
546 if errors.num_errors > 0:
547 return {}, [], Mapper({})
548
549 ctext = compile_ir_to_c(groups, modules, result, mapper, compiler_options)
550 write_cache(modules, result, group_map, ctext)
551
552 return modules, [ctext[name] for _, name in groups], mapper
553
554
555def generate_function_declaration(fn: FuncIR, emitter: Emitter) -> None:

Callers

nothing calls this directly

Calls 5

MapperClass · 0.90
compile_modules_to_irFunction · 0.85
compile_ir_to_cFunction · 0.85
set_fileMethod · 0.80
write_cacheFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…