@@ -116,26 +116,6 @@ def get_mypy_config(mypy_options: List[str],
116116 return mypyc_sources , all_sources , options
117117
118118
119- shim_template = """\
120- #include <Python.h>
121-
122- PyMODINIT_FUNC
123- PyInit_{modname}(void)
124- {{
125- if (!PyImport_ImportModule("{libname}")) return NULL;
126- void *init_func = PyCapsule_Import("{libname}.init_{full_modname}", 0);
127- if (!init_func) {{
128- return NULL;
129- }}
130- return ((PyObject *(*)(void))init_func)();
131- }}
132-
133- // distutils sometimes spuriously tells cl to export CPyInit___init__,
134- // so provide that so it chills out
135- PyMODINIT_FUNC PyInit___init__(void) {{ return PyInit_{modname}(); }}
136- """
137-
138-
139119def generate_c_extension_shim (
140120 full_module_name : str , module_name : str , dir_name : str , group_name : str ) -> str :
141121 """Create a C extension shim with a passthrough PyInit function.
@@ -149,6 +129,11 @@ def generate_c_extension_shim(
149129 cname = '%s.c' % exported_name (full_module_name )
150130 cpath = os .path .join (dir_name , cname )
151131
132+ # We load the C extension shim template from a file.
133+ # (So that the file could be reused as a bazel template also.)
134+ with open (os .path .join (include_dir (), 'module_shim.tmpl' )) as f :
135+ shim_template = f .read ()
136+
152137 write_file (
153138 cpath ,
154139 shim_template .format (modname = module_name ,
0 commit comments