]> granicus.if.org Git - python/commitdiff
Expose Subversion revision number (calculated via "svnversion .") to Python.
authorBarry Warsaw <barry@python.org>
Sun, 18 Dec 2005 01:27:35 +0000 (01:27 +0000)
committerBarry Warsaw <barry@python.org>
Sun, 18 Dec 2005 01:27:35 +0000 (01:27 +0000)
Add C API function Py_GetBuildNumber(), add it to the interactive prompt
banner (i.e. Py_GetBuildInfo()), and add it as the sys.build_number
attribute.  The build number is a string instead of an int because it may
contain a trailing 'M' if there are local modifications.

Doc/api/init.tex
Doc/lib/libsys.tex
Include/pythonrun.h
Makefile.pre.in
Misc/NEWS
Modules/getbuildinfo.c
Python/sysmodule.c

index 51b925f5bdd8af4bea19b33c47244a1894ed99c5..67f74a145421f235d6279796ed184eb798ee9e56 100644 (file)
   \withsubitem{(in module sys)}{\ttindex{version}}
 \end{cfuncdesc}
 
+\begin{cfuncdesc}{const char*}{Py_GetBuildNumber}{}
+  Return a string representing the Subversion revision that this Python
+  executable was built from.  This number is a string because it may contain a
+  trailing 'M' if Python was built from a mixed revision source tree.
+\end{cfuncdesc}
+
 \begin{cfuncdesc}{const char*}{Py_GetPlatform}{}
   Return the platform identifier for the current platform.  On \UNIX,
   this is formed from the ``official'' name of the operating system,
index 4efe5f6f27277fbd9cb4bdadd19e014dcb33e168..7ffa35d9bdbba966125bb4b40422de533a18364c 100644 (file)
@@ -27,6 +27,12 @@ It is always available.
   \versionadded{2.0}
 \end{datadesc}
 
+\begin{datadesc}{build_number}
+  A string representing the Subversion revision that this Python executable
+  was built from.  This number is a string because it may contain a trailing
+  'M' if Python was built from a mixed revision source tree.
+\end{datadesc}  
+
 \begin{datadesc}{builtin_module_names}
   A tuple of strings giving the names of all modules that are compiled
   into this Python interpreter.  (This information is not available in
index e309078a69193df5bd185c88030a77884273d371..6cf33d8723f4d482c6d392011282d76697c86f7c 100644 (file)
@@ -108,6 +108,7 @@ PyAPI_FUNC(const char *) Py_GetPlatform(void);
 PyAPI_FUNC(const char *) Py_GetCopyright(void);
 PyAPI_FUNC(const char *) Py_GetCompiler(void);
 PyAPI_FUNC(const char *) Py_GetBuildInfo(void);
+PyAPI_FUNC(const char *) Py_GetBuildNumber(void);
 
 /* Internal -- various one-time initializations */
 PyAPI_FUNC(PyObject *) _PyBuiltin_Init(void);
index ab01deb387364b4ba1506dee4617706d049674b8..0ce2afa685b94c3b5d2024bf22f6ad7619b13cd9 100644 (file)
@@ -349,7 +349,9 @@ buildno: $(PARSER_OBJS) \
                $(SIGNAL_OBJS) \
                $(MODOBJS) \
                $(srcdir)/Modules/getbuildinfo.c
-       if test -f buildno; then \
+       if test -d .svn; then \
+               svnversion . >buildno; \
+       elif test -f buildno; then \
                expr `cat buildno` + 1 >buildno1; \
                mv -f buildno1 buildno; \
        else echo 1 >buildno; fi
@@ -444,7 +446,7 @@ Modules/Setup: $(srcdir)/Modules/Setup.dist
 # Special rules for object files
 
 Modules/getbuildinfo.o: $(srcdir)/Modules/getbuildinfo.c buildno
-       $(CC) -c $(PY_CFLAGS) -DBUILD=`cat buildno` -o $@ $(srcdir)/Modules/getbuildinfo.c
+       $(CC) -c $(PY_CFLAGS) -DBUILD=\"`cat buildno`\" -o $@ $(srcdir)/Modules/getbuildinfo.c
 
 Modules/getpath.o: $(srcdir)/Modules/getpath.c Makefile
        $(CC) -c $(PY_CFLAGS) -DPYTHONPATH='"$(PYTHONPATH)"' \
index bd004912d8297e3059e4e7da3e8b377fc3c18a95..d4aaa744a643a057a896191c20d9c6d05d277541 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,10 @@ What's New in Python 2.5 alpha 1?
 Core and builtins
 -----------------
 
+- Patch #1382163: Expose Subversion revision number to Python.  New C API
+  function Py_GetBuildNumber().  New attribute sys.build_number.  Build number
+  is now displayed in interactive prompt banner.
+
 - Implementation of PEP 341 - Unification of try/except and try/finally.
   "except" clauses can now be written together with a "finally" clause in
   one try statement instead of two nested ones.  Patch #1355913.
index b541bb64c8f4b63d212f533479a21f69a2dde6ce..8b1ca22f3ab3b9b60b2837ebccedfdf988cb3c5f 100644 (file)
@@ -21,7 +21,7 @@
 #endif
 
 #ifndef BUILD
-#define BUILD 0
+#define BUILD "0"
 #endif
 
 const char *
@@ -29,6 +29,12 @@ Py_GetBuildInfo(void)
 {
        static char buildinfo[50];
        PyOS_snprintf(buildinfo, sizeof(buildinfo),
-                     "#%d, %.20s, %.9s", BUILD, DATE, TIME);
+                     "%s, %.20s, %.9s", BUILD, DATE, TIME);
        return buildinfo;
 }
+
+const char *
+Py_GetBuildNumber(void)
+{
+       return BUILD;
+}
index d9f133705705d68ef8db9506a0ceab7596ab9bb1..f97a56deb5b25af0eab8a2fa22f45d7fdafc2caa 100644 (file)
@@ -1003,6 +1003,9 @@ _PySys_Init(void)
        PyDict_SetItemString(sysdict, "hexversion",
                             v = PyInt_FromLong(PY_VERSION_HEX));
        Py_XDECREF(v);
+       PyDict_SetItemString(sysdict, "build_number",
+                            v = PyString_FromString(Py_GetBuildNumber()));
+       Py_XDECREF(v);
        /*
         * These release level checks are mutually exclusive and cover
         * the field, so don't get too fancy with the pre-processor!