7
7
8
8
import sh
9
9
import shutil
10
- from os import listdir , unlink , environ , mkdir , curdir
10
+ import fnmatch
11
+ from os import listdir , unlink , environ , mkdir , curdir , walk
11
12
from sys import stdout
12
13
try :
13
14
from urlparse import urlparse
@@ -895,6 +896,7 @@ def rebuild_compiled_components(self, arch, env):
895
896
class CythonRecipe (PythonRecipe ):
896
897
pre_build_ext = False
897
898
cythonize = True
899
+ cython_args = []
898
900
899
901
def __init__ (self , * args , ** kwargs ):
900
902
super (CythonRecipe , self ).__init__ (* args , ** kwargs )
@@ -945,18 +947,7 @@ def build_cython_components(self, arch):
945
947
manually_cythonise = True
946
948
947
949
if manually_cythonise :
948
- info ('Running cython where appropriate' )
949
- cyenv = env .copy ()
950
- if 'CYTHONPATH' in cyenv :
951
- cyenv ['PYTHONPATH' ] = cyenv ['CYTHONPATH' ]
952
- elif 'PYTHONPATH' in cyenv :
953
- del cyenv ['PYTHONPATH' ]
954
- cython = 'cython' if self .ctx .python_recipe .from_crystax else self .ctx .cython
955
- cython_cmd = 'find "{}" -iname *.pyx | xargs "{}"' .format (
956
- self .get_build_dir (arch .arch ), cython )
957
- shprint (sh .sh , '-c' , cython_cmd , _env = cyenv )
958
- info ('ran cython' )
959
-
950
+ self .cythonize_build (env = env )
960
951
shprint (hostpython , 'setup.py' , 'build_ext' , '-v' , _env = env ,
961
952
_tail = 20 , _critical = True , * self .setup_extra_args )
962
953
else :
@@ -969,20 +960,28 @@ def build_cython_components(self, arch):
969
960
env ['STRIP' ], '{}' , ';' , _env = env )
970
961
print ('stripped!?' )
971
962
972
- # def cythonize_file(self, filename):
973
- # if filename.startswith(self.build_dir):
974
- # filename = filename[len(self.build_dir) + 1:]
975
- # print("Cythonize {}".format(filename))
976
- # cmd = sh.Command(join(self.ctx.root_dir, "tools", "cythonize.py"))
977
- # shprint(cmd, filename)
978
-
979
- # def cythonize_build(self):
980
- # if not self.cythonize:
981
- # return
982
- # root_dir = self.build_dir
983
- # for root, dirnames, filenames in walk(root_dir):
984
- # for filename in fnmatch.filter(filenames, "*.pyx"):
985
- # self.cythonize_file(join(root, filename))
963
+ def cythonize_file (self , env , build_dir , filename ):
964
+ short_filename = filename
965
+ if filename .startswith (build_dir ):
966
+ short_filename = filename [len (build_dir ) + 1 :]
967
+ info (u"Cythonize {}" .format (short_filename ))
968
+ cyenv = env .copy ()
969
+ if 'CYTHONPATH' in cyenv :
970
+ cyenv ['PYTHONPATH' ] = cyenv ['CYTHONPATH' ]
971
+ elif 'PYTHONPATH' in cyenv :
972
+ del cyenv ['PYTHONPATH' ]
973
+ cython = 'cython' if self .ctx .python_recipe .from_crystax else self .ctx .cython
974
+ cython_command = sh .Command (cython )
975
+ shprint (cython_command , filename , * self .cython_args , _env = cyenv )
976
+
977
+ def cythonize_build (self , env , build_dir = "." ):
978
+ if not self .cythonize :
979
+ info ('Running cython cancelled per recipe setting' )
980
+ return
981
+ info ('Running cython where appropriate' )
982
+ for root , dirnames , filenames in walk ("." ):
983
+ for filename in fnmatch .filter (filenames , "*.pyx" ):
984
+ self .cythonize_file (env , build_dir , join (root , filename ))
986
985
987
986
def get_recipe_env (self , arch , with_flags_in_cc = True ):
988
987
env = super (CythonRecipe , self ).get_recipe_env (arch , with_flags_in_cc )
0 commit comments