Skip to content

Instantly share code, notes, and snippets.

@odra
Last active September 3, 2015 13:57
Show Gist options
  • Save odra/e4c99d3bff33204149a9 to your computer and use it in GitHub Desktop.
Save odra/e4c99d3bff33204149a9 to your computer and use it in GitHub Desktop.
cython setup.py file to compile packages
# -*- coding: utf-8 -*-
#source: https://github.com/cython/cython/wiki/PackageHierarchy
'''
gd/
__init__.py
hello.pxd
hello.pyx
greetings/
__init__.py
en.pxd
en.pyx
'''
import sys, os
from distutils.core import setup, Extension
from Cython.Distutils import build_ext
package_name = 'gd'
package_dir = 'gd'
packages = ['gd', 'gd.greetings']
compile_args = ['-Wall']
link_args = ['-g']
def scandir(dir, files=[]):
for file in os.listdir(dir):
path = os.path.join(dir, file)
if os.path.isfile(path) and path.endswith('.pyx'):
files.append(path.replace(os.path.sep, '.')[:-4])
elif os.path.isdir(path):
scandir(path, files)
return files
def make_extension(extName):
extPath = extName.replace('.', os.path.sep) + '.pyx'
options = {
'extra_compile_args': compile_args,
'extra_link_args': link_args
}
return Extension(extName, [extPath], **options)
ext_names = scandir('gd')
extensions = [make_extension(name) for name in ext_names]
options = {
'name': package_name,
'packages': packages,
'ext_modules': extensions,
'cmdclass': {'build_ext': build_ext}
}
setup(**options)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment