This document is meant to help get you the information needed to get the source code to Python, compile it for debugging purposes, set up your tools, and have a basic idea of the directory structure of the source code. For organizational purposes, details of the tools needed to work with the Python source code is kept in the dev FAQ, so you will probably want to have it easily available as you read this document.
Checking out the code
Python always has the in-development version of the current major versions along with the last minor release of each major version. For instance, if Python 2.6 was the latest release (and thus has a major version of 2 and a minor version of 6), then the in-development 2.7 branch is available along with the maintenance branch for 2.6.
For each branch there is read-only access for the general public and read-write access for those with commit privileges (called "core developers"). The location of these branches and the steps to check out the code are listed in the dev FAQ.
Compiling for debugging
Python has two features to aid in developing for it. First, there is a Py_DEBUG compilation flag which turns on some features in the interpreter which will help with debugging. While this is not the only compilation flag available (see Misc/SpecialBuilds.txt in a checkout for all of them), it is the basic one that you should always use as it tends to catch bugs more often than running a build of Python without the flag.
The other feature is support for using code directly from a checkout of Python. This is handy as it means you do not need to install your build of Python but can just use the build in-place. It also means that when you edit code in your checkout you get to see the results without having to install the changed files as well.
The steps to compile a debug version of Python are specified in the dev FAQ.
Editors and Tools
Python includes within its source tree some files to help work with various popular editors and tools. A list of those tools and what is available for them can be found in the dev FAQ.
Directory Structure
There are several top-level directories in the Python source tree. Knowing what which one is meant to hold will help you find where a certain piece of functionality is implemented. Do realize, though, there are always exceptions to every rule.
- Demo
- Example code goes here. This directory is not well-maintained and thus should not be considered best-of-breed in terms how best to accomplish something with the newest version of Python.
- Doc
- The official documentation. This is what http://docs.python.org/ uses. The tools for building the documentation is kept in another repository. To build the docs, see Doc/README.txt.
- Grammar
- Contains the EBNF grammar file for Python.
- Include
- Contains all interpreter-wide header files.
- Lib
- The part of the standard library implemented in pure Python is here.
- Mac
- Mac-specific code for things such as using IDLE as an OS X application.
- Misc
- Things that do not belong elsewhere. Typically this is varying kinds of documentation.
- Modules
- The part of the standard library (plus some other code) that is implemented as extension modules.
- Objects
- Code for all built-in types.
- PC
- Windows-specific code along with build files for VC 6, 7, & 8 along with OS/2.
- PCbuild
- Build files for VC 9 and newer.
- Parser
- Code related to the parser. The definition of the AST nodes is also kept here.
- Python
- The code that makes Python run. This includes the compiler, eval loop and various built-in modules.
- RISCOS : Not in Python 3.0
- RISC-specific files.
- Tools
- Various tools that are (or have been) used to maintain Python.
