@@ -357,6 +357,7 @@ def construct_groups(
357357 sources : list [BuildSource ],
358358 separate : bool | list [tuple [list [str ], str | None ]],
359359 use_shared_lib : bool ,
360+ group_name_override : str | None ,
360361) -> emitmodule .Groups :
361362 """Compute Groups given the input source list and separate configs.
362363
@@ -386,7 +387,10 @@ def construct_groups(
386387 # Generate missing names
387388 for i , (group , name ) in enumerate (groups ):
388389 if use_shared_lib and not name :
389- name = group_name ([source .module for source in group ])
390+ if group_name_override is not None :
391+ name = group_name_override
392+ else :
393+ name = group_name ([source .module for source in group ])
390394 groups [i ] = (group , name )
391395
392396 return groups
@@ -432,7 +436,10 @@ def mypyc_build(
432436 or always_use_shared_lib
433437 )
434438
435- groups = construct_groups (mypyc_sources , separate , use_shared_lib )
439+ groups = construct_groups (mypyc_sources , separate , use_shared_lib , compiler_options .group_name )
440+
441+ if compiler_options .group_name is not None :
442+ assert len (groups ) == 1 , "If using custom group_name, only one group is expected"
436443
437444 # We let the test harness just pass in the c file contents instead
438445 # so that it can do a corner-cutting version without full stubs.
@@ -477,6 +484,7 @@ def mypycify(
477484 target_dir : str | None = None ,
478485 include_runtime_files : bool | None = None ,
479486 strict_dunder_typing : bool = False ,
487+ group_name : str | None = None ,
480488) -> list [Extension ]:
481489 """Main entry point to building using mypyc.
482490
@@ -519,6 +527,10 @@ def mypycify(
519527 strict_dunder_typing: If True, force dunder methods to have the return type
520528 of the method strictly, which can lead to more
521529 optimization opportunities. Defaults to False.
530+ group_name: If set, override the default group name derived from
531+ the hash of module names. This is used for the names of the
532+ output C files and the shared library. This is only supported
533+ if there is a single group. [Experimental]
522534 """
523535
524536 # Figure out our configuration
@@ -530,6 +542,7 @@ def mypycify(
530542 target_dir = target_dir ,
531543 include_runtime_files = include_runtime_files ,
532544 strict_dunder_typing = strict_dunder_typing ,
545+ group_name = group_name ,
533546 )
534547
535548 # Generate all the actual important C code
0 commit comments