Important
This is part of a Draft of the Python Contributor’s Guide. Text in square brackets are notes about content to fill in. Currently, the devguide and this new Contributor’s Guide co-exist in the repo. We are using Sphinx include directives to demonstrate the re-organization. The final Contributor’s Guide will replace the devguide with content in only one place. We welcome help with this!
The [Plan for the Contributor’s Guide] page has more details about the current state of this draft and how you can help. See more info about the Contributor Guide in the discussion forum: Refactoring the DevGuide.
Get the source code¶
Note
[This is the Get the source code section from the devguide. We might need to edit it to clarify that some steps are only needed for code contribution.]
The CPython repo is hosted on GitHub. To get a copy of the source code you should fork the Python repository on GitHub, create a local clone of your personal fork, and configure the remotes.
You will only need to execute these steps once per machine:
Press Fork on the top right.
When asked where to fork the repository, choose to fork it to your username.
Your fork will be created at
https://github.com/<username>/cpython
.Clone your GitHub fork (replace
<username>
with your username):$ git clone git@github.com:<username>/cpython.git
(You can use both SSH-based or HTTPS-based URLs.)
Add an
upstream
remote, then configuregit
to pullmain
fromupstream
and always push toorigin
:$ cd cpython $ git remote add upstream https://github.com/python/cpython $ git config --local branch.main.remote upstream $ git remote set-url --push upstream git@github.com:<your-username>/cpython.git
Verify that your setup is correct:
$ git remote -v origin git@github.com:<your-username>/cpython.git (fetch) origin git@github.com:<your-username>/cpython.git (push) upstream https://github.com/python/cpython (fetch) upstream git@github.com:<your-username>/cpython.git (push) $ git config branch.main.remote upstream
For more information about these commands see Git Bootcamp and Cheat Sheet.
If you did everything correctly, you should now have a copy of the code
in the cpython
directory and two remotes that refer to your own GitHub fork
(origin
) and the official CPython repository (upstream
).
If you want a working copy of an already-released version of Python,
that is, a version in maintenance mode, you can checkout
a release branch. For instance, to checkout a working copy of Python 3.13,
do git switch 3.13
.
You will need to re-compile CPython when you do such an update.
Do note that CPython will notice that it is being run from a working copy. This means that if you edit CPython’s source code in your working copy, changes to Python code will be picked up by the interpreter for immediate use and testing. (If you change C code, you will need to recompile the affected files as described below.)
Changes for the documentation can be made from the same repository; see Getting started.
Install pre-commit as a Git hook¶
To make sure your code is linted correctly, we recommend setting up pre-commit as a Git hook:
$ pre-commit install --allow-missing-config
pre-commit installed at .git/hooks/pre-commit
Now pre-commit will run automatically on git commit
.