Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b510899

Browse files
committed
Backport PR ipython#3008: fix cython module so extension for multiarched python
backported from a1daa02 see http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=697704
1 parent ddddf17 commit b510899

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

IPython/extensions/cythonmagic.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,7 @@ def f(x):
151151
ctx = Context(cython_include_dirs, default_options)
152152
key = code, sys.version_info, sys.executable, Cython.__version__
153153
module_name = "_cython_magic_" + hashlib.md5(str(key).encode('utf-8')).hexdigest()
154-
so_ext = [ ext for ext,_,mod_type in imp.get_suffixes() if mod_type == imp.C_EXTENSION ][0]
155-
module_path = os.path.join(lib_dir, module_name+so_ext)
154+
module_path = os.path.join(lib_dir, module_name+self.so_ext)
156155

157156
if not os.path.exists(lib_dir):
158157
os.makedirs(lib_dir)
@@ -173,15 +172,7 @@ def f(x):
173172
extra_compile_args = args.compile_args,
174173
libraries = args.lib,
175174
)
176-
dist = Distribution()
177-
config_files = dist.find_config_files()
178-
try:
179-
config_files.remove('setup.cfg')
180-
except ValueError:
181-
pass
182-
dist.parse_config_files(config_files)
183-
build_extension = build_ext(dist)
184-
build_extension.finalize_options()
175+
build_extension = self._get_build_extension()
185176
try:
186177
build_extension.extensions = cythonize([extension], ctx=ctx, quiet=quiet)
187178
except CompileError:
@@ -194,6 +185,27 @@ def f(x):
194185
module = imp.load_dynamic(module_name, module_path)
195186
self._import_all(module)
196187

188+
@property
189+
def so_ext(self):
190+
"""The extension suffix for compiled modules."""
191+
try:
192+
return self._so_ext
193+
except AttributeError:
194+
self._so_ext = self._get_build_extension().get_ext_filename('')
195+
return self._so_ext
196+
197+
def _get_build_extension(self):
198+
dist = Distribution()
199+
config_files = dist.find_config_files()
200+
try:
201+
config_files.remove('setup.cfg')
202+
except ValueError:
203+
pass
204+
dist.parse_config_files(config_files)
205+
build_extension = build_ext(dist)
206+
build_extension.finalize_options()
207+
return build_extension
208+
197209

198210
_loaded = False
199211

0 commit comments

Comments
 (0)