Commit 5266d1f9 authored by Robert Bradshaw's avatar Robert Bradshaw

Aliases for inline dependencies (e.g. numpy_include_dirs).

parent 8e18e1c0
...@@ -68,24 +68,25 @@ def line_iter(source): ...@@ -68,24 +68,25 @@ def line_iter(source):
class DistutilsInfo(object): class DistutilsInfo(object):
def __init__(self, source): def __init__(self, source=None):
self.values = {} self.values = {}
for line in line_iter(source): if source is not None:
line = line.strip() for line in line_iter(source):
if line != '' and line[0] != '#': line = line.strip()
break if line != '' and line[0] != '#':
line = line[1:].strip() break
if line[:10] == 'distutils:': line = line[1:].strip()
line = line[10:] if line[:10] == 'distutils:':
ix = line.index('=') line = line[10:]
key = str(line[:ix].strip()) ix = line.index('=')
value = line[ix+1:].strip() key = str(line[:ix].strip())
type = distutils_settings[key] value = line[ix+1:].strip()
if type in (list, transitive_list): type = distutils_settings[key]
value = parse_list(value) if type in (list, transitive_list):
if key == 'define_macros': value = parse_list(value)
value = [tuple(macro.split('=')) for macro in value] if key == 'define_macros':
self.values[key] = value value = [tuple(macro.split('=')) for macro in value]
self.values[key] = value
def merge(self, other): def merge(self, other):
for key, value in other.values.items(): for key, value in other.values.items():
...@@ -101,6 +102,28 @@ class DistutilsInfo(object): ...@@ -101,6 +102,28 @@ class DistutilsInfo(object):
else: else:
self.values[key] = value self.values[key] = value
return self return self
def subs(self, aliases):
if aliases is None:
return self
resolved = DistutilsInfo()
for key, value in self.values.items():
type = distutils_settings[key]
if type in [list, transitive_list]:
new_value_list = []
for v in value:
if v in aliases:
v = aliases[v]
if isinstance(v, list):
new_value_list += v
else:
new_value_list.append(v)
value = new_value_list
else:
if value in aliases:
value = aliases[value]
resolved.values[key] = value
return resolved
def strip_string_literals(code, prefix='__Pyx_L'): def strip_string_literals(code, prefix='__Pyx_L'):
...@@ -280,8 +303,8 @@ class DependencyTree(object): ...@@ -280,8 +303,8 @@ class DependencyTree(object):
def distutils_info0(self, filename): def distutils_info0(self, filename):
return self.parse_dependencies(filename)[3] return self.parse_dependencies(filename)[3]
def distutils_info(self, filename): def distutils_info(self, filename, aliases):
return self.transitive_merge(filename, self.distutils_info0, DistutilsInfo.merge) return self.transitive_merge(filename, self.distutils_info0, DistutilsInfo.merge).subs(aliases)
def transitive_merge(self, node, extract, merge): def transitive_merge(self, node, extract, merge):
try: try:
...@@ -328,7 +351,7 @@ def create_dependency_tree(ctx=None): ...@@ -328,7 +351,7 @@ def create_dependency_tree(ctx=None):
# TODO: Take common options. # TODO: Take common options.
# TODO: Symbolic names (e.g. for numpy.include_dirs() # TODO: Symbolic names (e.g. for numpy.include_dirs()
def create_extension_list(filepatterns, ctx=None): def create_extension_list(filepatterns, ctx=None, aliases=None):
deps = create_dependency_tree(ctx) deps = create_dependency_tree(ctx)
if isinstance(filepatterns, str): if isinstance(filepatterns, str):
filepatterns = [filepatterns] filepatterns = [filepatterns]
...@@ -337,7 +360,7 @@ def create_extension_list(filepatterns, ctx=None): ...@@ -337,7 +360,7 @@ def create_extension_list(filepatterns, ctx=None):
for file in glob(pattern): for file in glob(pattern):
pkg = deps.package(file) pkg = deps.package(file)
name = deps.fully_qualifeid_name(file) name = deps.fully_qualifeid_name(file)
module_list.append(Extension(name=name, sources=[file], **deps.distutils_info(file).values)) module_list.append(Extension(name=name, sources=[file], **deps.distutils_info(file, aliases).values))
return module_list return module_list
def cythonize(module_list, ctx=None, nthreads=0): def cythonize(module_list, ctx=None, nthreads=0):
......
...@@ -10,12 +10,13 @@ from Cython.Compiler.Dependencies import create_extension_list, cythonize ...@@ -10,12 +10,13 @@ from Cython.Compiler.Dependencies import create_extension_list, cythonize
from distutils.core import setup from distutils.core import setup
setup( setup(
ext_modules = cythonize(create_extension_list("*.pyx")), ext_modules = cythonize(create_extension_list("*.pyx", aliases={'MATH_LIBS': ['m']})),
) )
######## my_lib.pxd ######## ######## my_lib.pxd ########
# distutils: language=c++ # distutils: language = c++
# distutils: libraries = MATH_LIBS
cdef extern from "my_lib_helper.cpp" namespace "A": cdef extern from "my_lib_helper.cpp" namespace "A":
int x 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