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

Function construct_groups

mypyc/build.py:517–566  ·  view source on GitHub ↗

Compute Groups given the input source list and separate configs. separate is the user-specified configuration for how to assign modules to compilation groups (see mypycify docstring for details). This takes that and expands it into our internal representation of group configuration

(
    sources: list[BuildSource],
    separate: bool | list[tuple[list[str], str | None]],
    use_shared_lib: bool,
    group_name_override: str | None,
)

Source from the content-addressed store, hash-verified

515
516
517def construct_groups(
518 sources: list[BuildSource],
519 separate: bool | list[tuple[list[str], str | None]],
520 use_shared_lib: bool,
521 group_name_override: str | None,
522) -> emitmodule.Groups:
523 """Compute Groups given the input source list and separate configs.
524
525 separate is the user-specified configuration for how to assign
526 modules to compilation groups (see mypycify docstring for details).
527
528 This takes that and expands it into our internal representation of
529 group configuration, documented in mypyc.emitmodule's definition
530 of Group.
531 """
532
533 if separate is True:
534 groups: emitmodule.Groups = [([source], None) for source in sources]
535 elif isinstance(separate, list):
536 groups = []
537 used_sources = set()
538 for files, name in separate:
539 normalized_files = {os.path.normpath(f) for f in files}
540 group_sources = [
541 src
542 for src in sources
543 if src.path is not None and os.path.normpath(src.path) in normalized_files
544 ]
545 groups.append((group_sources, name))
546 used_sources.update(group_sources)
547 unused_sources = [src for src in sources if src not in used_sources]
548 if unused_sources:
549 groups.extend([([source], None) for source in unused_sources])
550 else:
551 groups = [(sources, None)]
552
553 # Generate missing names.
554 # Sort the modules to make the compilation results consistent regardless of
555 # the source file order passed to mypycify.
556 for i, (group, name) in enumerate(groups):
557 group = sorted(group, key=lambda source: source.module)
558 if use_shared_lib and not name:
559 if group_name_override is not None:
560 name = group_name_override
561 else:
562 name = group_name([source.module for source in group])
563 groups[i] = (group, name)
564
565 groups = sorted(groups, key=lambda g: (g[1] or "", [s.module for s in g[0]]))
566 return groups
567
568
569def get_header_deps(cfiles: list[tuple[str, str]]) -> list[str]:

Calls 8

isinstanceFunction · 0.85
setClass · 0.85
enumerateFunction · 0.85
sortedFunction · 0.85
group_nameFunction · 0.85
appendMethod · 0.80
extendMethod · 0.80
updateMethod · 0.45

Used in the wild real call sites across dependent graphs

searching dependent graphs…