From bb72b52d5b6a5c5660182390d2110570cb8f74ac Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Fri, 9 May 2008 09:28:36 +0200 Subject: [PATCH] put the annotated .html file next to the .c file to fix annotation when the .c file is not in the same directory as the .pyx file --- Cython/Compiler/Annotate.py | 13 +++++++------ Cython/Compiler/Main.py | 4 +++- Cython/Compiler/ModuleNode.py | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Cython/Compiler/Annotate.py b/Cython/Compiler/Annotate.py index d88ac7bf..ca3f5679 100644 --- a/Cython/Compiler/Annotate.py +++ b/Cython/Compiler/Annotate.py @@ -48,9 +48,9 @@ class AnnotationCCodeWriter(CCodeWriter): def annotate(self, pos, item): self.annotations.append((pos, item)) - def save_annotation(self, filename): + def save_annotation(self, source_filename, target_filename): self.mark_pos(None) - f = Utils.open_source_file(filename) + f = Utils.open_source_file(source_filename) lines = f.readlines() for k in range(len(lines)): line = lines[k] @@ -60,12 +60,12 @@ class AnnotationCCodeWriter(CCodeWriter): f.close() all = [] for pos, item in self.annotations: - if pos[0] == filename: + if pos[0] == source_filename: start = item.start() size, end = item.end() if size: all.append((pos, start)) - all.append(((filename, pos[1], pos[2]+size), end)) + all.append(((source_filename, pos[1], pos[2]+size), end)) else: all.append((pos, start+end)) @@ -78,7 +78,8 @@ class AnnotationCCodeWriter(CCodeWriter): line = lines[line_no] lines[line_no] = line[:col] + item + line[col:] - f = codecs.open("%s.html" % filename, "w", encoding="UTF-8") + html_filename = os.path.splitext(target_filename)[0] + ".html" + f = codecs.open(html_filename, "w", encoding="UTF-8") f.write(u'\n') f.write(u""" @@ -117,7 +118,7 @@ function toggleDiv(id) { """) f.write(u'\n') f.write(u'

Generated by Cython %s on %s\n' % (Version.version, time.asctime())) - c_file = Utils.encode_filename(os.path.basename(filename)[:-3] + 'c') + c_file = Utils.encode_filename(os.path.basename(target_filename)) f.write(u'

Raw output: %s\n' % (c_file, c_file)) k = 0 diff --git a/Cython/Compiler/Main.py b/Cython/Compiler/Main.py index 5fc91545..f0e1beb6 100644 --- a/Cython/Compiler/Main.py +++ b/Cython/Compiler/Main.py @@ -174,7 +174,8 @@ class Context: full_module_name = re.sub(r'[^\w.]', '_', full_module_name) source = os.path.join(cwd, source) - + result.main_source_file = source + if options.use_listing_file: result.listing_file = replace_suffix(source, ".lis") Errors.open_listing_file(result.listing_file, @@ -286,6 +287,7 @@ class CompilationResult: self.listing_file = None self.object_file = None self.extension_file = None + self.main_source_file = None def compile(source, options = None, c_compile = 0, c_link = 0, diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py index f7d1d3fb..2acb1016 100644 --- a/Cython/Compiler/ModuleNode.py +++ b/Cython/Compiler/ModuleNode.py @@ -247,7 +247,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): result.c_file_generated = 1 if Options.annotate or options.annotate: self.annotate(code) - code.save_annotation(result.c_file[:-1] + "pyx") # change? + code.save_annotation(result.main_source_file, result.c_file) def find_referenced_modules(self, env, module_list, modules_seen): if env not in modules_seen: -- 2.26.2