Commit a0ec9c54 authored by Robert Bradshaw's avatar Robert Bradshaw

Allow distutils directives in test files.

parent bda90138
...@@ -148,14 +148,18 @@ distutils_settings = { ...@@ -148,14 +148,18 @@ distutils_settings = {
@cython.locals(start=long, end=long) @cython.locals(start=long, end=long)
def line_iter(source): def line_iter(source):
start = 0 if isinstance(source, file):
while True: for line in source:
end = source.find('\n', start) yield line
if end == -1: else:
yield source[start:] start = 0
return while True:
yield source[start:end] end = source.find('\n', start)
start = end+1 if end == -1:
yield source[start:]
return
yield source[start:end]
start = end+1
class DistutilsInfo(object): class DistutilsInfo(object):
...@@ -225,6 +229,14 @@ class DistutilsInfo(object): ...@@ -225,6 +229,14 @@ class DistutilsInfo(object):
resolved.values[key] = value resolved.values[key] = value
return resolved return resolved
def apply(self, extension):
for key, value in self.values.items():
type = distutils_settings[key]
if type in [list, transitive_list]:
getattr(extension, key).extend(value)
else:
setattr(extension, key, value)
@cython.locals(start=long, q=long, single_q=long, double_q=long, hash_mark=long, @cython.locals(start=long, q=long, single_q=long, double_q=long, hash_mark=long,
end=long, k=long, counter=long, quote_len=long) end=long, k=long, counter=long, quote_len=long)
def strip_string_literals(code, prefix='__Pyx_L'): def strip_string_literals(code, prefix='__Pyx_L'):
......
...@@ -75,6 +75,7 @@ from distutils.command.build_ext import build_ext as _build_ext ...@@ -75,6 +75,7 @@ from distutils.command.build_ext import build_ext as _build_ext
from distutils import sysconfig from distutils import sysconfig
distutils_distro = Distribution() distutils_distro = Distribution()
if sys.platform == 'win32': if sys.platform == 'win32':
# TODO: Figure out why this hackery (see http://thread.gmane.org/gmane.comp.python.cython.devel/8280/). # TODO: Figure out why this hackery (see http://thread.gmane.org/gmane.comp.python.cython.devel/8280/).
config_files = distutils_distro.find_config_files() config_files = distutils_distro.find_config_files()
...@@ -204,7 +205,7 @@ EXCLUDE_EXT = object() ...@@ -204,7 +205,7 @@ EXCLUDE_EXT = object()
EXT_EXTRAS = { EXT_EXTRAS = {
'tag:numpy' : update_numpy_extension, 'tag:numpy' : update_numpy_extension,
'tag:openmp': update_openmp_extension, 'tag:openmp': update_openmp_extension,
'tag:trace': update_linetrace_extension, 'tag:trace' : update_linetrace_extension,
} }
...@@ -334,7 +335,7 @@ def parse_tags(filepath): ...@@ -334,7 +335,7 @@ def parse_tags(filepath):
if tag == 'tags': if tag == 'tags':
tag = 'tag' tag = 'tag'
print("WARNING: test tags use the 'tag' directive, not 'tags' (%s)" % filepath) print("WARNING: test tags use the 'tag' directive, not 'tags' (%s)" % filepath)
if tag not in ('mode', 'tag', 'ticket', 'cython'): if tag not in ('mode', 'tag', 'ticket', 'cython', 'distutils'):
print("WARNING: unknown test directive '%s' found (%s)" % (tag, filepath)) print("WARNING: unknown test directive '%s' found (%s)" % (tag, filepath))
values = values.split(',') values = values.split(',')
tags[tag].extend(filter(None, [value.strip() for value in values])) tags[tag].extend(filter(None, [value.strip() for value in values]))
...@@ -772,6 +773,11 @@ class CythonCompileTestCase(unittest.TestCase): ...@@ -772,6 +773,11 @@ class CythonCompileTestCase(unittest.TestCase):
# Set the language now as the fixer might need it # Set the language now as the fixer might need it
extension.language = 'c++' extension.language = 'c++'
if 'distutils' in self.tags:
from Cython.Build.Dependencies import DistutilsInfo
pyx_path = os.path.join(self.test_directory, self.module + ".pyx")
DistutilsInfo(open(pyx_path)).apply(extension)
for matcher, fixer in list(EXT_EXTRAS.items()): for matcher, fixer in list(EXT_EXTRAS.items()):
if isinstance(matcher, str): if isinstance(matcher, str):
# lazy init # lazy init
......
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