put the annotated .html file next to the .c file to fix annotation when the .c file...
authorStefan Behnel <scoder@users.berlios.de>
Fri, 9 May 2008 07:28:36 +0000 (09:28 +0200)
committerStefan Behnel <scoder@users.berlios.de>
Fri, 9 May 2008 07:28:36 +0000 (09:28 +0200)
Cython/Compiler/Annotate.py
Cython/Compiler/Main.py
Cython/Compiler/ModuleNode.py

index d88ac7bf74fc6d493bb64ee217063fe7ee2db647..ca3f56799c667866adb3a929b530dad20915f842 100644 (file)
@@ -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
         
index 5fc91545b34fd38ef5ffc8a5fb05dd18f1ce3c91..f0e1beb6c9723e685650ddec083d8f1db6648459 100644 (file)
@@ -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,
index f7d1d3fbb54640b31b35ae7986e3844f90eb3861..2acb1016b5465cf8f47252f6cc1306a1b08c5d67 100644 (file)
@@ -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: