Commit f277e978 authored by Robert Bradshaw's avatar Robert Bradshaw

Merge pull request #413 from jdemeyer/multiple_cimports

Correctly parse dependencies of "cimport foo,bar"
parents 0a589021 fc551f60
...@@ -342,8 +342,8 @@ def strip_string_literals(code, prefix='__Pyx_L'): ...@@ -342,8 +342,8 @@ def strip_string_literals(code, prefix='__Pyx_L'):
return "".join(new_code), literals return "".join(new_code), literals
dependancy_regex = re.compile(r"(?:^from +([0-9a-zA-Z_.]+) +cimport)|" dependency_regex = re.compile(r"(?:^from +([0-9a-zA-Z_.]+) +cimport)|"
r"(?:^cimport +([0-9a-zA-Z_.]+)\b)|" r"(?:^cimport +([0-9a-zA-Z_.]+(?: *, *[0-9a-zA-Z_.]+)*))|"
r"(?:^cdef +extern +from +['\"]([^'\"]+)['\"])|" r"(?:^cdef +extern +from +['\"]([^'\"]+)['\"])|"
r"(?:^include +['\"]([^'\"]+)['\"])", re.M) r"(?:^include +['\"]([^'\"]+)['\"])", re.M)
...@@ -412,12 +412,12 @@ def parse_dependencies(source_filename): ...@@ -412,12 +412,12 @@ def parse_dependencies(source_filename):
cimports = [] cimports = []
includes = [] includes = []
externs = [] externs = []
for m in dependancy_regex.finditer(source): for m in dependency_regex.finditer(source):
cimport_from, cimport, extern, include = m.groups() cimport_from, cimport_list, extern, include = m.groups()
if cimport_from: if cimport_from:
cimports.append(cimport_from) cimports.append(cimport_from)
elif cimport: elif cimport_list:
cimports.append(cimport) cimports.extend(x.strip() for x in cimport_list.split(","))
elif extern: elif extern:
externs.append(literals[extern]) externs.append(literals[extern])
else: else:
......
...@@ -13,6 +13,7 @@ ext_modules = [ ...@@ -13,6 +13,7 @@ ext_modules = [
ext_modules = cythonize(ext_modules) ext_modules = cythonize(ext_modules)
assert len(ext_modules[0].libraries) == 2
assert ext_modules[1].libraries == ["lib_x"] assert ext_modules[1].libraries == ["lib_x"]
assert ext_modules[2].libraries == ["lib_y"] assert ext_modules[2].libraries == ["lib_y"]
...@@ -23,8 +24,7 @@ assert ext_modules[2].libraries == ["lib_y"] ...@@ -23,8 +24,7 @@ assert ext_modules[2].libraries == ["lib_y"]
# distutils: libraries = lib_y # distutils: libraries = lib_y
######## a.pyx ######## ######## a.pyx ########
cimport libx cimport libx , liby
cimport liby
######## x.pyx ######## ######## x.pyx ########
cimport libx cimport libx
......
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