[Python-checkins] commit of r41744 - in python/trunk: Doc/api/init.tex Doc/lib/libsys.tex Include/pythonrun.h Mac Makefile.pre.in Misc/NEWS Modules/getbuildinfo.c Python/sysmodule.c

barry.warsaw python-checkins at python.org
Sun Dec 18 02:27:38 CET 2005


Author: barry.warsaw
Date: Sun Dec 18 02:27:35 2005
New Revision: 41744

Modified:
   python/trunk/Doc/api/init.tex
   python/trunk/Doc/lib/libsys.tex
   python/trunk/Include/pythonrun.h
   python/trunk/Mac/   (props changed)
   python/trunk/Makefile.pre.in
   python/trunk/Misc/NEWS
   python/trunk/Modules/getbuildinfo.c
   python/trunk/Python/sysmodule.c
Log:
Expose Subversion revision number (calculated via "svnversion .") to Python.
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.


Modified: python/trunk/Doc/api/init.tex
==============================================================================
--- python/trunk/Doc/api/init.tex	(original)
+++ python/trunk/Doc/api/init.tex	Sun Dec 18 02:27:35 2005
@@ -272,6 +272,12 @@
   \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,

Modified: python/trunk/Doc/lib/libsys.tex
==============================================================================
--- python/trunk/Doc/lib/libsys.tex	(original)
+++ python/trunk/Doc/lib/libsys.tex	Sun Dec 18 02:27:35 2005
@@ -27,6 +27,12 @@
   \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

Modified: python/trunk/Include/pythonrun.h
==============================================================================
--- python/trunk/Include/pythonrun.h	(original)
+++ python/trunk/Include/pythonrun.h	Sun Dec 18 02:27:35 2005
@@ -108,6 +108,7 @@
 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);

Modified: python/trunk/Makefile.pre.in
==============================================================================
--- python/trunk/Makefile.pre.in	(original)
+++ python/trunk/Makefile.pre.in	Sun Dec 18 02:27:35 2005
@@ -349,7 +349,9 @@
 		$(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 @@
 # 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)"' \

Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Sun Dec 18 02:27:35 2005
@@ -12,6 +12,10 @@
 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.

Modified: python/trunk/Modules/getbuildinfo.c
==============================================================================
--- python/trunk/Modules/getbuildinfo.c	(original)
+++ python/trunk/Modules/getbuildinfo.c	Sun Dec 18 02:27:35 2005
@@ -21,7 +21,7 @@
 #endif
 
 #ifndef BUILD
-#define BUILD 0
+#define BUILD "0"
 #endif
 
 const char *
@@ -29,6 +29,12 @@
 {
 	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;
+}

Modified: python/trunk/Python/sysmodule.c
==============================================================================
--- python/trunk/Python/sysmodule.c	(original)
+++ python/trunk/Python/sysmodule.c	Sun Dec 18 02:27:35 2005
@@ -1003,6 +1003,9 @@
 	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!


More information about the Python-checkins mailing list