Contributing to PyClaw code development

If you are interested in contributing to PyClaw development, you can add your contribution through making patches; see Making a patch, for quick fixes. However, for substantial contributions, you may want to consider forking PyClaw github repository, see Making a fork, for substantial contributions, and making pull requests for your changes. Here we introduce those two methods for contributing to PyClaw source code. For more information about the forking model, please see Development workflow.

Getting PyClaw from the development repository

After installing git, you can get the latest PyClaw source from the PyClaw github repository using the following command:

$ git clone git://github.com/clawpack/pyclaw.git

You now have a copy of the code tree in the new pyclaw directory. From time to time you may want to pull down the latest code. Do this with:

cd pyclaw
git pull

The tree in pyclaw will now have the latest changes from pyclaw repository.

Making a patch, for quick fixes

You’ve discovered a bug or something else you want to change in PyClaw .. — excellent!

You’ve worked out a way to fix it — even better!

You want to tell us about it — best of all!

The easiest way is to make a patch or set of patches. Here we explain how. Making a patch is the simplest and quickest, but if you’re going to be doing anything more than simple quick things, please consider Making a fork, for substantial contributions instead.

Following are the steps for making patches:

  1. Tell git who you are so it can label the commits you’ve made:

    git config --global user.email you@yourdomain.example.com
    git config --global user.name "Your Name Comes Here"
    
  2. If you don’t already have one, clone a copy of the PyClaw repository:

    git clone git://github.com/clawpack/pyclaw.git
    cd pyclaw
    
  3. Make a ‘feature branch’. This will be where you work on your bug fix. It’s nice and safe and leaves you with access to an unmodified copy of the code in the main branch:

    git branch the-fix-im-thinking-of
    git checkout the-fix-im-thinking-of
    
  4. Do some edits, and commit them as you go:

    # hack, hack, hack
    # Tell git about any new files you've made
    git add somewhere/tests/test_my_bug.py
    # commit work in progress as you go
    git commit -am 'BF - added tests for Funny bug'
    # hack hack, hack
    git commit -am 'BF - added fix for Funny bug'
    

    Note the -am options to commit. The m flag just signals that you’re going to type a message on the command line. The a flag — you can just take on faith — or see why the -a flag?.

  5. When you have finished, check you have committed all your changes:

    git status
    
  6. Finally, make your commits into patches. You want all the commits since you branched from the master branch:

    git format-patch -M -C master
    

    You will now have several files named for the commits:

    0001-BF-added-tests-for-Funny-bug.patch
    0002-BF-added-fix-for-Funny-bug.patch
    

    Send these files to the PyClaw mailing list — where we will thank you warmly.

When you are done, to switch back to the main copy of the code, just return to the master branch:

git checkout master

Making a fork, for substantial contributions

If you find you have done some patches, and you have one or more feature branches, you will probably want to start working on a separate fork and make pull requests.

You need to make a fork only once. The instructions here are very similar to the instructions at http://help.github.com/forking/ — please see that page for more detail. We’re repeating some of it here just to give the specifics for the PyClaw project, and to suggest some default names.

Set up and configure a github account

If you don’t have a github account, go to the github page, and make one.

You then need to configure your account to allow write access — see the Generating SSH keys help on github help.

Create your own forked copy of PyClaw

  1. Log into your github account.

  2. Go to the PyClaw github home at PyClaw github.

  3. Click on the fork button:

    ../../../_images/forking_button.png

    Now, after a short pause and some ‘Hardcore forking action’, you should find yourself at the home page for your own forked copy of PyClaw.

Set your local clone of PyClaw to point to your fork and to the main repository

If you already have a local clone of the main PyClaw repository, you can set the clone origin to be your fork while keeping the main repository as an additional remote that you can pull from. The following are the required steps:

# checkout and refresh master branch from main repo
git checkout master
git pull origin master
# rename pointer to main repository to 'upstream'
git remote rename origin upstream
# point your repo to default read / write to your fork on github
git remote add origin git@github.com:your-user-name/pyclaw.git
# push up any branches you've made and want to keep
git push origin the-fix-im-thinking-of

Then you can, if you want, follow the Development workflow.

You also can directly clone your fork and set it to additionally point to the main repository. Here are the required steps:

  1. Clone your fork to your local machine with

    $ git clone git@github.com:your-user-name/pyclaw.git
    
  2. To view all the branches you have

    $ cd pyclaw
    $ git branch -a
    

    You’ll get something like:

    * master
    remotes/origin/master
    

    This tells you that you are currently on the master branch, and that you also have a remote connection to origin/master.

  3. To view the URLs of the remote repositories you have, try

    $ git remote -v
    

    which will point to your github fork in this case.

  4. Now you want to connect to the upstream PyClaw github repository, so you can merge in changes from trunk. To point your clone to the main PyClaw repository, do:

    $ git remote add upstream git://github.com/clawpack/pyclaw.git
    

upstream here is just the arbitrary name we’re using to refer to the main PyClaw repository at PyClaw github.

Note that we’ve used git:// for the URL rather than git@. The git:// URL is read only. This means that we can’t accidentally (or deliberately) write to the upstream repository, and we are only going to use it to merge into our own code.

  1. Just for your own satisfaction, show yourself that you now have a new ‘remote’, with git remote -v show, giving you something like:

    upstream git://github.com/clawpack/pyclaw.git (fetch)
    upstream git://github.com/clawpack/pyclaw.git (push)
    origin   git@github.com:your-user-name/pyclaw.git (fetch)
    origin   git@github.com:your-user-name/pyclaw.git (push)