diff options
author | mattip <matti.picus@gmail.com> | 2019-03-20 12:39:53 +0200 |
---|---|---|
committer | mattip <matti.picus@gmail.com> | 2019-05-20 18:45:27 +0300 |
commit | fa8af41c9d375072b2c7af66e5f7f01df4754841 (patch) | |
tree | a70e8ac590d1aa7b04799b8c4deb3d67603e856b /tools/cythonize.py | |
parent | 6e386c05c292da49224fcab372013a6d4247ae3b (diff) | |
download | numpy-fa8af41c9d375072b2c7af66e5f7f01df4754841.tar.gz |
BUILD: move files out of _randomgen
first cut at building randomgen
upgrade 'cythonize' and fix absolute imports to relative
define NPY_NO_DEPRECATED_API and fix other warnings
enable pgc64 by always using PCG_EMULATED_MATH
refactor so import randomgen works
add TODO comments for pcg64 improvements
fix imports, module name in setup.py; remove _testing
make cythonize non-recursive, restore examples to proper place
update to randomgen 7bca296c0b9
replace mtrand with LegacyGenerator, tweak for compatibility
port f879ef4 to fix GH10839
minimized difference between generator.pyx and _legacy.pyx
fix namespace in doctests, mark results that are random
update to randomgen commit 95c8cdd1c
Incorporate testing of edge cases into main tests
Rename test files to describe their purpose
Import import locations to reflect numpy paths
Correct tolerance on float32 tests
Remove set_printoptions
Remove complex normal
Remove future imports
Pull in BasicRNG source changes from original author
Small doc fixes
_mtrand => _rand
Improve consistency of nan handling
Prevent nans prducing values from int functions
add randomgen documentation to the tree
Diffstat (limited to 'tools/cythonize.py')
-rwxr-xr-x | tools/cythonize.py | 85 |
1 files changed, 52 insertions, 33 deletions
diff --git a/tools/cythonize.py b/tools/cythonize.py index 9e2af840d..c81b72d25 100755 --- a/tools/cythonize.py +++ b/tools/cythonize.py @@ -52,7 +52,7 @@ except NameError: # Rules # def process_pyx(fromfile, tofile): - flags = ['--fast-fail'] + flags = ['-3', '--fast-fail'] if tofile.endswith('.cxx'): flags += ['--cplus'] @@ -99,6 +99,17 @@ def process_tempita_pyx(fromfile, tofile): process_pyx(pyxfile, tofile) +def process_tempita_pyd(fromfile, tofile): + import npy_tempita as tempita + + assert fromfile.endswith('.pxd.in') + assert tofile.endswith('.pxd') + with open(fromfile, "r") as f: + tmpl = f.read() + pyxcontent = tempita.sub(tmpl) + with open(tofile, "w") as f: + f.write(pyxcontent) + def process_tempita_pxi(fromfile, tofile): import npy_tempita as tempita @@ -110,10 +121,24 @@ def process_tempita_pxi(fromfile, tofile): with open(tofile, "w") as f: f.write(pyxcontent) +def process_tempita_pxd(fromfile, tofile): + import npy_tempita as tempita + + assert fromfile.endswith('.pxd.in') + assert tofile.endswith('.pxd') + with open(fromfile, "r") as f: + tmpl = f.read() + pyxcontent = tempita.sub(tmpl) + with open(tofile, "w") as f: + f.write(pyxcontent) + rules = { - # fromext : function - '.pyx' : process_pyx, - '.pyx.in' : process_tempita_pyx + # fromext : function, toext + '.pyx' : (process_pyx, '.c'), + '.pyx.in' : (process_tempita_pyx, '.c'), + '.pxi.in' : (process_tempita_pxi, '.pxi'), + '.pxd.in' : (process_tempita_pxd, '.pxd'), + '.pyd.in' : (process_tempita_pyd, '.pyd'), } # # Hash db @@ -179,38 +204,32 @@ def process(path, fromfile, tofile, processor_function, hash_db): def find_process_files(root_dir): hash_db = load_hashes(HASH_FILE) - for cur_dir, dirs, files in os.walk(root_dir): - # .pxi or .pxi.in files are most likely dependencies for - # .pyx files, so we need to process them first - files.sort(key=lambda name: (name.endswith('.pxi') or - name.endswith('.pxi.in')), - reverse=True) - - for filename in files: - in_file = os.path.join(cur_dir, filename + ".in") - if filename.endswith('.pyx') and os.path.isfile(in_file): - continue - elif filename.endswith('.pxi.in'): - toext = '.pxi' - fromext = '.pxi.in' + files = [x for x in os.listdir(root_dir) if not os.path.isdir(x)] + # .pxi or .pxi.in files are most likely dependencies for + # .pyx files, so we need to process them first + files.sort(key=lambda name: (name.endswith('.pxi') or + name.endswith('.pxi.in') or + name.endswith('.pxd.in')), + reverse=True) + + for filename in files: + in_file = os.path.join(root_dir, filename + ".in") + for fromext, value in rules.items(): + if filename.endswith(fromext): + if not value: + break + function, toext = value + if toext == '.c': + with open(os.path.join(root_dir, filename), 'rb') as f: + data = f.read() + m = re.search(br"^\s*#\s*distutils:\s*language\s*=\s*c\+\+\s*$", data, re.I|re.M) + if m: + toext = ".cxx" fromfile = filename - function = process_tempita_pxi tofile = filename[:-len(fromext)] + toext - process(cur_dir, fromfile, tofile, function, hash_db) + process(root_dir, fromfile, tofile, function, hash_db) save_hashes(hash_db, HASH_FILE) - else: - for fromext, function in rules.items(): - if filename.endswith(fromext): - toext = ".c" - with open(os.path.join(cur_dir, filename), 'rb') as f: - data = f.read() - m = re.search(br"^\s*#\s*distutils:\s*language\s*=\s*c\+\+\s*$", data, re.I|re.M) - if m: - toext = ".cxx" - fromfile = filename - tofile = filename[:-len(fromext)] + toext - process(cur_dir, fromfile, tofile, function, hash_db) - save_hashes(hash_db, HASH_FILE) + break def main(): try: |