Tutorial To Contribute To The Cpython Project Documentation: Release 0.0
Tutorial To Contribute To The Cpython Project Documentation: Release 0.0
project Documentation
Release 0.0
Victor Stinner
1 Getting Help 1
1.1 Active Core Developers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 #python-dev channel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.3 Core-mentorship mailing list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.4 Developer Guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.5 Contributors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.6 Looking for help on a specific Python module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2 Getting Started 3
2.1 Build CPython on Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.2 Build CPython on Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.3 Build CPython on macOS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
4 Python Community 9
4.1 Code Of Conduct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
4.2 Diversity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
4.3 CPython Communication Channels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
5 Run tests 11
5.1 Introduce a Bug . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
5.2 Run tests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
5.3 Fix the bug . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
5.4 Run the whole test suite . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
i
7.5 Check for reference leaks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
ii
CHAPTER 1
Getting Help
This tutorial is an early draft. It is likely that you will quickly be blocked by an incomplete section (like “XXX”) or a
missing section. Don’t hesistate to complain, ask for help, and report issues!
While the CPython developers has more than 100 core developers, some of them “left” the project and are no more
active.
GitHub statistics on contributors can help to identify active contributors if you select a recent time window, like last 6
or 12 months.
Developers available to mentor new contributors:
• Victor Stinner, lives in France, works for Red Hat, core dev since 2010. IRC nickname: vstinner on Freen-
ode. Timezone: France (Paris) local clock.
• Zachary (Zach) Ware, living in the US (midwest), working as an independent consultant, core dev since 2013.
IRC nickname: zware on Freenode. Timezone: US/Central.
1
Tutorial to contribute to the CPython project Documentation, Release 0.0
1.5 Contributors
Contributors are also encouraged to help other contributors since new comers are the most experienced in issues to
start contributing for CPython :-)
• Stéphane Wirtel, living in Belgium, working as an independent consultant, contributor since 2014. IRC nick-
name: matrixise on Freenode. Timezone: Europe/Brussels.
The Expert Index lists maintainers for the some but not all Python modules.
Getting Started
Goals:
• Get a running Python executable built manually
• Run basic sanity checks to make sure that your executable is working
Requirements:
• Know CPython, Git and the C compiler of your operating system
See also Build CPython on macOS for specific instructions for macOS.
• Install Git:
– Fedora: sudo dnf install -y git-core
– Debian: sudo apt-get install -y git-core
• Clone the GitHub cpython project: git clone https://github.com/python/cpython.git
which creates a cpython/ directory. The history starts in 1991 so be patient, the clone can take several
minutes!
• Get CPython dependencies:
– Fedora:
3
Tutorial to contribute to the CPython project Documentation, Release 0.0
Single command:
./configure --with-pydebug && make
Or detailed instructions:
• Configuration Python in debug mode: ./configure --with-pydebug
• Build CPython: make
• There is no need to install Python.
For example, with a missing dependency, the make command will show the optional modules which do not compile
The necessary bits to build these optional modules were not found:
_lzma
In this case, you have to install the xz library. For Fedora 25 and 26, it’s xz-devel, but normally, this dependency
is installed with builddep python3. For Debian/Ubuntu, this dependency should be installed with apt-get
build-dep python3
If everything is fine, you are done! Let’s move to the next section: XXX!
If something goes wrong, see Getting Help.
Guide to build the master branch of CPython. Other Python versions need a different Visual Studio version.
To develop on CPython, the best is to enable all debug checks and so compile Python in “debug mode”.
• Install homebrew
• Install Git: brew install git
• XXX install OpenSSL
Single command:
Or detailed instructions:
• Configuration Python in debug mode: ./configure --with-pydebug
• Build CPython: make
• There is no need to install Python.
XXX how to check “setup” output and detect missing dependencies?
If everything is fine, you are done! Let’s move to the next section: XXX!
If something goes wrong, see Getting Help.
For more information about the compilation, you can read the compiling section of the devguide.
Badge: “getting_started”.
CPython core isn’t the easiest place to start. The development process is rather enterprisy with long release cycles and
rigid backwards compatibility policy. CPython also support a lot of platforms and CPU architectures.
How can you start? Where? That’s an hard question. CPython is old and widely used: any change must be carefully
discussed to remain Python homogenous. For bug fixes, the most complex part is the backward compatibility.
It’s very hard to find “easy issue”. First, just watch the current activity to get some ideas.
• To start, the best is maybe to look at recent commits to see what is currently done to get some ideas: https:
//github.com/python/cpython/commits/master
• Look also at active bugs: see https://bugs.python.org/ homepage, and maybe the second and third pages
• You may also look at ideas currently discussed on the https://mail.python.org/mailman/listinfo/python-ideas
mailing list
To find an easy issue, persistence is the key :-)
Contribute to CPython? What is CPython? CPython is made of many parts:
• CPython source code: basically made of 50% Python and 50% C code
• Build system: complex tools to build Python on all platforms, Visual Studio project for Windows
• Windows and macOS installer
• 233,000 lines of documentation written with Sphinx
• Documentation translated to multiple languages: french, japanese, and other languages
• Bug tracker: bugs.python.org which has its own “meta” bug tracker for bugs in the bug tracker :-)
• GitHub project: pull requests, host the Git repository
• Travis CI to run the test suite on Linux and check the documentation
• AppVeyor CI to run the test suite on Windows
• Buildbot master and many workers to run the test suite as post-commit on many variables architectures and
operating systems
7
Tutorial to contribute to the CPython project Documentation, Release 0.0
Python Community
Goals:
• Know the CPython community, code of conduct, the diversity statement and communication channels
The Python community wants to be welcome and fair with everyone and so has written down a code of conduct to
decide how to handle conflicts: Python Community Code of Conduct.
The Code of Conduct applies to most, if not all, Python mailing lists, to the bug tracker, etc.
Questions/comments/reports? See the contact information at the end of Python Community Code of Conduct.
See also Proposal for procedures regarding CoC actions.
Action: [ Click to confirm that you read the code of conduct :-) ]
4.2 Diversity
Diversity Statement:
The Python Software Foundation and the global Python community welcome and encourage participation
by everyone. Our community is based on mutual respect, tolerance, and encouragement, and we are
working to help each other live up to these principles. We want our community to be more diverse:
whoever you are, and whatever your background, we welcome you.
• https://www.python.org/community/diversity/
• http://wiki.python.org/moin/DiversityInPython
For example, don’t say “hey guys!” but “hey everyone!”.
Action: [ Click to confirm that you read the diversity statement :-) ]
9
Tutorial to contribute to the CPython project Documentation, Release 0.0
Run tests
def do_POST(self):
+ bug
"""Serve a POST request.
(...)
======================================================================
ERROR: test_post (test.test_httpservers.CGIHTTPServerTestCase)
----------------------------------------------------------------------
(continues on next page)
11
Tutorial to contribute to the CPython project Documentation, Release 0.0
----------------------------------------------------------------------
(...)
FAILED (errors=1)
(...)
Find the code of the failing tests, see most recent call in the traceback:
File ".../Lib/test/test_httpservers.py", line 726, in test_post
res = self.request('/cgi-bin/file2.py', 'POST', params, headers)
Flags:
• -j0: run tests in parallel using as many test processes than your CPUs
• -r: randomize tests
• -W: hide test output on success, but write tests output on failure
Goal: be able to write a Python fix with an unit test, but not publish it.
15
Tutorial to contribute to the CPython project Documentation, Release 0.0
Goal: be able to write a C fix with an unit test (but not publish it).
17
Tutorial to contribute to the CPython project Documentation, Release 0.0
• http://bugs.python.org/
• Click on [Register]
• Fill the form
• XXX
• Confirm your email
• XXX
• Log in
• Click on [Create New]
• Write a short title
• Describe the bug or feature request
• [Submit New Entry]
19
Tutorial to contribute to the CPython project Documentation, Release 0.0
• Specify the OS
• Specify your Python version
• Write a script to reproduce the bug, the best is if the script doesn’t use third-party modules
21
Tutorial to contribute to the CPython project Documentation, Release 0.0
• Sign https://www.python.org/psf/contrib/contrib-form/
• Wait. . . the confirmation is done manually by humans, so be prepared to wait up to one week (usually 3 business
days)
For legal question, you can send an email to legal@python.org .
Once you have your patch (see XXX Python or XXX C fix sections), make sure that your changes are in a local branch:
Fix a race condition in the email module. Before xxx failed. It now works
well!
9.6.1 Manually
23
Tutorial to contribute to the CPython project Documentation, Release 0.0
Reading code written by others can be a good practice to learn from others, and learn the Python workflow.
The repository on GitHub has a page for the Pull Requests (PR) and in this case, you could go on the page and review
the proposed PR.
For example, we prefer to review the PR where the CLA is signed
Usually, if the CLA is not signed by the contributor, we prefer to ask to sign the document and wait for 3 business
days, its bugs.python.org account will be updated.
25
Tutorial to contribute to the CPython project Documentation, Release 0.0
To propose new ideas, the python-ideas mailing list is the good place.
• The python-idea mailing list
• python-ideas archives
• LWN: Things that won’t change in Python
• LWN: Ideas versus implementation
27
Tutorial to contribute to the CPython project Documentation, Release 0.0
To discuss more in depth the actual implementation of a feature, the python-dev mailing list is the good place.
• https://mail.python.org/mailman/listinfo/python-dev
• https://mail.python.org/pipermail/python-dev/
29
Tutorial to contribute to the CPython project Documentation, Release 0.0
14.1 Travis CI
XXX
Configuration: .travis.yml file.
14.2 AppVeyor
XXX
Configuration: .github/appveyor.yml file.
14.3 Buildbots
31
Tutorial to contribute to the CPython project Documentation, Release 0.0
15.1 python-committers
While the python-committers mailing list is public (anyone can be archives), only core developers are allowed to
subscribe and to send messages.
33
Tutorial to contribute to the CPython project Documentation, Release 0.0
Requirements:
• Be nice, polite and respectful
• Know what they are talking about, and explain their reasoning well. Contributions to the bug tracker that
demonstrate an understanding of our code culture. . . specifically, commenting that a bug should be closed (and
why) and demonstrating an understanding of what python versions a bug applies to (enhancement versus bug
fix, when to backport a bug fix and when not). See the Status of Python branches
• Don’t close a bug if it’s not well understood to not “lose” information (closed bugs are ignored in search by
default, and hidden from the main page).
A good triager must be familiar with our codebase, our bug tracker, and our “code culture”, in particular:
• being able to find (or remember) duplicate and related issues, link them to each other, and closing the duplicates
as necessary;
• being able to correctly select the versions affected by the issue, the components, the stage, and other fields;
• being able to verify if the issue can be reproduced and if the report is valid or not;
• being able to recognize commonly reported issues and link to the appropriate FAQ or other existing is-
sues/explanations;
• being able to identify and specify the next step, possibly suggesting which files should be updated to fix the
issue;
• being able to locate the commits that might have introduced the issue, and the reason for the change;
• being able to leave meaningful opinions on the issue (e.g. whether it should be addressed or closed and why);
It usually takes some time and a few contributions before people can do these things.
Responsability for bug tracker:
• Request more information if a report is incomplete
• Ping original reporters if they don’t reply
• Adjust Python version, component, bug type, etc.
• Rewrite the issue title if needed
• Close duplicated bugs as DUPLICATE
• Close irrevelant bugs as NOTABUG
Nice to have, but not a strong requirement:
A core developer has to identify an active contributor on the bug tracker, or a contributor can also ask for more power
themselves.
If the contributor reachs the requirements listed in the previous section, the core developer give them triage.
15.6 Mentoring
“A core dev should know not only what changes should be made, but also (and this is more important)
what changes should not be made.” – Serhiy Storchaka
The historical definition is that CPython core developer has the commit bit, is able to push a change to upstream, to
the GitHub cpython project.
Officially, other core developers don’t expect and cannot expect anything from a developer.
The unwritten definition is that other core developers expect from a core developer to maintain their contributions:
long term commitement, since CPython requires long term support: 5 years or longer. If a core developer writes a new
large chunk of code but then disappears for whatever reasons, there is a risk that the code dies slowly.
For example, Python branches are supported for 5 years. See the Status of Python branches.
Most of the following core developer requirements are already expected from regular contributors.
Know to be nice and respectful to the others, at least to the extent they’re nice and respectful to yourself :-) We don’t
have a rock-star (or “bro”, “wizard”, “ninja”, whatever the hyperbole of the day is) culture here.
15.7.2 Humility
Show a bit of humility towards existing work and try to understand the decisions behind something before deciding to
change it all. That said, given Python’s current position on the technical evolution and adoption curve, we get less and
less proposals for sweeping changes (perhaps not enough, actually, since even when rejected, they help challenge the
status quo).
When someone lands a big chunk of code, we need someone to maintain it for at least the next 2 years. Maybe for the
next 10 years.
It is not strictly a requirement, it’s more a whish from other core developers.
15.6. Mentoring 35
Tutorial to contribute to the CPython project Documentation, Release 0.0
15.7.4 Reviews
Review patches and pull requests. While we don’t require not expect newcomers to review, we expect that core
developers dedicate a part of their time on reviews. What it means is that core developers care about the quality of the
whole code base (and also the non-code parts), not only their own contributions to it.
Know the CPython workflow. Be aware of the pre-commit and post-commits CIs. How ideas are discussed. It’s not
only about writing and pushing patches. This part is also required from regular contributors, at least the experienced
ones.
Know the project’s lifecycle: Python has multiple maitained branches, some of them accept bugfixes, others only
security fixes. Deciding if a fix can or cannot be backported is a complex question.
Good quality patches: proposed changes are good (or almost good) at the first iteration. Or, if the code isn’t good
at the first iteration, the author is able to figure it out by themselves and doesn’t rush merge it. Of course, nobody is
perfect, which is why non-trivial code written by core developers ideally goes through a review phase anyway. But a
general sense of what is “in good state for review/merging” vs. “just a draft I’m working on” is indeed preferrable.
Pushing core means becoming responsible for this code. For regressions, backward compatibility, security, etc.
CPython has a long history and many unwritten strict rules. For example, backward compatibility is taken very
seriously. We don’t remove public functions in a minor release (3.x), but start with a deprecation period. It’s not
only about removing features, but also changing the behaviour. Even if Python has a wide test suite with a good code
coverage, some functions are still untested, or not fully tested.
15.8 Be patient
Be patient, being aware of Python complex code and workflow can take between 6 months and 2 years.
Usually the contributor doesn’t ask for themselves to become a core developer, but another core developer proposes to
promote them.
The main questions about a potential new core developer are:
• Would gaining core developer privileges improve their ability to contribute effectively (in my opinion or the
opinion of another core developer)?
• Do a core developer that is willing to mentor them trust their judgment on when things should be escalated for
further review & discussion (or even rejected outright) versus just going ahead and merging them?
The first step is to ask the contributor if they want to become a core developer. Since great power comes with great
responsibilities, it’s not uncommon that some contributors prefer to remain contributors. Technically, it doesn’t prevent
to propose pull requests, reviews, etc.
If the contributor agrees, usually a private discussion starts. Sadly, the discussion is private because it’s tricky to
discuss someone skills in public. A negative vote can be harmful, whereas it isn’t the intend.
Sometimes, the contributor is evaluated as “too green” and someone can propose to become their mentor to help them
to learn the workflow, give advices on pull requests, etc.
The real vote occurs on the python-committers list where only core developers are allow to post. The developer
who proposes to promote someone has to write a very short biography, list previous contributions and evaluates the
contributor skills.
A negative vote can still happen at this point. It doesn’t mean that the contributor will never become a core dev, just
that they need more practice.
If the vote is positive, the contributor sends their SSH key and will be subscribed to the python-committers mailing
list.
• Proposing Carol Willing to become a core developer (Brett Cannon, May 2017)
• Proposed new core developer – Mariatta Wijaya (Raymond Hettinger, January 2017)
• Promote Xiang Zhang as a core developer (Victor Stinner, Nov 2016)
• commit privileges for INADA Naoki (Yury Selivanov, Sept 2016)
Other votes:
• commit privs given to Maciej Szulik for bugs.python.org work (Brett Cannon, December 2016): https://hg.
python.org/tracker/ repository
Except one or two exceptions, no core developer is paid to contribute to CPython: we are all volunteers. Don’t be
surprised to not get any kind of feedback in next hours, or sometimes even before one week.
Most core developers have a specific interest in specific areas of the code, and so not all core developers are interested
by your specific issue.
39
Tutorial to contribute to the CPython project Documentation, Release 0.0
• genindex
• modindex
• search
41