mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-09 07:11:31 +08:00
Merge pull request #1924 from ev-br/tempita
Handle tempita templed cython files
This commit is contained in:
+26
-1
@@ -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,23 @@ 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')
|
||||
template = tempita.Template.from_filename(fromfile,
|
||||
encoding=sys.getdefaultencoding())
|
||||
pyxcontent = template.substitute()
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user