Commit ae25c47f authored by Stefan Behnel's avatar Stefan Behnel

clean up distutils argument handling in cythonize script, avoid unnecessary...

clean up distutils argument handling in cythonize script, avoid unnecessary cwd changing, move intermediate compiler artifacts into temp directory and delete them afterwards
parent b9809a96
#!/usr/bin/env python #!/usr/bin/env python
import os import os
import sys import shutil
import tempfile
from distutils.core import setup from distutils.core import setup
from Cython.Build.Dependencies import cythonize, extended_iglob from Cython.Build.Dependencies import cythonize, extended_iglob
...@@ -77,22 +78,15 @@ def cython_compile(path_pattern, options): ...@@ -77,22 +78,15 @@ def cython_compile(path_pattern, options):
# assume it's a file(-like thing) # assume it's a file(-like thing)
paths = [path] paths = [path]
cwd = os.getcwd() ext_modules = cythonize(
try: paths,
if base_dir: nthreads=options.parallel,
os.chdir(base_dir) exclude_failures=options.keep_going,
ext_modules = cythonize( exclude=options.excludes,
paths, compiler_directives=options.directives,
nthreads=options.parallel, force=options.force,
exclude_failures=options.keep_going, quiet=options.quiet,
exclude=options.excludes, **options.options)
compiler_directives=options.directives,
force=options.force,
quiet=options.quiet,
**options.options)
finally:
if base_dir:
os.chdir(cwd)
if ext_modules and options.build: if ext_modules and options.build:
if len(ext_modules) > 1 and options.parallel > 1: if len(ext_modules) > 1 and options.parallel > 1:
...@@ -117,15 +111,24 @@ def cython_compile(path_pattern, options): ...@@ -117,15 +111,24 @@ def cython_compile(path_pattern, options):
def run_distutils(args): def run_distutils(args):
base_dir, ext_modules = args base_dir, ext_modules = args
sys.argv[1:] = ['build_ext', '-i'] script_args = ['build_ext', '-i']
cwd = os.getcwd() cwd = os.getcwd()
temp_dir = None
try: try:
if base_dir: if base_dir:
os.chdir(base_dir) os.chdir(base_dir)
setup(ext_modules=ext_modules) temp_dir = tempfile.mkdtemp(dir=base_dir)
script_args.extend(['--build-temp', temp_dir])
setup(
script_name='setup.py',
script_args=script_args,
ext_modules=ext_modules,
)
finally: finally:
if base_dir: if base_dir:
os.chdir(cwd) os.chdir(cwd)
if temp_dir and os.path.isdir(temp_dir):
shutil.rmtree(temp_dir)
def parse_args(args): def parse_args(args):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment