Commit abed5162 authored by Stefan Behnel's avatar Stefan Behnel

allow passing additional sources into cythonize() through the 'distutils:...

allow passing additional sources into cythonize() through the 'distutils: sources' option in the source file
parent aa9e1b6a
......@@ -22,6 +22,19 @@ from Cython.Compiler.Main import Context, CompilationOptions, default_options
os.path.join = cached_function(os.path.join)
if sys.version_info[0] < 3:
# stupid Py2 distutils enforces str type in list of sources
_fs_encoding = sys.getfilesystemencoding()
if _fs_encoding is None:
_fs_encoding = sys.getdefaultencoding()
def encode_filename_in_py2(filename):
if isinstance(filename, unicode):
return filename.encode(_fs_encoding)
return filename
else:
def encode_filename_in_py2(filename):
return filename
def extended_iglob(pattern):
if '**/' in pattern:
seen = set()
......@@ -529,6 +542,13 @@ def create_extension_list(patterns, exclude=[], ctx=None, aliases=None):
sources = [file]
if template is not None:
sources += template.sources[1:]
if 'sources' in kwds:
# allow users to add .c files etc.
for source in kwds['sources']:
source = encode_filename_in_py2(source)
if source not in sources:
sources.append(source)
del kwds['sources']
module_list.append(exn_type(
name=module_name,
sources=sources,
......
PYTHON setup.py build_ext --inplace
PYTHON -c "import a; assert a.test() == 43"
######## setup.py ########
from Cython.Build.Dependencies import cythonize
from distutils.core import setup
setup(
ext_modules = cythonize("*.pyx"),
)
######## a.pyx ########
# distutils: sources=alib.c
cdef extern from "alib.h":
int c_function(int x)
def test():
return c_function(42)
######## alib.c ########
int c_function(int x) {
return x + 1;
}
######## alib.h ########
int c_function(int x);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment