Before you start to write code, it is important to have a good git branching strategy for easy collaboration with other contributors. There are several strategies proposed for git branching. The blog post here gives an overview of different alternatives. We follow the GitHub flow as our branching strategy. As per that branching strategy, we first create a branch for a new feature, then write code, document it, test it, review the code and finally merge it back to master branch.
The workflow for creating a branch and writing code is given below:
1. Clone the master branch to your local machine using the following command:
git clone https://github.com/<your-github-id>/<project-name.git> local-repo-name
2. Change into your local-repo-name and connect your local repository to the upstream main repository from which it was cloned (this is important to fetch latest changes to the main repository)
git remote add upstream https://github.com/<your-github-id>/<project-name.git>
3. Create a feature branch (See here for illustration) for making your changes in GitHub. Then, checkout the created branch to your local repository using the following commands:
git pull
git checkout branch-name
4. Write code. While writing code, it is important to follow coding guidelines. There are many guidelines proposed such as PEP8 and Google style guide. Pick one and follow consistently. In our group, we follow Google style guide for Python for writing code.
5. As you are coding, periodically merge in work from the master branch. Specifically, you need to fetch changes in the original repository and then merge them into your branch using the following commands:
git fetch upstream
git merge upstream/master
6. After you are done with coding, proceed to step 3 of the Python package development process.
Best Practices
Keep the code simple and readable.
Avoid obfuscated code.
Make sure the code is compatible across the Python versions that the package supports.
Resources