def extensions(coverage=False): def from_env(var): with suppress(KeyError): return filter(None, os.environ[var].split(ENVSEP)) return () WINDOWS = platform.system() == "Windows" ENVSEP = ";" if WINDOWS else ":" libraries = ([ "AdvAPI32", # `Crypt*` calls from `library/entropy_poll.c` "mbedTLS", ] if WINDOWS else ["mbedcrypto", "mbedtls", "mbedx509"]) library_dirs = list(from_env("LIBPATH" if WINDOWS else "LIBRARY_PATH")) for dirpath, _, filenames in os.walk("src"): for fn in filenames: root, ext = os.path.splitext(fn) if ext != ".pyx": continue mod = ".".join(dirpath.split(os.sep)[1:] + [root]) extension = Extension( mod, sources=[os.path.join(dirpath, fn)], library_dirs=library_dirs, libraries=libraries, define_macros=[ ("CYTHON_TRACE", "1"), ("CYTHON_TRACE_NOGIL", "1"), ] if coverage else [], ) extension.cython_directives = {"language_level": "3str"} if coverage: extension.cython_directives["linetrace"] = True yield extension
def extensions(coverage=False): for dirpath, dirnames, filenames in os.walk("src"): for fn in filenames: root, ext = os.path.splitext(fn) if ext != ".pyx": continue mod = ".".join(dirpath.split(os.sep)[1:] + [root]) extension = Extension( mod, [os.path.join(dirpath, fn)], library_dirs=[ os.environ.get("LD_LIBRARY_PATH", ""), os.environ.get("DYLD_LIBRARY_PATH", ""), ], libraries=["mbedcrypto", "mbedtls", "mbedx509"], define_macros=[ ("CYTHON_TRACE", "1"), ("CYTHON_TRACE_NOGIL", "1"), ] if coverage else [], ) extension.cython_directives = {"language_level": 3} if coverage: extension.cython_directives["linetrace"] = True yield extension
def get_ext_modules_n_cmdclass(): root_path = Path('.') try: from Cython.Distutils import build_ext except ImportError: use_cython = False else: use_cython = True cmdclass = {} ext_modules = [] if use_cython: # get all .pyx files pyx_paths = sorted(root_path.rglob("*.pyx")) for pyx_path in pyx_paths: path_str = str(pyx_path) header = pyx_path.read_text().split('\n')[0] if ('cpp' in header) or ('c++' in header): language = 'c++' else: language = 'c' extension = Extension( path_str[:-4].replace('/', '.'), [path_str], language=language, ) # Have Cython embed function call signature information in docstrings, # so that Sphinx can extract and use those signatures. extension.cython_directives = {"embedsignature": True} ext_modules.append(extension) cmdclass.update({'build_ext': build_ext}) else: # .c files c_paths = sorted(root_path.rglob("*.c")) for c_path in c_paths: path_str = str(c_path) ext_modules.append( Extension( path_str[:-2].replace('/', '.'), [path_str], ), ) # .cpp files cpp_paths = sorted(root_path.rglob("*.cpp")) for cpp_path in cpp_paths: path_str = str(cpp_path) ext_modules.append( Extension( path_str[:-4].replace('/', '.'), [path_str], ), ) return ext_modules, cmdclass
sources = ['src/seabreeze/cseabreeze/c_seabreeze_wrapper.pyx'] for root, subdirs, fns in os.walk('src/libseabreeze/src'): subdirs[:] = (d for d in subdirs if d not in ignore_subdirs) sources.extend((os.path.join(root, fn) for fn in fns)) # Add seabreeze include dirs compile_opts['include_dirs'].append(os.path.relpath('src/libseabreeze/include')) # define extension libseabreeze = Extension('seabreeze.cseabreeze._wrapper', language='c++', sources=[os.path.relpath(s) for s in sources], **compile_opts) building_sphinx_documentation = bool(strtobool(os.environ.get('READTHEDOCS', 'false'))) libseabreeze.cython_directives = { 'binding': building_sphinx_documentation, # fix class method parameters for sphinx 'embedsignature': not building_sphinx_documentation, # add function signature to docstring for ipython } extensions = [libseabreeze] # noinspection PyPep8Naming class sb_build_ext(build_ext): def build_extensions(self): # Deal with windows command line limit if os.name == 'nt': # noinspection PyArgumentList self.compiler.spawn = win_spawn.__get__(self.compiler) # prevent cpp compiler warning # - see: https://stackoverflow.com/a/36293331 # - see: https://github.com/python/cpython/pull/7476/files customize_compiler(self.compiler)
ext = ".c" peakfinder8_ext = Extension( name="om.lib.peakfinder8_extension", include_dirs=[numpy.get_include()], libraries=["stdc++"], sources=[ "lib_src/peakfinder8_extension/peakfinder8.cpp", "lib_src/peakfinder8_extension/peakfinder8_extension.pyx", ] if OM_USE_CYTHON else [ "lib_src/peakfinder8_extension/peakfinder8_extension.cpp", "lib_src/peakfinder8_extension/peakfinder8.cpp", ], language="c++", ) peakfinder8_ext.cython_directives = {"embedsignature": True} if OM_USE_CYTHON: from Cython.Build import cythonize extensions = cythonize(peakfinder8_ext) else: extensions = [peakfinder8_ext] version_fh = open("src/om/__init__.py", "r") version = version_fh.readlines()[-1].split("=")[1].strip().split('"')[1] version_fh.close() setup( name="ondamonitor", version=version, url="https://www.ondamonitor.com",
import os import numpy as np from Cython.Distutils import build_ext from setuptools import Extension, find_packages, setup ext_modules = [] e = Extension( "riip.formulas_cython", sources=[os.path.join("src", "utils", "formulas_cython.pyx")], depends=[], include_dirs=[np.get_include(), "."], language="c++", ) e.cython_directives = {"language_level": "3"} ext_modules.append(e) setup( name="riip", version="0.6.13", url="https://github.com/mnishida/RII_Pandas", license="MIT", author="Munehiro Nishida", author_email="*****@*****.**", description= "Python 3 + Pandas wrapper for the refractiveindex.info database", long_description=open("README.md").read(), long_description_content_type="text/markdown", zip_safe=False, packages=find_packages("src"), package_dir={"": "src"},
from Cython.Distutils import build_ext import numpy, sys, re if len(sys.argv) != 4: raise ValueError("Wrong number of parameters received. Expected 4, got {}".format(sys.argv)) # Get the name of the file to compile fileToCompile = sys.argv[1] # Remove the argument from sys argv in order for it to contain only what setup needs del sys.argv[1] extensionName = re.sub("\.pyx", "", fileToCompile) ext_modules = Extension(extensionName, [fileToCompile], extra_compile_args=['-O2'], include_dirs=[numpy.get_include(),], ) ext_modules.cython_directives = {'language_level': '3'} setup( cmdclass={'build_ext': build_ext}, ext_modules=[ext_modules] )