Where is the Python startup banner defined?

I'm compiling several different versions of Python for my system, and I'd like to know where in the source the startup banner is defined so I can change it for each version. For example, when the interpreter starts it displays

Python 3.3.1 (default, Apr 28 2013, 10:19:42) 
[GCC 4.7.2 20121109 (Red Hat 4.7.2-8)] on linux
Type "help", "copyright", "credits" or "license" for more information.

I'd like to change the string default to other things to signal which version I'm using, but I'm also interested in how the whole shebang is assembled. Where is this defined?


Let's use grep to get in the ballpark. I'm not going to bother searching for default because I'll get too many results, but I'll try Type "Help", which should not appear too many times. If it's a C string, the quotes will be escaped. We should look for C strings first and Python strings later.

Python $ grep 'Type \\"help\\"' . -Ir
./Modules/main.c:    "Type \"help\", \"copyright\", \"credits\" or \"license\" " \

It's in Modules/main.c, in Py_Main(). More digging gives us this line:

fprintf(stderr, "Python %s on %s\n",
    Py_GetVersion(), Py_GetPlatform());

Because "on" is in the format string, Py_GetPlatform() must be linux and Py_GetVersion() must give the string we want...

Python $ grep Py_GetVersion . -Irl

That looks promising...

PyOS_snprintf(version, sizeof(version), "%.80s (%.80s) %.80s",
              PY_VERSION, Py_GetBuildInfo(), Py_GetCompiler());

We must want Py_GetBuildInfo(), because it's inside the parentheses...

Python $ grep Py_GetBuildInfo . -Irl

That looks a little too obvious.

const char *
    static char buildinfo[50 + sizeof(HGVERSION) +
                          ((sizeof(HGTAG) > sizeof(HGBRANCH)) ?
                           sizeof(HGTAG) : sizeof(HGBRANCH))];
    const char *revision = _Py_hgversion();
    const char *sep = *revision ? ":" : "";
    const char *hgid = _Py_hgidentifier();
    if (!(*hgid))
        hgid = "default";
    PyOS_snprintf(buildinfo, sizeof(buildinfo),
                  "%s%s%s, %.20s, %.9s", hgid, sep, revision,
                  DATE, TIME);
    return buildinfo;

So, default is the name of the Mercurial branch. By examining the makefiles, we can figure out that this comes from the macro HGTAG. A makefile variable named HGTAG produces the variable, and that variable is run as a command. So,

Simple solution

When building Python,

Python $ ./configure
Python $ make HGTAG='echo awesome'
Python $ ./python
Python 3.2.3 (awesome, May  1 2013, 21:33:27) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.

Need Your Help

Scala initializing class level Array variable within a method

arrays scala

class Foo() { val array // how do I leave initialization till later? def initializeArray(size : Int) = array = Array.ofDim[Int](size) } The above code won't compile, so how do I initialize my

Search string in a subject string in Outlook VBA

string vba contains email-integration

I am using VBA in MSOutlook to search a string in subject line and if it is present then prompt a warning if it is true

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.