Case Study: CPython Development Workflow (v1 engine)
It’s no secret that Mergify is written in Python. Our engine is open source and is free for anyone to contribute to. That’s how we roll.
We’ve been doing Python for a long time, and that got us close to the development of Python itself and genuinely interested in their development processes.
A couple of years ago, the Python developers decided to move to git and GitHub for developing the language. What a smart move, right? 😉
What’s interesting for us is the automation workflow that Python built around GitHub. It’s pretty well setup and advanced compared to most projects. The CPython’s developers wrote and maintain bots to customize GitHub to their needs.
In this article, we decided to submit ourselves to an interesting exercise: we decrypted what CPython’s process for merging pull requests is, and how one could implement the same workflow using Mergify.
Merging rules
CPython merging rules are pretty simple. Let’s dissect the pull request #8297 to understand the process.
Once a pull request is created, there a few automatic checks that are being run such as continuous integration (tests), Contributors Licensed Agreement signed, etc. A human is then mandated to review the code and to approve it. Once it’s approved, it can be merged by a human — either the one that reviewed the patch, another one, or the author of the patch themselves if they want to have a final word. It is not visible in the above screenshot, but further digging indicates that some of the continuous integration jobs are mandatory: the merge button is greyed out if any of the jobs fail.
Overall, there is a couple of drawbacks in this process:
- It is possible to merge a pull request even if it has zero reviews. Basically, a developer could push the green button of merging without having to read the code. Using the “review” interface in GitHub makes sure you at least took a look at the files, preventing clicking the merge button in the wrong window—yes we’ve seen that.
- If a committer wants to merge a patch, it has to wait for the continuous integration system to finish. It is possible that the patch is approved while some of the test jobs are not finished yet, needing the reviewer to come back at a later unknown moment to push the merge button.
The good news is that it is possible to implement Python’s workflow—with a few improvements—using Mergify. It’ll fix those little drawbacks, while implementing the same process! How would you do that? Here’s an idea:
rules:
default:
protection:
required_status_checks:
contexts:
- continuous-integration/appveyor/pr
- continuous-integration/travis-ci/pr
required_pull_request_reviews:
required_approving_review_count: 1
enabling_label: ready-to-mergeWe’re not sure whether the Python folks would love to have the merge done with just a single human action—the review approval. There are teams that prefer to have a final merge action nonetheless. To that end, we’ve set enabling_label to the ready-to-mergelabel—once this label is set, Mergify automatically merges the pull request according to the rules. We set the rules to one reviewer and set the check jobs to be green.
Get Mergify’s stories in your inbox
Join Medium for free to get updates from this writer.
With such a configuration, CPython would have the same workflow it has currently, plus it would solve all of the small issues listed above:
- Impossibility to merge a pull request if nobody clicked on the “Approve” button of the review system.
- The merge automatically happens whenever the continuous integration finishes. There’s no need for a human to wait behind its screen to click a button.
No strict workflow
CPython development workflow has another flaw that is not obviousthere are not the only ones. Many projects relying on pull requests chose to ignore the risk of merging code that seems to work while it’s going to break master because it’s not up-to-date. We wrote a few weeks ago an article on what we call the strict workflow that can solve this, and I beg you to read it to understand what might be wrong there.
Backports
CPython creates a stable branch each time it releases a new version of the language. There are branches for Python 2.7, Python 3.6, Python 3.7, etc.
Bugs happen, and when they get fixed in the master branch, they need to be ported back to stable branches. Usually that process is done manually by developers, but in this case, the CPython developers have been smart.
They created a bot, named miss-islington, that is in charge of doing the grunt work of backporting the patches to old branches.
It works that way:
- A human puts a label such as
needs backport to 3.7on a pull request. - Once the pull request is merged, miss-islington creates a copy of this pull request targeting the
python:3.7branch. - A human needs to approve the pull request.
- miss-islington merges the pull request if the continuous integration system validates it.
We think it’s an excellent workflow. Why? Because it’s exactly the one we implemented inside Mergify. Who said we are biased?
If you want you own Miss Islington for doing backports and ease your life, just write something like this in your .mergify.yml :
rules:
default:
automated_backport_labels:
"needs backport to 2.7": python:2.7
"needs backport to 3.6": python:3.6
"needs backport to 3.7": python:3.7This configuration file makes Mergify creates pull requests automatically when a pull request is merged with a label such as needs backport to 2.7. Fantastic!
We built Mergify to be able to adapt to most workflows. We hope that many more projects will be able to use it and automate their development workflows.
Feel free to suggest projects with different workflows in the comment section. We’d be delighted to feature them as case studies. 😀







