Version 3 (modified by Chris Jerdonek, 13 years ago) (diff)

Added preliminary instructions on how to install new versions of Python on a Mac.

WebKit Python Guidelines and Tips

Here is an overview of WebKit's use of Python.

  • Most of the Python code is in WebKitTools/Scripts/webkitpy.
  • WebKitTools/Scripts also contains some Python code in the form of end-user scripts. Generally, we try to keep as much of the code in webkitpy as possible since this allows the code to be organized more nicely, for unit tests to be in companion files, etc.
  • Unit test files are in correspondence with modules. For example, if is the name of a module, its unit test file would be and would lie in the same directory.
  • Informally, we try to follow PEP8.
  • We put all third-party Python code in webkitpy/thirdparty.
  • Scripts/test-webkitpy unit tests the Python code.
  • Most of WebKit's Python scripts require Python 2.5 to run.

Installing a new version of Python

[Most of these instructions are Mac-specific.]

You can tell what version of Python you are currently using by typing--

python -V

Before trying to install a new version, check whether your machine already has other versions installed. From a Mac, you can try reading the man page--

man python

On Snow Leopard you will find that your machine comes with Python 2.5, 2.6, and 3.0. The man page also provides instructions on how to switch your system between these system-installed versions.

If you need to install a new version not on your machine, you can use MacPorts to do this. MacPorts allows you to install Python versions alongside your system versions without interfering with them. After installing MacPorts, simply type (for example)--

sudo port install python26

We recommend that Tiger users with 2.3 install Python 2.6 for starters.

You should probably also install python_select using MacPorts--

sudo port install python_select

The python_select command allows you to quickly go back and forth between Python versions, like so--

> python -V
Python 2.6.4
> sudo python_select python24
Selecting version "python24" for python
> python -V
Python 2.4.6

To find out what versions of Python you can switch to using python_select, type--

python_select -l