Commit bb72b52d authored by Stefan Behnel's avatar Stefan Behnel

put the annotated .html file next to the .c file to fix annotation when the .c...

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
parent 0aea8272
......@@ -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'<html>\n')
f.write(u"""
<head>
......@@ -117,7 +118,7 @@ function toggleDiv(id) {
""")
f.write(u'<body>\n')
f.write(u'<p>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'<p>Raw output: <a href="%s">%s</a>\n' % (c_file, c_file))
k = 0
......
......@@ -174,6 +174,7 @@ 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")
......@@ -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,
......
......@@ -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:
......
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