aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2014-03-10 08:19:09 -0400
committerJason R. Coombs <jaraco@jaraco.com>2014-03-10 08:19:09 -0400
commit261a4ed096f5be63d138eadc31361038b0b515fd (patch)
tree1b749577f7384afb2531f5e0cdf82ba7acb8365a
parent158b463e715d0f4c752df1c9e138e630718e74fa (diff)
downloadexternal_python_setuptools-261a4ed096f5be63d138eadc31361038b0b515fd.tar.gz
external_python_setuptools-261a4ed096f5be63d138eadc31361038b0b515fd.tar.bz2
external_python_setuptools-261a4ed096f5be63d138eadc31361038b0b515fd.zip
Use a single method to handle both languages.
-rw-r--r--CHANGES.txt6
-rw-r--r--setuptools/extension.py34
2 files changed, 21 insertions, 19 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 68a36996..ca1bd00c 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -3,6 +3,12 @@ CHANGES
=======
---
+3.2
+---
+
+* Pull Request #39: Add support for C++ targets from Cython ``.pyx`` files.
+
+---
3.1
---
diff --git a/setuptools/extension.py b/setuptools/extension.py
index b72f6e2a..06ec1cec 100644
--- a/setuptools/extension.py
+++ b/setuptools/extension.py
@@ -26,27 +26,23 @@ class Extension(_Extension):
def __init__(self, *args, **kw):
_Extension.__init__(self, *args, **kw)
- if not have_pyrex():
- if self.language.lower() == 'c++':
- self._convert_pyx_sources_to_cpp()
- else:
- self._convert_pyx_sources_to_c()
-
- def _convert_pyx_sources_to_cpp(self):
- "convert .pyx extensions to .cpp"
- def pyx_to_c(source):
+ self._convert_pyx_sources_to_lang()
+
+ def _convert_pyx_sources_to_lang(self):
+ """
+ Replace sources with .pyx extensions to sources with the target
+ language extension. This mechanism allows language authors to supply
+ pre-converted sources but to prefer the .pyx sources.
+ """
+ if have_pyrex():
+ # the build has Cython, so allow it to compile the .pyx files
+ return
+ def pyx_to_target(source):
+ target_ext = '.cpp' if self.language.lower() == 'c++' else '.c'
if source.endswith('.pyx'):
- source = source[:-4] + '.cpp'
+ source = source[:-4] + target_ext
return source
- self.sources = list(map(pyx_to_c, self.sources))
-
- def _convert_pyx_sources_to_c(self):
- "convert .pyx extensions to .c"
- def pyx_to_c(source):
- if source.endswith('.pyx'):
- source = source[:-4] + '.c'
- return source
- self.sources = list(map(pyx_to_c, self.sources))
+ self.sources = list(map(pyx_to_target, self.sources))
class Library(Extension):
"""Just like a regular Extension, but built as a library instead"""