Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions mypyc/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ def construct_groups(
sources: list[BuildSource],
separate: bool | list[tuple[list[str], str | None]],
use_shared_lib: bool,
group_name_override: str | None,
) -> emitmodule.Groups:
"""Compute Groups given the input source list and separate configs.

Expand Down Expand Up @@ -386,7 +387,10 @@ def construct_groups(
# Generate missing names
for i, (group, name) in enumerate(groups):
if use_shared_lib and not name:
name = group_name([source.module for source in group])
if group_name_override is not None:
name = group_name_override
else:
name = group_name([source.module for source in group])
groups[i] = (group, name)

return groups
Expand Down Expand Up @@ -432,7 +436,10 @@ def mypyc_build(
or always_use_shared_lib
)

groups = construct_groups(mypyc_sources, separate, use_shared_lib)
groups = construct_groups(mypyc_sources, separate, use_shared_lib, compiler_options.group_name)

if compiler_options.group_name is not None:
assert len(groups) == 1, "If using custom group_name, only one group is expected"

# We let the test harness just pass in the c file contents instead
# so that it can do a corner-cutting version without full stubs.
Expand Down Expand Up @@ -477,6 +484,7 @@ def mypycify(
target_dir: str | None = None,
include_runtime_files: bool | None = None,
strict_dunder_typing: bool = False,
group_name: str | None = None,
) -> list[Extension]:
"""Main entry point to building using mypyc.

Expand Down Expand Up @@ -519,6 +527,10 @@ def mypycify(
strict_dunder_typing: If True, force dunder methods to have the return type
of the method strictly, which can lead to more
optimization opportunities. Defaults to False.
group_name: If set, override the default group name derived from
the hash of module names. This is used for the names of the
output C files and the shared library. This is only supported
if there is a single group. [Experimental]
"""

# Figure out our configuration
Expand All @@ -530,6 +542,7 @@ def mypycify(
target_dir=target_dir,
include_runtime_files=include_runtime_files,
strict_dunder_typing=strict_dunder_typing,
group_name=group_name,
)

# Generate all the actual important C code
Expand Down
7 changes: 7 additions & 0 deletions mypyc/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def __init__(
capi_version: tuple[int, int] | None = None,
python_version: tuple[int, int] | None = None,
strict_dunder_typing: bool = False,
group_name: str | None = None,
) -> None:
self.strip_asserts = strip_asserts
self.multi_file = multi_file
Expand All @@ -38,3 +39,9 @@ def __init__(
# will assume the return type of the method strictly, which can lead to
# more optimization opportunities.
self.strict_dunders_typing = strict_dunder_typing
# Override the automatic group name derived from the hash of module names.
# This affects the names of generated .c, .h and shared library files.
# This is only supported when compiling exactly one group, and a shared
# library is generated (with shims). This can be used to make the output
# file names more predictable.
self.group_name = group_name
2 changes: 1 addition & 1 deletion mypyc/test/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def run_case_step(self, testcase: DataDrivenTestCase, incremental_step: int) ->
else False
)

groups = construct_groups(sources, separate, len(module_names) > 1)
groups = construct_groups(sources, separate, len(module_names) > 1, None)

try:
compiler_options = CompilerOptions(
Expand Down