File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -729,7 +729,7 @@ def get_export_symbols(self, ext):
729
729
provided, "PyInit_" + module_name. Only relevant on Windows, where
730
730
the .pyd file (DLL) must export the module "PyInit_" function.
731
731
"""
732
- name = ext . name . split ( '.' )[ - 1 ]
732
+ name = self . _get_module_name_for_symbol ( ext )
733
733
try :
734
734
# Unicode module name support as defined in PEP-489
735
735
# https://peps.python.org/pep-0489/#export-hook-name
@@ -744,6 +744,15 @@ def get_export_symbols(self, ext):
744
744
ext .export_symbols .append (initfunc_name )
745
745
return ext .export_symbols
746
746
747
+ def _get_module_name_for_symbol (self , ext ):
748
+ # Package name should be used for `__init__` modules
749
+ # https://github.com/python/cpython/issues/80074
750
+ # https://github.com/pypa/setuptools/issues/4826
751
+ parts = ext .name .split ("." )
752
+ if parts [- 1 ] == "__init__" and len (parts ) >= 2 :
753
+ return parts [- 2 ]
754
+ return parts [- 1 ]
755
+
747
756
def get_libraries (self , ext ): # noqa: C901
748
757
"""Return the list of libraries to link against when building a
749
758
shared extension. On most platforms, this is just 'ext.libraries';
Original file line number Diff line number Diff line change @@ -345,6 +345,19 @@ def test_unicode_module_names(self):
345
345
assert cmd .get_export_symbols (modules [0 ]) == ['PyInit_foo' ]
346
346
assert cmd .get_export_symbols (modules [1 ]) == ['PyInitU_f_1gaa' ]
347
347
348
+ def test_export_symbols__init__ (self ):
349
+ # https://github.com/python/cpython/issues/80074
350
+ # https://github.com/pypa/setuptools/issues/4826
351
+ modules = [
352
+ Extension ('foo.__init__' , ['aaa' ]),
353
+ Extension ('föö.__init__' , ['uuu' ]),
354
+ ]
355
+ dist = Distribution ({'name' : 'xx' , 'ext_modules' : modules })
356
+ cmd = self .build_ext (dist )
357
+ cmd .ensure_finalized ()
358
+ assert cmd .get_export_symbols (modules [0 ]) == ['PyInit_foo' ]
359
+ assert cmd .get_export_symbols (modules [1 ]) == ['PyInitU_f_1gaa' ]
360
+
348
361
def test_compiler_option (self ):
349
362
# cmd.compiler is an option and
350
363
# should not be overridden by a compiler instance
You can’t perform that action at this time.
0 commit comments