From 8dfa58696aff81a6fa7ab2d10d859610711fdb49 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Mon, 10 Mar 2014 08:26:10 -0400 Subject: Use functools.partial and re.sub to construct the substitution function. --- setuptools/extension.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'setuptools/extension.py') diff --git a/setuptools/extension.py b/setuptools/extension.py index d8516092..ab5908da 100644 --- a/setuptools/extension.py +++ b/setuptools/extension.py @@ -1,4 +1,6 @@ import sys +import re +import functools import distutils.core import distutils.extension @@ -37,13 +39,10 @@ class Extension(_Extension): if have_pyrex(): # the build has Cython, so allow it to compile the .pyx files return - def pyx_to_target(source): - lang = self.language or '' - target_ext = '.cpp' if lang.lower() == 'c++' else '.c' - if source.endswith('.pyx'): - source = source[:-4] + target_ext - return source - self.sources = list(map(pyx_to_target, self.sources)) + lang = self.language or '' + target_ext = '.cpp' if lang.lower() == 'c++' else '.c' + sub = functools.partial(re.sub, '.pyx$', target_ext) + self.sources = list(map(sub, self.sources)) class Library(Extension): """Just like a regular Extension, but built as a library instead""" -- cgit v1.2.1