Skip to content

Commit

Permalink
Backport PR #3008: fix cython module so extension for multiarched python
Browse files Browse the repository at this point in the history
  • Loading branch information
minrk committed Mar 20, 2013
1 parent ddddf17 commit b510899
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions IPython/extensions/cythonmagic.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ def f(x):
ctx = Context(cython_include_dirs, default_options)
key = code, sys.version_info, sys.executable, Cython.__version__
module_name = "_cython_magic_" + hashlib.md5(str(key).encode('utf-8')).hexdigest()
so_ext = [ ext for ext,_,mod_type in imp.get_suffixes() if mod_type == imp.C_EXTENSION ][0]
module_path = os.path.join(lib_dir, module_name+so_ext)
module_path = os.path.join(lib_dir, module_name+self.so_ext)

if not os.path.exists(lib_dir):
os.makedirs(lib_dir)
Expand All @@ -173,15 +172,7 @@ def f(x):
extra_compile_args = args.compile_args,
libraries = args.lib,
)
dist = Distribution()
config_files = dist.find_config_files()
try:
config_files.remove('setup.cfg')
except ValueError:
pass
dist.parse_config_files(config_files)
build_extension = build_ext(dist)
build_extension.finalize_options()
build_extension = self._get_build_extension()
try:
build_extension.extensions = cythonize([extension], ctx=ctx, quiet=quiet)
except CompileError:
Expand All @@ -194,6 +185,27 @@ def f(x):
module = imp.load_dynamic(module_name, module_path)
self._import_all(module)

@property
def so_ext(self):
"""The extension suffix for compiled modules."""
try:
return self._so_ext
except AttributeError:
self._so_ext = self._get_build_extension().get_ext_filename('')
return self._so_ext

def _get_build_extension(self):
dist = Distribution()
config_files = dist.find_config_files()
try:
config_files.remove('setup.cfg')
except ValueError:
pass
dist.parse_config_files(config_files)
build_extension = build_ext(dist)
build_extension.finalize_options()
return build_extension


_loaded = False

Expand Down

0 comments on commit b510899

Please sign in to comment.