|
| 1 | +Contributing to UV-CDAT |
| 2 | +====================== |
| 3 | + |
| 4 | +Where to start? |
| 5 | +--------------- |
| 6 | + |
| 7 | +All contributions, bug reports, bug fixes, documentation improvements, |
| 8 | +enhancements and ideas are welcome. |
| 9 | + |
| 10 | +If you are simply looking to start working with the *UV-CDAT* codebase, |
| 11 | +navigate to the [GitHub "issues" |
| 12 | +tab](https://github.com/UV-CDAT/uvcdat/issues) and start looking through |
| 13 | +interesting issues. |
| 14 | + |
| 15 | +Feel free to ask questions on [mailing |
| 16 | +list](uvcdat-users@llnl.gov) |
| 17 | + |
| 18 | +Bug Reports/Enhancement Requests |
| 19 | +-------------------------------- |
| 20 | + |
| 21 | +Bug reports are an important part of making *UV-CDAT* more stable. Having |
| 22 | +a complete bug report will allow others to reproduce the bug and provide |
| 23 | +insight into fixing. Since many versions of *UV-CDAT* are supported, |
| 24 | +knowing version information will also identify improvements made since |
| 25 | +previous versions. Often trying the bug-producing code out on the |
| 26 | +*master* branch is a worthwhile exercise to confirm the bug still |
| 27 | +exists. It is also worth searching existing bug reports and pull |
| 28 | +requests to see if the issue has already been reported and/or fixed. |
| 29 | + |
| 30 | +Bug reports must: |
| 31 | + |
| 32 | +1. Include a short, self-contained Python snippet reproducing the |
| 33 | + problem. You can have the code formatted nicely by using [GitHub |
| 34 | + Flavored |
| 35 | + Markdown](http://github.github.com/github-flavored-markdown/): : |
| 36 | + |
| 37 | + ```python |
| 38 | + >>> import vcs |
| 39 | + >>> vcs.init() |
| 40 | + ... |
| 41 | + ``` |
| 42 | + |
| 43 | +2. Explain why the current behavior is wrong/not desired and what you |
| 44 | + expect instead. |
| 45 | + |
| 46 | +The issue will then show up to the *UV-CDAT* community and be open to |
| 47 | +comments/ideas from others. |
| 48 | + |
| 49 | +Working with the code |
| 50 | +--------------------- |
| 51 | + |
| 52 | +Now that you have an issue you want to fix, enhancement to add, or |
| 53 | +documentation to improve, you need to learn how to work with GitHub and |
| 54 | +the *UV-CDAT* code base. |
| 55 | + |
| 56 | +### Version Control, Git, and GitHub |
| 57 | + |
| 58 | +To the new user, working with Git is one of the more daunting aspects of |
| 59 | +contributing to *UV-CDAT*. It can very quickly become overwhelming, but |
| 60 | +sticking to the guidelines below will make the process straightforward |
| 61 | +and will work without much trouble. As always, if you are having |
| 62 | +difficulties please feel free to ask for help. |
| 63 | + |
| 64 | +The code is hosted on [GitHub](https://www.github.com/UV-CDAT/uvcdat). To |
| 65 | +contribute you will need to sign up for a [free GitHub |
| 66 | +account](https://github.com/signup/free). We use |
| 67 | +[Git](http://git-scm.com/) for version control to allow many people to |
| 68 | +work together on the project. |
| 69 | + |
| 70 | +Some great resources for learning git: |
| 71 | + |
| 72 | +- the [GitHub help pages](http://help.github.com/). |
| 73 | +- the [NumPy's |
| 74 | + documentation](http://docs.scipy.org/doc/numpy/dev/index.html). |
| 75 | +- Matthew Brett's |
| 76 | + [Pydagogue](http://matthew-brett.github.com/pydagogue/). |
| 77 | + |
| 78 | +### Getting Started with Git |
| 79 | + |
| 80 | +[GitHub has instructions](http://help.github.com/set-up-git-redirect) |
| 81 | +for installing git, setting up your SSH key, and configuring git. All |
| 82 | +these steps need to be completed before working seamlessly with your |
| 83 | +local repository and GitHub. |
| 84 | + |
| 85 | +### Forking |
| 86 | + |
| 87 | +You will need your own fork to work on the code. Go to the [UV-CDAT |
| 88 | +project page](https://github.com/UV-CDAT/uvcdat) and hit the *fork* |
| 89 | +button. You will want to clone your fork to your machine: : |
| 90 | + |
| 91 | + git clone git://github.com/UV-CDAT/uvcdat.git UV-CDAT-yourname |
| 92 | + cd UV-CDAT-yourname |
| 93 | + git remote add myuvcdat git@github.com:your-user-name/uvcdat.git |
| 94 | + |
| 95 | +This creates the directory UV-CDAT-yourname and connects your repository |
| 96 | +to the upstream (main project) *UV-CDAT* repository. |
| 97 | + |
| 98 | +You will also need to hook up Travis-CI to your GitHub repository so the |
| 99 | +suite is automatically run when a Pull Request is submitted. |
| 100 | +Instructions are |
| 101 | +[here](http://about.travis-ci.org/docs/user/getting-started/). |
| 102 | + |
| 103 | +### Creating a Branch |
| 104 | + |
| 105 | +You want your master branch to reflect only production-ready code, so |
| 106 | +create a feature branch for making your changes. For example: |
| 107 | + |
| 108 | + git branch shiny-new-feature |
| 109 | + git checkout shiny-new-feature |
| 110 | + |
| 111 | +The above can be simplified to: |
| 112 | + |
| 113 | + git checkout -b shiny-new-feature |
| 114 | + |
| 115 | +This changes your working directory to the shiny-new-feature branch. |
| 116 | +Keep any changes in this branch specific to one bug or feature so it is |
| 117 | +clear what the branch brings to *UV-CDAT*. You can have many |
| 118 | +shiny-new-features and switch in between them using the git checkout |
| 119 | +command. |
| 120 | + |
| 121 | +### Making changes |
| 122 | +Before making your code changes, it is often necessary to build the code |
| 123 | +that was just checked out. There are two primary methods of doing this. |
| 124 | + |
| 125 | +The best way to develop *UV-CDAT* is to build using default settings: |
| 126 | + |
| 127 | + mkdir uvcdat-build |
| 128 | + cmake uvcdat-path-to-source |
| 129 | + make -jN |
| 130 | + |
| 131 | + If you startup the Python interpreter in the *UV-CDAT* source |
| 132 | + directory you will call the built C extensions |
| 133 | + |
| 134 | +Contributing to the documentation |
| 135 | +--------------------------------- |
| 136 | + |
| 137 | +If you're not the developer type, contributing to the documentation is |
| 138 | +still of huge value. You don't even have to be an expert on *UV-CDAT* to |
| 139 | +do so! Something as simple as |
| 140 | + |
| 141 | +Contributing to the code base |
| 142 | +----------------------------- |
| 143 | +### Code Standards |
| 144 | + |
| 145 | +*UV-CDAT* uses the [PEP8](http://www.python.org/dev/peps/pep-0008/) |
| 146 | +standard. There are several tools to ensure you abide by this standard. |
| 147 | + |
| 148 | +Alternatively, use [flake8](http://pypi.python.org/pypi/flake8) tool for |
| 149 | +checking the style of your code. Additional standards are outlined on |
| 150 | +the [code style wiki |
| 151 | +page](LINK HERE). |
| 152 | + |
| 153 | +Please try to maintain backward-compatibility. *UV-CDAT* has lots of |
| 154 | +users with lots of existing code, so don't break it if at all possible. |
| 155 | +If you think breakage is required clearly state why as part of the Pull |
| 156 | +Request. Also, be careful when changing method signatures and add |
| 157 | +deprecation warnings where needed. |
| 158 | + |
| 159 | +### Test-driven Development/Writing Code |
| 160 | +*UV-CDAT* is serious about [Test-driven Development |
| 161 | +(TDD)](http://en.wikipedia.org/wiki/Test-driven_development). This |
| 162 | +development process "relies on the repetition of a very short |
| 163 | +development cycle: first the developer writes an (initially failing) |
| 164 | +automated test case that defines a desired improvement or new function, |
| 165 | +then produces the minimum amount of code to pass that test." So, before |
| 166 | +actually writing any code, you should write your tests. Often the test |
| 167 | +can be taken from the original GitHub issue. However, it is always worth |
| 168 | +considering additional use cases and writing corresponding tests. |
| 169 | + |
| 170 | +Adding tests is one of the most common requests after code is pushed to |
| 171 | +*UV-CDAT*. It is worth getting in the habit of writing tests ahead of |
| 172 | +time so this is never an issue. |
| 173 | + |
| 174 | +#### Writing tests |
| 175 | + |
| 176 | +All tests should go into the *tests* subdirectory of the specific |
| 177 | +package. There are probably many examples already there and looking to |
| 178 | +these for inspiration is suggested. |
| 179 | + |
| 180 | +The `UV-CDAT.util.testing` module has many special `assert` functions |
| 181 | +that make it easier to make statements about whether Series or DataFrame |
| 182 | +objects are equivalent. The easiest way to verify that your code is |
| 183 | +correct is to explicitly construct the result you expect, then compare |
| 184 | +the actual result to the expected correct result: |
| 185 | + |
| 186 | + def test_pivot(self): |
| 187 | + data = { |
| 188 | + 'index' : ['A', 'B', 'C', 'C', 'B', 'A'], |
| 189 | + 'columns' : ['One', 'One', 'One', 'Two', 'Two', 'Two'], |
| 190 | + 'values' : [1., 2., 3., 3., 2., 1.] |
| 191 | + } |
| 192 | + |
| 193 | + frame = DataFrame(data) |
| 194 | + pivoted = frame.pivot(index='index', columns='columns', values='values') |
| 195 | + |
| 196 | + expected = DataFrame({ |
| 197 | + 'One' : {'A' : 1., 'B' : 2., 'C' : 3.}, |
| 198 | + 'Two' : {'A' : 1., 'B' : 2., 'C' : 3.} |
| 199 | + }) |
| 200 | + |
| 201 | + assert_frame_equal(pivoted, expected) |
| 202 | + |
| 203 | +#### Running the test suite |
| 204 | + |
| 205 | +The tests can then be run directly inside your build tree by typing:: |
| 206 | + |
| 207 | + ctest |
| 208 | + |
| 209 | +To save time and run tests in Pararallel |
| 210 | + |
| 211 | + ctest -jN |
| 212 | + |
| 213 | +The tests suite is exhaustive and takes around 20 minutes to run. Often |
| 214 | +it is worth running only a subset of tests first around your changes |
| 215 | +before running the entire suite. This is done using one of the following |
| 216 | +constructs: |
| 217 | + |
| 218 | + ctest -R test-name |
| 219 | + ctest -R regex* |
| 220 | + |
| 221 | +#### Running the performance test suite |
| 222 | + |
| 223 | +TODO |
| 224 | + |
| 225 | +### Documenting your code |
| 226 | + |
| 227 | +TODO |
| 228 | + |
| 229 | +Contributing your changes to *UV-CDAT* |
| 230 | +------------------------------------- |
| 231 | + |
| 232 | +### Committing your code |
| 233 | + |
| 234 | +Keep style fixes to a separate commit to make your PR more readable. Once you've made changes, you can see them by typing: |
| 235 | + |
| 236 | + git status |
| 237 | + |
| 238 | +If you've created a new file, it is not being tracked by git. Add it by |
| 239 | +typing : |
| 240 | + |
| 241 | + git add path/to/file-to-be-added.py |
| 242 | + |
| 243 | +Doing 'git status' again should give something like : |
| 244 | + |
| 245 | + # On branch shiny-new-feature |
| 246 | + # |
| 247 | + # modified: /relative/path/to/file-you-added.py |
| 248 | + # |
| 249 | + |
| 250 | +Finally, commit your changes to your local repository with an |
| 251 | +explanatory message. An informal commit message format is in effect for |
| 252 | +the project. Please try to adhere to it. Here are some common prefixes |
| 253 | +along with general guidelines for when to use them: |
| 254 | + |
| 255 | +> - ENH: Enhancement, new functionality |
| 256 | +> - BUG: Bug fix |
| 257 | +> - DOC: Additions/updates to documentation |
| 258 | +> - TST: Additions/updates to tests |
| 259 | +> - BLD: Updates to the build process/scripts |
| 260 | +> - PERF: Performance improvement |
| 261 | +> - CLN: Code cleanup |
| 262 | +
|
| 263 | +The following defines how a commit message should be structured. Please |
| 264 | +reference the relevant GitHub issues in your commit message using GH1234 |
| 265 | +or \#1234. Either style is fine, but the former is generally preferred: |
| 266 | + |
| 267 | +> - a subject line with \< 80 chars. |
| 268 | +> - One blank line. |
| 269 | +> - Optionally, a commit message body. |
| 270 | +
|
| 271 | +Now you can commit your changes in your local repository: |
| 272 | + |
| 273 | + git commit -m |
| 274 | + |
| 275 | +If you have multiple commits, it is common to want to combine them into |
| 276 | +one commit, often referred to as "squashing" or "rebasing". This is a |
| 277 | +common request by package maintainers when submitting a Pull Request as |
| 278 | +it maintains a more compact commit history. To rebase your commits: |
| 279 | + |
| 280 | + git rebase -i HEAD~# |
| 281 | + |
| 282 | +Where \# is the number of commits you want to combine. Then you can pick |
| 283 | +the relevant commit message and discard others. |
| 284 | + |
| 285 | +### Pushing your changes |
| 286 | + |
| 287 | +When you want your changes to appear publicly on your GitHub page, push |
| 288 | +your forked feature branch's commits : |
| 289 | + |
| 290 | + git push origin shiny-new-feature |
| 291 | + |
| 292 | +Here origin is the default name given to your remote repository on |
| 293 | +GitHub. You can see the remote repositories : |
| 294 | + |
| 295 | + git remote -v |
| 296 | + |
| 297 | +If you added the upstream repository as described above you will see |
| 298 | +something like : |
| 299 | + |
| 300 | + origin git://github.com/UV-CDAT/uvcdat.git |
| 301 | + myuvcdat git@github.com:yourname/uvcdat.git (fetch) |
| 302 | + myuvcdat git@github.com:yourname/uvcdat.git (fetch) |
| 303 | + |
| 304 | +Now your code is on GitHub, but it is not yet a part of the *UV-CDAT* |
| 305 | +project. For that to happen, a Pull Request needs to be submitted on |
| 306 | +GitHub. |
| 307 | + |
| 308 | +### Review your code |
| 309 | + |
| 310 | +When you're ready to ask for a code review, you will file a Pull |
| 311 | +Request. Before you do, again make sure you've followed all the |
| 312 | +guidelines outlined in this document regarding code style, tests, |
| 313 | +performance tests, and documentation. You should also double check your |
| 314 | +branch changes against the branch it was based off of: |
| 315 | + |
| 316 | +1. Navigate to your repository on |
| 317 | + GitHub--<https://github.com/your-user-name/uvcdat>. |
| 318 | +2. Click on Branches. |
| 319 | +3. Click on the Compare button for your feature branch. |
| 320 | +4. Select the base and compare branches, if necessary. This will be |
| 321 | + master and shiny-new-feature, respectively. |
| 322 | + |
| 323 | +### Finally, make the Pull Request |
| 324 | + |
| 325 | +If everything looks good you are ready to make a Pull Request. A Pull |
| 326 | +Request is how code from a local repository becomes available to the |
| 327 | +GitHub community and can be looked at and eventually merged into the |
| 328 | +master version. This Pull Request and its associated changes will |
| 329 | +eventually be committed to the master branch and available in the next |
| 330 | +release. To submit a Pull Request: |
| 331 | + |
| 332 | +1. Navigate to your repository on GitHub. |
| 333 | +2. Click on the Pull Request button. |
| 334 | +3. You can then click on Commits and Files Changed to make sure |
| 335 | + everything looks okay one last time. |
| 336 | +4. Write a description of your changes in the Preview Discussion tab. |
| 337 | +5. Click Send Pull Request. |
| 338 | + |
| 339 | +This request then appears to the repository maintainers, and they will |
| 340 | +review the code. If you need to make more changes, you can make them in |
| 341 | +your branch, push them to GitHub, and the pull request will be |
| 342 | +automatically updated. Pushing them to GitHub again is done by: |
| 343 | + |
| 344 | + git push -f myuvcdat shiny-new-feature |
| 345 | + |
| 346 | +This will automatically update your Pull Request with the latest code |
| 347 | +and restart the Travis-CI tests. |
| 348 | + |
| 349 | +### Delete your merged branch (optional) |
| 350 | + |
| 351 | +Once your feature branch is accepted into upstream, you'll probably want |
| 352 | +to get rid of the branch. First, merge upstream master into your branch |
| 353 | +so git knows it is safe to delete your branch : |
| 354 | + |
| 355 | + git fetch origin |
| 356 | + git checkout master |
| 357 | + git reset --hard origin/master |
| 358 | + |
| 359 | +Then you can just do: |
| 360 | + |
| 361 | + git branch -d shiny-new-feature |
| 362 | + |
| 363 | +Make sure you use a lower-case -d, or else git won't warn you if your |
| 364 | +feature branch has not actually been merged. |
| 365 | + |
| 366 | +The branch will still exist on GitHub, so to delete it there do : |
| 367 | + |
| 368 | + git push origin --delete shiny-new-feature |
| 369 | + |
| 370 | + |
| 371 | + |
| 372 | + |
| 373 | + |
| 374 | + |
0 commit comments