@@ -125,13 +125,15 @@ def build_wheels(py_envs=DEFAULT_PY_ENVS, cleanup=True, cmake_options=[]):
125125 if cleanup :
126126 check_call ([python_executable , "setup.py" , "clean" ])
127127
128- def rename_wheel_init (py_env , filepath ):
128+ def rename_wheel_init (py_env , filepath , add_module_name = True ):
129129 """
130- Rename module __init__ file in wheel.
131- This is required to prevent modules to override ITK's __init__ file on install.
132- If the module ships its own __init__ file, it is automatically renamed to
133- __init_{module_name}__ by this function. The renamed __init__ file will be executed
134- by ITK's __init__ file when loading ITK.
130+ Rename module __init__ (if add_module_name is True) or __init_module__ (if
131+ add_module_name is False) file in wheel. This is required to prevent
132+ modules to override ITK's __init__ file on install or to prevent delvewheel
133+ to override __init_module__ file. If the module ships its own __init__
134+ file, it is automatically renamed to __init_{module_name}__ by this
135+ function. The renamed __init__ file will be executed by ITK's __init__ file
136+ when loading ITK.
135137 """
136138 python_executable , python_include_dir , python_library , pip , ninja_executable , path = venv_paths (py_env )
137139
@@ -145,11 +147,15 @@ def rename_wheel_init(py_env, filepath):
145147 wheel_dir = os .path .join (dist_dir , "itk_" + module_name .replace ('-' ,'_' ) + "-" + module_version )
146148 init_dir = os .path .join (wheel_dir , "itk" )
147149 init_file = os .path .join (init_dir , "__init__.py" )
150+ init_file_module = os .path .join (init_dir , "__init_" + module_name .split ("-" )[0 ] + "__.py" )
148151
149152 # Unpack wheel and rename __init__ file if it exists.
150153 check_call ([python_executable , "-m" , "wheel" , "unpack" , filepath , "-d" , dist_dir ])
151- if os .path .isfile (init_file ):
152- shutil .move (init_file , os .path .join (init_dir , "__init_" + module_name + "__.py" ))
154+ if add_module_name and os .path .isfile (init_file ):
155+ shutil .move (init_file , init_file_module )
156+ if not add_module_name and os .path .isfile (init_file_module ):
157+ shutil .move (init_file_module , init_file )
158+
153159 # Pack wheel and clean wheel folder
154160 check_call ([python_executable , "-m" , "wheel" , "pack" , wheel_dir , "-d" , dist_dir ])
155161 shutil .rmtree (wheel_dir )
@@ -160,6 +166,10 @@ def fixup_wheel(py_envs, filepath, lib_paths:str='', exclude_libs:str=''):
160166
161167 py_env = py_envs [0 ]
162168
169+ # Make sure the module __init_module__.py file has the expected name for
170+ # delvewheel, i.e., __init__.py.
171+ rename_wheel_init (py_env , filepath , False )
172+
163173 delve_wheel = os .path .join ("C:/P/IPP" , "venv-" + py_env , "Scripts" , "delvewheel.exe" )
164174 check_call ([delve_wheel , "repair" , "--no-mangle-all" , "--add-path" ,
165175 lib_paths , "--no-dll" , exclude_libs , "--ignore-in-wheel" , "-w" ,
0 commit comments