From ed9ebca5b0c012c6b44adad4efa475f1cccd460d Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 10 Mar 2012 19:03:23 -0800 Subject: Indent with spaces --HG-- branch : distribute extra : rebase_source : 799441b639f6f9c55fe25745e793ac29419f0293 --- setuptools/extension.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'setuptools/extension.py') diff --git a/setuptools/extension.py b/setuptools/extension.py index 980ee0a7..b5a0702b 100644 --- a/setuptools/extension.py +++ b/setuptools/extension.py @@ -5,12 +5,12 @@ _Extension = _get_unpatched(_Extension) # Prefer Cython to Pyrex pyrex_impls = 'Cython.Distutils.build_ext', 'Pyrex.Distutils.build_ext' for pyrex_impl in pyrex_impls: - try: - # from (pyrex_impl) import build_ext - build_ext = __import__(pyrex_impl, fromlist=['build_ext']).build_ext - break - except: - pass + try: + # from (pyrex_impl) import build_ext + build_ext = __import__(pyrex_impl, fromlist=['build_ext']).build_ext + break + except: + pass have_pyrex = 'build_ext' in globals() @@ -18,7 +18,7 @@ class Extension(_Extension): """Extension that uses '.c' files in place of '.pyx' files""" if not have_pyrex: - # convert .pyx extensions to .c + # convert .pyx extensions to .c def __init__(self,*args,**kw): _Extension.__init__(self,*args,**kw) sources = [] -- cgit v1.2.1 From 5e47a200c412793a2878e3df57f29e854e2e9356 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 10 Mar 2012 19:21:15 -0800 Subject: Reorganized imports --HG-- branch : distribute extra : rebase_source : 3c54aa84f71220021b92f890359546b4ff41e5f6 --- setuptools/extension.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'setuptools/extension.py') diff --git a/setuptools/extension.py b/setuptools/extension.py index b5a0702b..e87494ad 100644 --- a/setuptools/extension.py +++ b/setuptools/extension.py @@ -1,6 +1,10 @@ -from distutils.core import Extension as _Extension +import sys +import distutils.core +import distutils.extension + from setuptools.dist import _get_unpatched -_Extension = _get_unpatched(_Extension) + +_Extension = _get_unpatched(distutils.core.Extension) # Prefer Cython to Pyrex pyrex_impls = 'Cython.Distutils.build_ext', 'Pyrex.Distutils.build_ext' @@ -19,12 +23,12 @@ class Extension(_Extension): if not have_pyrex: # convert .pyx extensions to .c - def __init__(self,*args,**kw): - _Extension.__init__(self,*args,**kw) + def __init__(self, *args, **kw): + _Extension.__init__(self, *args, **kw) sources = [] for s in self.sources: if s.endswith('.pyx'): - sources.append(s[:-3]+'c') + sources.append(s[:-3] + 'c') else: sources.append(s) self.sources = sources @@ -32,9 +36,7 @@ class Extension(_Extension): class Library(Extension): """Just like a regular Extension, but built as a library instead""" -import sys, distutils.core, distutils.extension distutils.core.Extension = Extension distutils.extension.Extension = Extension if 'distutils.command.build_ext' in sys.modules: sys.modules['distutils.command.build_ext'].Extension = Extension - -- cgit v1.2.1 From 9f5991b303d87d49479381b971652950f0cfdac1 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 10 Mar 2012 22:17:12 -0800 Subject: Refactored Extension class so that __init__ is always called, but patched behavior is still selected by has_pyrex. --HG-- branch : distribute extra : rebase_source : d5670bf4bc6606d828b4ec7be055e26a7d4a9730 --- setuptools/extension.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'setuptools/extension.py') diff --git a/setuptools/extension.py b/setuptools/extension.py index e87494ad..db563305 100644 --- a/setuptools/extension.py +++ b/setuptools/extension.py @@ -21,17 +21,15 @@ have_pyrex = 'build_ext' in globals() class Extension(_Extension): """Extension that uses '.c' files in place of '.pyx' files""" - if not have_pyrex: - # convert .pyx extensions to .c - def __init__(self, *args, **kw): - _Extension.__init__(self, *args, **kw) - sources = [] - for s in self.sources: - if s.endswith('.pyx'): - sources.append(s[:-3] + 'c') - else: - sources.append(s) - self.sources = sources + def __init__(self, *args, **kw): + _Extension.__init__(self, *args, **kw) + if not have_pyrex: + self._convert_pyx_sources_to_c() + + def _convert_pyx_sources_to_c(self): + "convert .pyx extensions to .c" + self.sources = [source[:-3] + 'c' for source in self.sources + if source.endswith('.pyx')] class Library(Extension): """Just like a regular Extension, but built as a library instead""" -- cgit v1.2.1 From 8633ffe737039044e955a6e5bd52ac08a0d83b37 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 10 Mar 2012 22:31:45 -0800 Subject: Converted have_pyrex into a function --HG-- branch : distribute extra : rebase_source : b676ea404118a121400f2fd1b67095ab4521b7a0 --- setuptools/extension.py | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) (limited to 'setuptools/extension.py') diff --git a/setuptools/extension.py b/setuptools/extension.py index db563305..eb8b836c 100644 --- a/setuptools/extension.py +++ b/setuptools/extension.py @@ -6,16 +6,19 @@ from setuptools.dist import _get_unpatched _Extension = _get_unpatched(distutils.core.Extension) -# Prefer Cython to Pyrex -pyrex_impls = 'Cython.Distutils.build_ext', 'Pyrex.Distutils.build_ext' -for pyrex_impl in pyrex_impls: - try: - # from (pyrex_impl) import build_ext - build_ext = __import__(pyrex_impl, fromlist=['build_ext']).build_ext - break - except: - pass -have_pyrex = 'build_ext' in globals() +def have_pyrex(): + """ + Return True if Cython or Pyrex can be imported. + """ + pyrex_impls = 'Cython.Distutils.build_ext', 'Pyrex.Distutils.build_ext' + for pyrex_impl in pyrex_impls: + try: + # from (pyrex_impl) import build_ext + __import__(pyrex_impl, fromlist=['build_ext']).build_ext + return True + except Exception: + pass + return False class Extension(_Extension): @@ -23,13 +26,16 @@ class Extension(_Extension): def __init__(self, *args, **kw): _Extension.__init__(self, *args, **kw) - if not have_pyrex: + if not have_pyrex(): self._convert_pyx_sources_to_c() def _convert_pyx_sources_to_c(self): "convert .pyx extensions to .c" - self.sources = [source[:-3] + 'c' for source in self.sources - if source.endswith('.pyx')] + def pyx_to_c(source): + if source.endswith('.pyx'): + source = source[:-4] + '.c' + return source + self.sources = map(pyx_to_c, self.sources) class Library(Extension): """Just like a regular Extension, but built as a library instead""" -- cgit v1.2.1