From a461ba507293b8a51c922ca694ea69fb08cf20c4 Mon Sep 17 00:00:00 2001 From: Paul Date: Thu, 24 Mar 2016 01:01:41 -0500 Subject: [PATCH] Remove extracting example in python --- setup.py | 50 +------------------------------------------------- 1 file changed, 1 insertion(+), 49 deletions(-) diff --git a/setup.py b/setup.py index 9b93ca2..b0ba7b6 100644 --- a/setup.py +++ b/setup.py @@ -1,13 +1,9 @@ -import os, itertools +import os prefix = '/// ' include_dir = 'include/' doc_dir = 'doc/src' -example_dir = 'example' -namespace = 'fit' -declare_template_block = ('struct', 'class', 'template', 'namespace') -declare_template_stmt = ('FIT_LIFT_CLASS') def write_to(dir_name, file, lines): content = list((line + "\n" for line in lines)) @@ -15,49 +11,6 @@ def write_to(dir_name, file, lines): print('Writing file:', file) open(os.path.join(dir_name, file), 'w').writelines(content) -def drop(iterable, n): - return itertools.islice(iterable, n, None) - -def adjacent(iterable): - return itertools.izip_longest(iterable, drop(iterable, 1), fillvalue="") - -def extract_section(lines): - taken = itertools.takewhile(lambda x:not (x[1].startswith('--') or x[1].startswith('==')), adjacent(lines)) - return (x for x, y in taken) - -def extract_examples(lines): - result = [] - for i, x in enumerate(lines): - if x.startswith('Example'): - result.append(extract_section(lines[i+1:])) - return result - -def extract_classes(lines): - result = [[], []] - which = 1 - for line in lines: - if line.startswith(declare_template_block) or line.startswith(declare_template_stmt): which = 0 - if line.startswith(('assert')): which = 1 - result[which].append(line) - if which == 0: - if (line.startswith('}') or line.startswith(declare_template_stmt)): which = 1 - if (line.startswith(declare_template_block) and line.endswith(';')): which = 1 - return result[0], result[1] - -def generate_cpp(lines): - decls, main = extract_classes((x[4:] for x in lines if x.startswith(' '))) - yield '#include "example.h"' - yield 'using namespace {0};'.format(namespace) - for x in decls: yield x - yield 'int main() {' - for x in main: yield ' ' + x - yield "}" - -def write_examples(md, name): - examples = extract_examples(md) - for i, example in enumerate(examples): - write_to(example_dir, '{0}{1}.cpp'.format(name, i), generate_cpp(example)) - def insert_header(lines, file): for line in lines: yield line @@ -85,5 +38,4 @@ for root, subdirs, files in os.walk(include_dir): md = extract_md(file) name, ext = os.path.splitext(os.path.basename(file)) write_header(md, name, file) - write_examples(md, name)