Annotate by default if there is an existing annotation.
authorRobert Bradshaw <robertwb@math.washington.edu>
Fri, 25 Feb 2011 06:45:02 +0000 (22:45 -0800)
committerRobert Bradshaw <robertwb@math.washington.edu>
Fri, 25 Feb 2011 06:45:02 +0000 (22:45 -0800)
Cython/Compiler/Annotate.py
Cython/Compiler/Main.py

index cfdcfaed246e38edf89127f5ac52c1b4c840aa39..98823fe0caddd5894796d315bc08e436aee914fe 100644 (file)
@@ -86,6 +86,7 @@ class AnnotationCCodeWriter(CCodeWriter):
 
         html_filename = os.path.splitext(target_filename)[0] + ".html"
         f = codecs.open(html_filename, "w", encoding="UTF-8")
+        f.write(u'<!-- Generated by Cython %s on %s -->\n' % (Version.version, time.asctime()))
         f.write(u'<html>\n')
         f.write(u"""
 <head>
index c20d7a7c5af931c0177545d47e5aa11d6ab8ec3c..993d8d9985a612896c18d817069deba72598ffe3 100644 (file)
@@ -2,7 +2,7 @@
 #   Cython Top Level
 #
 
-import os, sys, re
+import os, sys, re, codecs
 if sys.version_info[:2] < (2, 3):
     sys.stderr.write("Sorry, Cython requires Python 2.3 or later\n")
     sys.exit(1)
@@ -607,6 +607,14 @@ def run_pipeline(source, options, full_module_name = None):
     # Set up result object
     result = create_default_resultobj(source, options)
 
+    if options.annotate is None:
+        # By default, decide based on whether an html file already exists.
+        html_filename = os.path.splitext(result.c_file)[0] + ".html"
+        if os.path.exists(html_filename):
+            line = codecs.open(html_filename, "r", encoding="UTF-8").readline()
+            if line.startswith(u'<!-- Generated by Cython'):
+                options.annotate = True            
+
     # Get pipeline
     if source_ext.lower() == '.py':
         pipeline = context.create_py_pipeline(options, result)
@@ -826,7 +834,7 @@ default_options = dict(
     errors_to_stderr = 1,
     cplus = 0,
     output_file = None,
-    annotate = False,
+    annotate = None,
     generate_pxi = 0,
     working_path = "",
     recursive = 0,