def run(self): # Make sure the compiled Cython files in the distribution are up-to-date if USE_CYTHON: _cythonize(EXTENSIONS) else: warn('\n\n\033[91m\033[1m WARNING: ' 'IF YOU A PREPARING A DISTRIBUTION: Cython is not available! ' 'The cythonized `*.cpp` files may be out of date. Please ' 'install Cython and run `sdist` again.' '\033[0m\n') _sdist.run(self)
def cythonize(extensions, **kwargs): try: from Cython.Build import cythonize as _cythonize except ImportError: assert_cython_required() print("Cython not found. Using preprocessed c files instead") missing_c_sources = [] for extension in extensions: for source in extension.sources: if source.endswith(".pyx"): c_file = source.replace(".pyx", ".c") if not os.path.exists(c_file): missing_c_sources.append((extension, c_file)) if missing_c_sources: for extension, source in missing_c_sources: print("Missing '{}' for building extension '{}'".format(source, extension.name)) raise SystemExit(1) return extensions return _cythonize(extensions, **kwargs)
def cythonize(orig, **kws): """Wrapper around Cython.Build.cythonize() to correct handling of :py:class:`DSO` s and :py:class:`Extension` s using them. """ cmods = _cythonize(orig, **kws) for new, old in zip(cmods, orig): if new is old or not isinstance(old, Extension): continue assert isinstance(new, Extension), new # _cythonize() has re-created our Extension. # The correct class is used, but our special attributes are lost. # So we copy them over for key in ('dsos', 'lang_compile_args', 'soversion'): if hasattr(old, key): setattr(new, key, getattr(old, key)) return cmods
def cythonize(extensions, **_ignore): # Attempt to use Cython if USE_CYTHON: return _cythonize(extensions) # Cython is not available for extension in extensions: sources = [] for sfile in extension.sources: path, ext = os.path.splitext(sfile) if ext in ('.pyx', '.py'): if extension.language == 'c++': ext = '.cpp' else: ext = '.c' sfile = path + ext sources.append(sfile) extension.sources[:] = sources return extensions