8000 recipe: factorize cython call in CythonRecipe, in order to pass cytho… · mixedCase/python-for-android@fb0e0ca · GitHub
[go: up one dir, main page]

Skip to content

Commit fb0e0ca

Browse files
committed
recipe: factorize cython call in CythonRecipe, in order to pass cython argument from recipe
1 parent 5fe8bea commit fb0e0ca

File tree

2 files changed

+26
-28
lines changed

2 files changed

+26
-28
lines changed

pythonforandroid/build.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -831,4 +831,3 @@ def copylibs_function(soname, objs_paths, extra_link_dirs=[], env=None):
831831
cp = sh.cp.bake('-t', dest)
832832
for lib in sofiles:
833833
shprint(cp, lib)
834-

pythonforandroid/recipe.py

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
import sh
99
import shutil
10-
from os import listdir, unlink, environ, mkdir, curdir
10+
import fnmatch
11+
from os import listdir, unlink, environ, mkdir, curdir, walk
1112
from sys import stdout
1213
try:
1314
from urlparse import urlparse
@@ -895,6 +896,7 @@ def rebuild_compiled_components(self, arch, env):
895896
class CythonRecipe(PythonRecipe):
896897
pre_build_ext = False
897898
cythonize = True
899+
cython_args = []
898900

899901
def __init__(self, *args, **kwargs):
900902
super(CythonRecipe, self).__init__(*args, **kwargs)
@@ -945,18 +947,7 @@ def build_cython_components(self, arch):
945947
manually_cythonise = True
946948

947949
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)
960951
shprint(hostpython, 'setup.py', 'build_ext', '-v', _env=env,
961952
_tail=20, _critical=True, *self.setup_extra_args)
962953
else:
@@ -969,20 +960,28 @@ def build_cython_components(self, arch):
969960
env['STRIP'], '{}', ';', _env=env)
970961
print('stripped!?')
971962

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))
986985

987986
def get_recipe_env(self, arch, with_flags_in_cc=True):
988987
env = super(CythonRecipe, self).get_recipe_env(arch, with_flags_in_cc)

0 commit comments

Comments
 (0)
0