Skip to content

Instantly share code, notes, and snippets.

@david-batranu
Created November 23, 2017 20:06
Show Gist options
  • Select an option

  • Save david-batranu/6f96e059e8b225c91a753bbd4aa138ca to your computer and use it in GitHub Desktop.

Select an option

Save david-batranu/6f96e059e8b225c91a753bbd4aa138ca to your computer and use it in GitHub Desktop.
basic cython compile everything
# to test:
# pip install Cython
# run with CYTHON_BUILD=true setup.py bdist_wheel
def ext_modules():
from setuptools import Extension
from setuptools.extension import _have_cython
cython_build = os.environ.get('CYTHON_BUILD')
if not _have_cython() or not cython_build:
return []
def _pystar_from_name(name):
return os.path.join(*name.split('.') + ['*.py'])
def _extension(name):
return Extension('{}.*'.format(name), [_pystar_from_name(name)])
from Cython.Build import cythonize
packages = find_packages(exclude=['ez_setup'])
return cythonize([_extension(name) for name in packages])
setup(ext_modules=ext_modules())
@david-batranu

david-batranu commented Nov 23, 2017

Copy link
Copy Markdown
Author
cython file.py
gcc -pthread -fPIC -I/usr/lib/python-exec/python2.7/../../../include/python2.7 -c file.c -o file.o
gcc -pthread -shared -Wl,-O1 -Wl,--as-needed -L. file.o -L/usr/lib64 -lpython2.7 -o file.so

or
cythonize -i file.py

@david-batranu

Copy link
Copy Markdown
Author

Need zope.interface>=4.0.0, due to Cython being „meant to be "translate once, build anywhere"”: cython/cython#1936 (comment) and https://www.python.org/dev/peps/pep-3155/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment