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
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(ext_name):
ext_path = ext_name.replace('.', os.path.sep) + '.pyx'
options = {
'extra_compile_args': compile_args,
'extra_link_args': link_args
}
return Extension(ext_name, [ext_path], **options)
ext_names = scandir(package_dir)
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