| 1 |
Contributing |
| 2 |
============ |
| 3 |
|
| 4 |
Submitting bugs |
| 5 |
--------------- |
| 6 |
|
| 7 |
Due diligence |
| 8 |
~~~~~~~~~~~~~ |
| 9 |
|
| 10 |
Before submitting a bug, please do the following: |
| 11 |
|
| 12 |
- Perform **basic troubleshooting** steps: |
| 13 |
|
| 14 |
- **Make sure you're on the latest version.** If you're not on the most recent version, your problem may have been |
| 15 |
solved already! Upgrading is always the best first step. |
| 16 |
- **Try older versions.** If you're already *on* the latest release, try rolling back a few minor versions (e.g. if |
| 17 |
on 1.7, try 1.5 or 1.6) and see if the problem goes away. This will help the devs narrow down when the problem |
| 18 |
first arose in the commit log. |
| 19 |
- **Try switching up dependency versions.** If the software in question has dependencies (other libraries, etc) try |
| 20 |
upgrading/downgrading those as well. |
| 21 |
|
| 22 |
- **Search the project's bug/issue tracker** to make sure it's not a known issue. |
| 23 |
- If you don't find a pre-existing issue, consider **checking with the mailing list and/or IRC channel** in case the |
| 24 |
problem is non-bug-related. |
| 25 |
|
| 26 |
What to put in your bug report |
| 27 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 28 |
|
| 29 |
Make sure your report gets the attention it deserves: bug reports with missing information may be ignored or punted back |
| 30 |
to you, delaying a fix. The below constitutes a bare minimum; more info is almost always better: |
| 31 |
|
| 32 |
- **What version of the core programming language interpreter/compiler are you using?** For example, if it's a Python |
| 33 |
project, are you using Python 2.7.3? Python 3.3.1? PyPy 2.0? |
| 34 |
- **What operating system are you on?** Windows? (Vista? 7? 32-bit? 64-bit?) Mac OS X? (10.7.4? 10.9.0?) Linux? (Which |
| 35 |
distro? Which version of that distro? 32 or 64 bits?) Again, more detail is better. |
| 36 |
- **Which version or versions of the software are you using?** Ideally, you followed the advice above and have ruled |
| 37 |
out (or verified that the problem exists in) a few different versions. |
| 38 |
- **How can the developers recreate the bug on their end?** If possible, include a copy of your code, the command you |
| 39 |
used to invoke it, and the full output of your run (if applicable.) |
| 40 |
|
| 41 |
- A common tactic is to pare down your code until a simple (but still bug-causing) "base case" remains. Not only can |
| 42 |
this help you identify problems which aren't real bugs, but it means the developer can get to fixing the bug |
| 43 |
faster. |
| 44 |
|
| 45 |
Contributing changes |
| 46 |
-------------------- |
| 47 |
|
| 48 |
Licensing of contributed material |
| 49 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 50 |
|
| 51 |
Keep in mind as you contribute, that code, docs and other material submitted to open source projects are usually |
| 52 |
considered licensed under the same terms as the rest of the work. |
| 53 |
|
| 54 |
The details vary from project to project, but from the perspective of this document's authors: |
| 55 |
|
| 56 |
- Anything submitted to a project falls under the licensing terms in the repository's top level ``LICENSE`` file. |
| 57 |
|
| 58 |
- For example, if a project's ``LICENSE`` is BSD-based, contributors should be comfortable with their work |
| 59 |
potentially being distributed in binary form without the original source code. |
| 60 |
|
| 61 |
- Per-file copyright/license headers are typically extraneous and undesirable. Please don't add your own copyright |
| 62 |
headers to new files unless the project's license actually requires them! |
| 63 |
|
| 64 |
- Not least because even a new file created by one individual (who often feels compelled to put their personal |
| 65 |
copyright notice at the top) will inherently end up contributed to by dozens of others over time, making a |
| 66 |
per-file header outdated/misleading. |
| 67 |
|
| 68 |
Version control branching |
| 69 |
~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 70 |
|
| 71 |
- Always **make a new branch** for your work, no matter how small. This makes it easy for others to take just that one |
| 72 |
set of changes from your repository, in case you have multiple unrelated changes floating around. |
| 73 |
|
| 74 |
- A corollary: **don't submit unrelated changes in the same branch/pull request**! The maintainer shouldn't have to |
| 75 |
reject your awesome bugfix because the feature you put in with it needs more review. |
| 76 |
|
| 77 |
- **Base your new branch off of the appropriate branch** on the main repository: |
| 78 |
|
| 79 |
- **Bug fixes** should be based on the branch named after the **oldest supported release line** the bug affects. |
| 80 |
|
| 81 |
- E.g. if a feature was introduced in 1.1, the latest release line is 1.3, and a bug is found in that feature - |
| 82 |
make your branch based on 1.1. The maintainer will then forward-port it to 1.3 and master. |
| 83 |
- Bug fixes requiring large changes to the code or which have a chance of being otherwise disruptive, may need to |
| 84 |
base off of **master** instead. This is a judgement call -- ask the devs! |
| 85 |
|
| 86 |
- **New features** should branch off of **the 'master' branch**. |
| 87 |
|
| 88 |
- Note that depending on how long it takes for the dev team to merge your patch, the copy of ``master`` you |
| 89 |
worked off of may get out of date! If you find yourself 'bumping' a pull request that's been sidelined for a |
| 90 |
while, **make sure you rebase or merge to latest master** to ensure a speedier resolution. |
| 91 |
|
| 92 |
Code formatting |
| 93 |
~~~~~~~~~~~~~~~ |
| 94 |
|
| 95 |
- **Follow the style you see used in the primary repository**! Consistency with the rest of the project always trumps |
| 96 |
other considerations. It doesn't matter if you have your own style or if the rest of the code breaks with the greater |
| 97 |
community - just follow along. |
| 98 |
- Python projects usually follow the `PEP-8 <http://www.python.org/dev/peps/pep-0008/>`__ guidelines (though many have |
| 99 |
minor deviations depending on the lead maintainers' preferences.) |
| 100 |
|
| 101 |
Documentation isn't optional |
| 102 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 103 |
|
| 104 |
It's not! Patches without documentation will be returned to sender. By "documentation" we mean: |
| 105 |
|
| 106 |
- **Docstrings** (for Python; or API-doc-friendly comments for other languages) must be created or updated for public |
| 107 |
API functions/methods/etc. (This step is optional for some bugfixes.) |
| 108 |
|
| 109 |
- Don't forget to include |
| 110 |
`versionadded <http://sphinx-doc.org/markup/para.html#directive-versionadded>`__/`versionchanged <http://sphinx-doc.org/markup/para.html#directive-versionchanged>`__ |
| 111 |
ReST directives at the bottom of any new or changed Python docstrings! |
| 112 |
|
| 113 |
- Use ``versionadded`` for truly new API members -- new methods, functions, classes or modules. |
| 114 |
- Use ``versionchanged`` when adding/removing new function/method arguments, or whenever behavior changes. |
| 115 |
|
| 116 |
- New features should ideally include updates to **prose documentation**, including useful example code snippets. |
| 117 |
|
| 118 |
- All submissions should have a **changelog entry** crediting the contributor and/or any individuals instrumental in |
| 119 |
identifying the problem. |
| 120 |
|
| 121 |
Tests aren't optional |
| 122 |
~~~~~~~~~~~~~~~~~~~~~ |
| 123 |
|
| 124 |
Any bugfix that doesn't include a test proving the existence of the bug being fixed, may be suspect. Ditto for new |
| 125 |
features that can't prove they actually work. |
| 126 |
|
| 127 |
We've found that test-first development really helps make features better architected and identifies potential edge |
| 128 |
cases earlier instead of later. Writing tests before the implementation is strongly encouraged. |
| 129 |
|
| 130 |
Full example |
| 131 |
~~~~~~~~~~~~ |
| 132 |
|
| 133 |
Here's an example workflow for a project ``theproject`` hosted on Github, which is currently in version 1.3.x. Your |
| 134 |
username is ``yourname`` and you're submitting a basic bugfix. (This workflow only changes slightly if the project is |
| 135 |
hosted at Bitbucket, self-hosted, or etc.) |
| 136 |
|
| 137 |
Preparing your Fork |
| 138 |
^^^^^^^^^^^^^^^^^^^ |
| 139 |
|
| 140 |
1. Click 'Fork' on Github, creating e.g. ``yourname/theproject``. |
| 141 |
2. Clone your project: ``git clone [email protected]:yourname/theproject``. |
| 142 |
3. ``cd theproject`` |
| 143 |
4. `Create and activate a virtual |
| 144 |
environment <https://packaging.python.org/tutorials/installing-packages/#creating-virtual-environments>`__. |
| 145 |
5. Install the development requirements: ``uv sync --extra tests``. |
| 146 |
6. Create a branch: ``git checkout -b foo-the-bars 1.3``. |
| 147 |
|
| 148 |
Making your Changes |
| 149 |
^^^^^^^^^^^^^^^^^^^ |
| 150 |
|
| 151 |
1. Add changelog entry crediting yourself. |
| 152 |
2. Write tests expecting the correct/fixed functionality; make sure they fail. |
| 153 |
3. Hack, hack, hack. |
| 154 |
4. Run tests again, making sure they pass. |
| 155 |
5. Commit your changes: ``git commit -m "Foo the bars"`` |
| 156 |
|
| 157 |
Creating Pull Requests |
| 158 |
^^^^^^^^^^^^^^^^^^^^^^ |
| 159 |
|
| 160 |
1. Push your commit to get it back up to your fork: ``git push origin HEAD`` |
| 161 |
2. Visit Github, click handy "Pull request" button that it will make upon noticing your new branch. |
| 162 |
3. In the description field, write down issue number (if submitting code fixing an existing issue) or describe the issue |
| 163 |
+ your fix (if submitting a wholly new bugfix). |
| 164 |
4. Hit 'submit'! And please be patient - the maintainers will get to you when they can. |