Commit a0ec9c54 authored by Robert Bradshaw's avatar Robert Bradshaw

Allow distutils directives in test files.

parent bda90138
......@@ -148,14 +148,18 @@ distutils_settings = {
@cython.locals(start=long, end=long)
def line_iter(source):
start = 0
while True:
end = source.find('\n', start)
if end == -1:
yield source[start:]
return
yield source[start:end]
start = end+1
if isinstance(source, file):
for line in source:
yield line
else:
start = 0
while True:
end = source.find('\n', start)
if end == -1:
yield source[start:]
return
yield source[start:end]
start = end+1
class DistutilsInfo(object):
......@@ -225,6 +229,14 @@ class DistutilsInfo(object):
resolved.values[key] = value
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,
end=long, k=long, counter=long, quote_len=long)
def strip_string_literals(code, prefix='__Pyx_L'):
......
......@@ -75,6 +75,7 @@ from distutils.command.build_ext import build_ext as _build_ext
from distutils import sysconfig
distutils_distro = Distribution()
if sys.platform == 'win32':
# TODO: Figure out why this hackery (see http://thread.gmane.org/gmane.comp.python.cython.devel/8280/).
config_files = distutils_distro.find_config_files()
......@@ -204,7 +205,7 @@ EXCLUDE_EXT = object()
EXT_EXTRAS = {
'tag:numpy' : update_numpy_extension,
'tag:openmp': update_openmp_extension,
'tag:trace': update_linetrace_extension,
'tag:trace' : update_linetrace_extension,
}
......@@ -334,7 +335,7 @@ def parse_tags(filepath):
if tag == 'tags':
tag = 'tag'
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))
values = values.split(',')
tags[tag].extend(filter(None, [value.strip() for value in values]))
......@@ -772,6 +773,11 @@ class CythonCompileTestCase(unittest.TestCase):
# Set the language now as the fixer might need it
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()):
if isinstance(matcher, str):
# 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