[Python-checkins] cpython: convert ast versioning to mercurial

benjamin.peterson python-checkins at python.org
Sun Mar 13 01:27:53 CET 2011


http://hg.python.org/cpython/rev/0daa6ba25d9b
changeset:   68412:0daa6ba25d9b
parent:      68407:6392261cdb74
user:        Benjamin Peterson <benjamin at python.org>
date:        Sat Mar 12 18:28:16 2011 -0600
summary:
  convert ast versioning to mercurial

files:
  Doc/library/ast.rst
  Misc/NEWS
  Parser/Python.asdl
  Parser/asdl.py
  Parser/asdl_c.py
  Python/Python-ast.c

diff --git a/Doc/library/ast.rst b/Doc/library/ast.rst
--- a/Doc/library/ast.rst
+++ b/Doc/library/ast.rst
@@ -96,8 +96,8 @@
 Abstract Grammar
 ----------------
 
-The module defines a string constant ``__version__`` which is the decimal
-Subversion revision number of the file shown below.
+The module defines a string constant ``__version__`` which is the Mercurial
+revision of the file shown below.
 
 The abstract grammar is currently defined as follows:
 
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,8 @@
 Core and Builtins
 -----------------
 
+- _ast.__version__ is now a Mercurial integer and hex revision.
+
 - Issue #9856: Change object.__format__ with a non-empty format string
   to be a DeprecationWarning. In 3.2 it was a PendingDeprecationWarning.
   In 3.4 it will be a TypeError.
diff --git a/Parser/Python.asdl b/Parser/Python.asdl
--- a/Parser/Python.asdl
+++ b/Parser/Python.asdl
@@ -1,6 +1,6 @@
 -- ASDL's four builtin types are identifier, int, string, object
 
-module Python version "$Revision$"
+module Python
 {
 	mod = Module(stmt* body)
 	    | Interactive(stmt* body)
diff --git a/Parser/asdl.py b/Parser/asdl.py
--- a/Parser/asdl.py
+++ b/Parser/asdl.py
@@ -114,28 +114,20 @@
         raise ASDLSyntaxError(tok.lineno, tok)
 
     def p_module_0(self, info):
-        " module ::= Id Id version { } "
-        module, name, version, _0, _1 = info
+        " module ::= Id Id { } "
+        module, name, _0, _1 = info
         if module.value != "module":
             raise ASDLSyntaxError(module.lineno,
                                   msg="expected 'module', found %s" % module)
-        return Module(name, None, version)
+        return Module(name, None)
 
     def p_module(self, info):
-        " module ::= Id Id version { definitions } "
-        module, name, version, _0, definitions, _1 = info
+        " module ::= Id Id { definitions } "
+        module, name, _0, definitions, _1 = info
         if module.value != "module":
             raise ASDLSyntaxError(module.lineno,
                                   msg="expected 'module', found %s" % module)
-        return Module(name, definitions, version)
-
-    def p_version(self, info):
-        "version ::= Id String"
-        version, V = info
-        if version.value != "version":
-            raise ASDLSyntaxError(version.lineno,
-                                  msg="expected 'version', found %" % version)
-        return V
+        return Module(name, definitions)
 
     def p_definition_0(self, definition):
         " definitions ::= definition "
@@ -246,10 +238,9 @@
     pass # a marker class
 
 class Module(AST):
-    def __init__(self, name, dfns, version):
+    def __init__(self, name, dfns):
         self.name = name
         self.dfns = dfns
-        self.version = version
         self.types = {} # maps type name to value (from dfns)
         for type in dfns:
             self.types[type.name.value] = type.value
diff --git a/Parser/asdl_c.py b/Parser/asdl_c.py
--- a/Parser/asdl_c.py
+++ b/Parser/asdl_c.py
@@ -5,6 +5,7 @@
 # handle fields that have a type but no name
 
 import os, sys
+import subprocess
 
 import asdl
 
@@ -882,9 +883,6 @@
             self.emit("if (!%s_singleton) return 0;" % cons.name, 1)
 
 
-def parse_version(mod):
-    return mod.version.value[12:-3]
-
 class ASTModuleVisitor(PickleVisitor):
 
     def visitModule(self, mod):
@@ -904,7 +902,7 @@
         self.emit("return NULL;", 2)
         # Value of version: "$Revision$"
         self.emit('if (PyModule_AddStringConstant(m, "__version__", "%s") < 0)'
-                % parse_version(mod), 1)
+                % (mod.version,), 1)
         self.emit("return NULL;", 2)
         for dfn in mod.dfns:
             self.visit(dfn)
@@ -1137,6 +1135,18 @@
 
 """
 
+
+def get_file_revision(f):
+    """Fish out the last change to a file in hg."""
+    args = ["hg", "log", "--template", "{rev}:{node|short}", "--limit", "1"]
+    p = subprocess.Popen(args, stdout=subprocess.PIPE)
+    out = p.communicate()[0]
+    if p.returncode:
+        print >> sys.stderr, "error return code from hg"
+        sys.exit(1)
+    return out
+
+
 def main(srcfile):
     argv0 = sys.argv[0]
     components = argv0.split(os.sep)
@@ -1145,6 +1155,7 @@
     mod = asdl.parse(srcfile)
     if not asdl.check(mod):
         sys.exit(1)
+    mod.version = get_file_revision(srcfile)
     if INC_DIR:
         p = "%s/%s-ast.h" % (INC_DIR, mod.name)
         f = open(p, "w")
@@ -1164,7 +1175,7 @@
         p = os.path.join(SRC_DIR, str(mod.name) + "-ast.c")
         f = open(p, "w")
         f.write(auto_gen_msg)
-        f.write(c_file_msg % parse_version(mod))
+        f.write(c_file_msg % (mod.version,))
         f.write('#include "Python.h"\n')
         f.write('#include "%s-ast.h"\n' % mod.name)
         f.write('\n')
diff --git a/Python/Python-ast.c b/Python/Python-ast.c
--- a/Python/Python-ast.c
+++ b/Python/Python-ast.c
@@ -2,7 +2,7 @@
 
 
 /*
-   __version__ 82163.
+   __version__ 68409:c017695acf19.
 
    This module must be committed separately after each AST grammar change;
    The __version__ number is set to the revision number of the commit
@@ -6739,7 +6739,8 @@
             NULL;
         if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0)
                 return NULL;
-        if (PyModule_AddStringConstant(m, "__version__", "82163") < 0)
+        if (PyModule_AddStringConstant(m, "__version__", "68409:c017695acf19")
+            < 0)
                 return NULL;
         if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return
             NULL;

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list