From 3cd4d03cb2de99da4a2a4592f3541074335ad6e9 Mon Sep 17 00:00:00 2001 From: Evgeni Burovski Date: Tue, 2 Feb 2016 16:35:20 +0000 Subject: [PATCH 1/3] ENH: handle tempita templated Cython source files, *.pyx.in --- skimage/_build.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/skimage/_build.py b/skimage/_build.py index b2ea94fc..e270c4d5 100644 --- a/skimage/_build.py +++ b/skimage/_build.py @@ -30,7 +30,8 @@ def cython(pyx_files, working_path=''): # If cython is not found, we do nothing -- the build will make use of # the distributed .c files print("Cython not found; falling back to pre-built %s" \ - % " ".join([f.replace('.pyx', '.c') for f in pyx_files])) + % " ".join([f.replace('.pyx.in', 'c').replace('.pyx', '.c') + for f in pyx_files])) else: for pyxfile in [os.path.join(working_path, f) for f in pyx_files]: @@ -38,6 +39,10 @@ def cython(pyx_files, working_path=''): if not _changed(pyxfile): continue + if pyxfile.endswith('.pyx.in'): + process_tempita_pyx(pyxfile) + pyxfile = pyxfile.replace('.pyx.in', '.pyx') + cythonize(pyxfile) def _md5sum(f): @@ -69,3 +74,21 @@ def _changed(filename): cf.write(md5_new.encode('utf-8')) return md5_cached != md5_new.encode('utf-8') + + +def process_tempita_pyx(fromfile): + try: + try: + from Cython import Tempita as tempita + except ImportError: + import tempita + except ImportError: + raise Exception('Building requires Tempita: ' + 'pip install --user Tempita') + from_filename = tempita.Template.from_filename + template = from_filename(fromfile) #, encoding=sys.getdefaultencoding()) + pyxcontent = template.substitute() + assert fromfile.endswith('.pyx.in') + pyxfile = fromfile[:-len('.pyx.in')] + '.pyx' + with open(pyxfile, "w") as f: + f.write(pyxcontent) From f4cbcf29f394fb31df208cb7246614b5fa6ac442 Mon Sep 17 00:00:00 2001 From: Evgeni Burovski Date: Wed, 3 Feb 2016 00:26:16 +0000 Subject: [PATCH 2/3] BLD: use default encoding --- skimage/_build.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skimage/_build.py b/skimage/_build.py index e270c4d5..c5041340 100644 --- a/skimage/_build.py +++ b/skimage/_build.py @@ -86,7 +86,7 @@ def process_tempita_pyx(fromfile): raise Exception('Building requires Tempita: ' 'pip install --user Tempita') from_filename = tempita.Template.from_filename - template = from_filename(fromfile) #, encoding=sys.getdefaultencoding()) + template = from_filename(fromfile, encoding=sys.getdefaultencoding()) pyxcontent = template.substitute() assert fromfile.endswith('.pyx.in') pyxfile = fromfile[:-len('.pyx.in')] + '.pyx' From ad535ac2bd90760a5cb2173de6a3a6c76f350565 Mon Sep 17 00:00:00 2001 From: Evgeni Burovski Date: Tue, 16 Feb 2016 07:10:13 +0000 Subject: [PATCH 3/3] MAINT: address review comments --- skimage/_build.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/skimage/_build.py b/skimage/_build.py index c5041340..a091dd1e 100644 --- a/skimage/_build.py +++ b/skimage/_build.py @@ -85,10 +85,12 @@ def process_tempita_pyx(fromfile): except ImportError: raise Exception('Building requires Tempita: ' 'pip install --user Tempita') - from_filename = tempita.Template.from_filename - template = from_filename(fromfile, encoding=sys.getdefaultencoding()) + template = tempita.Template.from_filename(fromfile, + encoding=sys.getdefaultencoding()) pyxcontent = template.substitute() - assert fromfile.endswith('.pyx.in') - pyxfile = fromfile[:-len('.pyx.in')] + '.pyx' + if not fromfile.endswith('.pyx.in'): + raise ValueError("Unexpected extension of %s." % fromfile) + + pyxfile = os.path.splitext(fromfile)[0] + '.pyx' with open(pyxfile, "w") as f: f.write(pyxcontent)