Skip to content

Commit b7453d6

Browse files
committed
Clean up
1 parent 8907b87 commit b7453d6

6 files changed

Lines changed: 16 additions & 23 deletions

File tree

mypyc/build.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
from mypyc.common import IS_FREE_THREADED, RUNTIME_C_FILES, shared_lib_name
4141
from mypyc.errors import Errors
4242
from mypyc.ir.deps import SourceDep
43-
from mypyc.ir.module_ir import ModuleIR
4443
from mypyc.ir.pprint import format_modules
4544
from mypyc.namegen import exported_name
4645
from mypyc.options import CompilerOptions
@@ -278,16 +277,6 @@ def include_dir() -> str:
278277
return os.path.join(os.path.abspath(os.path.dirname(__file__)), "lib-rt")
279278

280279

281-
def collect_source_dependencies(modules: dict[str, ModuleIR]) -> set[SourceDep]:
282-
"""Collect all SourceDep dependencies from all modules."""
283-
source_deps: set[SourceDep] = set()
284-
for module in modules.values():
285-
for dep in module.dependencies:
286-
if isinstance(dep, SourceDep):
287-
source_deps.add(dep)
288-
return source_deps
289-
290-
291280
def generate_c(
292281
sources: list[BuildSource],
293282
options: Options,
@@ -338,7 +327,7 @@ def generate_c(
338327
generate_annotated_html(options.mypyc_annotation_file, result, modules, mapper)
339328

340329
# Collect SourceDep dependencies
341-
source_deps = sorted(collect_source_dependencies(modules), key=lambda d: d.path)
330+
source_deps = sorted(emitmodule.collect_source_dependencies(modules), key=lambda d: d.path)
342331

343332
return ctext, "\n".join(format_modules(modules)), source_deps
344333

@@ -736,7 +725,7 @@ def mypycify(
736725
with open(os.path.join(include_dir(), name), encoding="utf-8") as f:
737726
write_file(rt_file, f.read())
738727
# Only add .c files to shared_cfilenames
739-
if name.endswith('.c'):
728+
if name.endswith(".c"):
740729
shared_cfilenames.append(rt_file)
741730

742731
extensions = []

mypyc/codegen/emitmodule.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,13 @@
2929
from mypy.util import hash_digest, json_dumps
3030
from mypyc.analysis.capsule_deps import find_implicit_op_dependencies
3131
from mypyc.codegen.cstring import c_string_initializer
32-
from mypyc.ir.deps import LIBRT_BASE64, LIBRT_STRINGS
33-
from mypyc.codegen.emit import Emitter, EmitterContext, HeaderDeclaration, c_array_initializer, native_function_doc_initializer
32+
from mypyc.codegen.emit import (
33+
Emitter,
34+
EmitterContext,
35+
HeaderDeclaration,
36+
c_array_initializer,
37+
native_function_doc_initializer,
38+
)
3439
from mypyc.codegen.emitclass import generate_class, generate_class_reuse, generate_class_type_decl
3540
from mypyc.codegen.emitfunc import generate_native_function, native_function_header
3641
from mypyc.codegen.emitwrapper import (
@@ -51,6 +56,7 @@
5156
short_id_from_name,
5257
)
5358
from mypyc.errors import Errors
59+
from mypyc.ir.deps import LIBRT_BASE64, LIBRT_STRINGS, SourceDep
5460
from mypyc.ir.func_ir import FuncIR
5561
from mypyc.ir.module_ir import ModuleIR, ModuleIRs, deserialize_modules
5662
from mypyc.ir.ops import DeserMaps, LoadLiteral
@@ -424,8 +430,6 @@ def load_scc_from_cache(
424430

425431
def collect_source_dependencies(modules: dict[str, ModuleIR]) -> set[SourceDep]:
426432
"""Collect all SourceDep dependencies from all modules."""
427-
from mypyc.ir.deps import SourceDep
428-
429433
source_deps: set[SourceDep] = set()
430434
for module in modules.values():
431435
for dep in module.dependencies:

mypyc/ir/deps.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Final, Union
1+
from typing import Final
22

33

44
class Capsule:
@@ -34,10 +34,10 @@ def __hash__(self) -> int:
3434

3535
def get_header(self) -> str:
3636
"""Get the header file path by replacing .c with .h"""
37-
return self.path.replace('.c', '.h')
37+
return self.path.replace(".c", ".h")
3838

3939

40-
Dependency = Union[Capsule, SourceDep]
40+
Dependency = Capsule | SourceDep
4141

4242

4343
LIBRT_STRINGS: Final = Capsule("librt.strings")

mypyc/ir/ops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class to enable the new behavior. Sometimes adding a new abstract
3131

3232
from mypy_extensions import trait
3333

34+
from mypyc.ir.deps import Dependency
3435
from mypyc.ir.rtypes import (
3536
RArray,
3637
RInstance,
@@ -55,7 +56,6 @@ class to enable the new behavior. Sometimes adding a new abstract
5556
short_int_rprimitive,
5657
void_rtype,
5758
)
58-
from mypyc.ir.deps import Dependency
5959

6060
if TYPE_CHECKING:
6161
from mypyc.codegen.literals import LiteralValue

mypyc/primitives/registry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@
3939

4040
from typing import Final, NamedTuple
4141

42+
from mypyc.ir.deps import Dependency
4243
from mypyc.ir.ops import PrimitiveDescription, StealsDescription
4344
from mypyc.ir.rtypes import RType
44-
from mypyc.ir.deps import Dependency
4545

4646
# Error kind for functions that return negative integer on exception. This
4747
# is only used for primitives. We translate it away during IR building.

mypyc/test/test_cheader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
import re
88
import unittest
99

10-
from mypyc.primitives import registry
1110
from mypyc.ir.deps import SourceDep
11+
from mypyc.primitives import registry
1212

1313

1414
class TestHeaderInclusion(unittest.TestCase):

0 commit comments

Comments
 (0)