U C^@sdZddlmZddlZddlZddlZddlZddlZddlZdZ d ddZ dd Z d d Z d d Z ddZddZddZddZddZddZedkrejddZejdddeZeejdS)!aX cythonize.py Cythonize pyx files into C++ files as needed. Usage: cythonize.py [root] Checks pyx files to see if they have been changed relative to their corresponding C++ files. If they have, then runs cython on these files to recreate the C++ files. Additionally, checks pxd files and setup.py if they have been changed. If they have, rebuilds everything. Change detection based on file hashes stored in JSON format. For now, this script should be run by developers when changing Cython files and the resulting C++ files checked in, so that end-users (and Python-only developers) do not get the Cython dependencies. Based upon: https://raw.github.com/dagss/private-scipy-refactor/cythonize/cythonize.py https://raw.githubusercontent.com/numpy/numpy/master/tools/cythonize.py Note: this script does not check any of the dependent C++ libraries. )print_functionNzcythonize.json-2c Cstd|z4ddlm}ddlm}|||dkr>tdWntk rTYnXd|g}|drr|d g7}z~z4tj d g|d ||gt j d }|dkrtd WnDt k rt t jddg|d ||g}|dkrtd YnXWnt k rt dYnXdS)Nz Processing %sr)version) LooseVersionz0.19zRequire Cython >= 0.19z --fast-fail.cppz--cplusZcythonz-o)envz Cython failedz-czVimport sys; from Cython.Compiler.Main import setuptools_main as main; sys.exit(main())zCython needs to be installed)printZCython.Compiler.VersionrZdistutils.versionr Exception ImportErrorendswith subprocesscallosenvironOSErrorsys executable)ZfromfileZtofileZlanguage_levelZcython_versionrflagsrr0/tmp/pip-install-6_kvzl1k/spacy/bin/cythonize.py process_pyx)sD        rc Gs0t}zt|||W5t|XdSN)rgetcwdchdir)pathfuncargsZorig_cwdrrr preserve_cwdSs   rc Cs2ztt|WSttfk r,iYSXdSr)jsonloadopen ValueErrorIOError)filenamerrr load_hashes\sr%c Cs*t|d}|t|W5QRXdS)Nw)r!writerdumps)Zhash_dbr$frrr save_hashescs r*cCstt|dS)Nrb)hashlibmd5r!read hexdigest)rrrrget_hashhsr0cCs*tjtj||}t|||k Sr)rrnormpathjoinr0getbaserdb full_pathrrr hash_changedlsr8cCs&tjtj||}t|||<dSr)rrr1r2r0r4rrrhash_addqsr9cCsxtj|\}}|dkrtt|||s>tjtj||dstt|t|d|dt||d|t||d|dS)N).pyxrrr:) rrsplitextr8isfiler2rrr9)r5r$r6rootextrrrprocessvsr?c Csd}i}d}td||td||r(d}t|D]:\}}}|D]*}|dr@t|||t|||r@d}q@q2|r||||S)NFzsetup.py.Tz.pxd)r9r8rwalkr clearupdate) r=r6resZnew_dbZsetup_filenamer5_filesr$rrr check_changess       rGc CsTtt}z:t||t|D] \}}}|D]}t|||q,qW5t|tXdSr)r% HASH_FILEr*rGrrAr?)r=r6r5rErFr$rrrruns rI__main__z,Cythonize pyx files into C++ files as needed) descriptionr=zroot directory)help)r)__doc__ __future__rrrrr,r argparserHrrr%r*r0r8r9r?rGrI__name__ArgumentParserparser add_argument parse_argsrr=rrrrs2  *