contributing.rst 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. .. _contributing:
  2. ==============
  3. Contributing
  4. ==============
  5. .. contents::
  6. :local:
  7. .. _community-code-of-conduct:
  8. Community Code of Conduct
  9. =========================
  10. The goal is to maintain a diverse community that is pleasant for everyone.
  11. That is why we would greatly appreciate it if everyone contributing to and
  12. interacting with the community also followed this Code of Conduct.
  13. The Code of Conduct covers our behavior as members of the community,
  14. in any forum, mailing list, wiki, website, Internet relay chat (IRC), public
  15. meeting or private correspondence.
  16. The Code of Conduct is heavily based on the `Ubuntu Code of Conduct`_, and
  17. the `Pylons Code of Conduct`_.
  18. .. _`Ubuntu Code of Conduct`: http://www.ubuntu.com/community/conduct
  19. .. _`Pylons Code of Conduct`: http://docs.pylonshq.com/community/conduct.html
  20. Be considerate.
  21. ---------------
  22. Your work will be used by other people, and you in turn will depend on the
  23. work of others. Any decision you take will affect users and colleagues, and
  24. we expect you to take those consequences into account when making decisions.
  25. Even if it's not obvious at the time, our contributions to Ubuntu will impact
  26. the work of others. For example, changes to code, infrastructure, policy,
  27. documentation and translations during a release may negatively impact
  28. others work.
  29. Be respectful.
  30. --------------
  31. The Celery community and its members treat one another with respect. Everyone
  32. can make a valuable contribution to Celery. We may not always agree, but
  33. disagreement is no excuse for poor behavior and poor manners. We might all
  34. experience some frustration now and then, but we cannot allow that frustration
  35. to turn into a personal attack. It's important to remember that a community
  36. where people feel uncomfortable or threatened is not a productive one. We
  37. expect members of the Celery community to be respectful when dealing with
  38. other contributors as well as with people outside the Celery project and with
  39. users of Celery.
  40. Be collaborative.
  41. -----------------
  42. Collaboration is central to Celery and to the larger free software community.
  43. We should always be open to collaboration. Your work should be done
  44. transparently and patches from Celery should be given back to the community
  45. when they are made, not just when the distribution releases. If you wish
  46. to work on new code for existing upstream projects, at least keep those
  47. projects informed of your ideas and progress. It many not be possible to
  48. get consensus from upstream, or even from your colleagues about the correct
  49. implementation for an idea, so don't feel obliged to have that agreement
  50. before you begin, but at least keep the outside world informed of your work,
  51. and publish your work in a way that allows outsiders to test, discuss and
  52. contribute to your efforts.
  53. When you disagree, consult others.
  54. ----------------------------------
  55. Disagreements, both political and technical, happen all the time and
  56. the Celery community is no exception. It is important that we resolve
  57. disagreements and differing views constructively and with the help of the
  58. community and community process. If you really want to go a different
  59. way, then we encourage you to make a derivative distribution or alternate
  60. set of packages that still build on the work we've done to utilize as common
  61. of a core as possible.
  62. When you are unsure, ask for help.
  63. ----------------------------------
  64. Nobody knows everything, and nobody is expected to be perfect. Asking
  65. questions avoids many problems down the road, and so questions are
  66. encouraged. Those who are asked questions should be responsive and helpful.
  67. However, when asking a question, care must be taken to do so in an appropriate
  68. forum.
  69. Step down considerately.
  70. ------------------------
  71. Developers on every project come and go and Celery is no different. When you
  72. leave or disengage from the project, in whole or in part, we ask that you do
  73. so in a way that minimizes disruption to the project. This means you should
  74. tell people you are leaving and take the proper steps to ensure that others
  75. can pick up where you leave off.
  76. .. _reporting-bugs:
  77. Reporting a Bug
  78. ===============
  79. Bugs can always be described to the :ref:`mailing-list`, but the best
  80. way to report an issue and to ensure a timely response is to use the
  81. issue tracker.
  82. 1) Create a GitHub account.
  83. You need to `create a GitHub account`_ to be able to create new issues
  84. and participate in the discussion.
  85. .. _`create a GitHub account`: https://github.com/signup/free
  86. 2) Determine if your bug is really a bug.
  87. You should not file a bug if you are requesting support. For that you can use
  88. the :ref:`mailing-list`, or :ref:`irc-channel`.
  89. 3) Make sure your bug hasn't already been reported.
  90. Search through the appropriate Issue tracker. If a bug like yours was found,
  91. check if you have new information that could be reported to help
  92. the developers fix the bug.
  93. 4) Collect information about the bug.
  94. To have the best chance of having a bug fixed, we need to be able to easily
  95. reproduce the conditions that caused it. Most of the time this information
  96. will be from a Python traceback message, though some bugs might be in design,
  97. spelling or other errors on the website/docs/code.
  98. If the error is from a Python traceback, include it in the bug report.
  99. We also need to know what platform you're running (Windows, OSX, Linux, etc),
  100. the version of your Python interpreter, and the version of Celery, and related
  101. packages that you were running when the bug occurred.
  102. 5) Submit the bug.
  103. By default `GitHub`_ will email you to let you know when new comments have
  104. been made on your bug. In the event you've turned this feature off, you
  105. should check back on occasion to ensure you don't miss any questions a
  106. developer trying to fix the bug might ask.
  107. .. _`GitHub`: http://github.com
  108. .. _issue-trackers:
  109. Issue Trackers
  110. --------------
  111. Bugs for a package in the Celery ecosystem should be reported to the relevant
  112. issue tracker.
  113. * Celery: http://github.com/ask/celery/issues/
  114. * Django-Celery: http://github.com/ask/django-celery/issues
  115. * Flask-Celery: http://github.com/ask/flask-celery/issues
  116. * Celery-Pylons: http://bitbucket.org/ianschenck/celery-pylons/issues
  117. * Kombu: http://github.com/ask/kombu/issues
  118. If you are unsure of the origin of the bug you can ask the
  119. :ref:`mailing-list`, or just use the Celery issue tracker.
  120. .. _versions::
  121. Versions
  122. ========
  123. Version numbers consists of a major version, minor version and a release number.
  124. Since version 2.1.0 we use the versioning semantics described by
  125. semver: http://semver.org.
  126. Stable releases are published at PyPI
  127. while development releases are only available in the GitHub git repository as tags.
  128. All version tags starts with “v”, so version 0.8.0 is the tag v0.8.0.
  129. .. _git-branches:
  130. Branches
  131. ========
  132. Current active version branches:
  133. * master (http://github.com/ask/celery/tree/master)
  134. * 3.0-devel (http://github.com/ask/celery/tree/3.0-devel)
  135. You can see the state of any branch by looking at the Changelog:
  136. https://github.com/ask/celery/blob/master/Changelog
  137. If the branch is in active development the topmost version info should
  138. contain metadata like::
  139. 2.4.0
  140. ======
  141. :release-date: TBA
  142. :status: DEVELOPMENT
  143. :branch: master
  144. The ``status`` field can be one of:
  145. * ``PLANNING``
  146. The branch is currently experimental and in the planning stage.
  147. * ``DEVELOPMENT``
  148. The branch is in active development, but the test suite should
  149. be passing and the product should be working and possible for users to test.
  150. * ``FROZEN``
  151. The branch is frozen, and no more features will be accepted.
  152. When a branch is frozen the focus is on testing the version as much
  153. as possible before it is released.
  154. ``master`` branch
  155. -----------------
  156. The master branch is where development of the next version happens.
  157. Maintenance branches
  158. --------------------
  159. Maintenance branches are named after the version, e.g. the maintenance branch
  160. for the 2.2.x series is named ``2.2``. Previously these were named
  161. ``releaseXX-maint``.
  162. The versions we currently maintain is:
  163. * 2.3
  164. This is the current series.
  165. * 2.2
  166. This is the previous series, and the last version to support Python 2.4.
  167. * 2.1
  168. This is the last version to use the ``carrot`` AMQP framework.
  169. Recent versions use ``kombu``.
  170. Archived branches
  171. -----------------
  172. Archived branches are kept for preserving history only,
  173. and theoretically someone could provide patches for these if they depend
  174. on a series that is no longer officially supported.
  175. An archived version is named ``X.Y-archived``.
  176. Our currently archived branches are:
  177. * 2.1-archived
  178. * 2.0-archived
  179. * 1.0-archived
  180. Feature branches
  181. ----------------
  182. Major new features are worked on in dedicated branches.
  183. There is no strict naming requirement for these branches.
  184. Feature branches are removed once they have been merged into a release branch.
  185. Tags
  186. ====
  187. Tags are used exclusively for tagging releases. A release tag is
  188. named with the format ``vX.Y.Z``, e.g. ``v2.3.1``.
  189. Experimental releases contain an additional identifier ``vX.Y.Z-id``, e.g.
  190. ``v3.0.0-rc1``. Experimental tags may be removed after the official release.
  191. .. _contributing-changes:
  192. Working on Features & Patches
  193. =============================
  194. Forking and Setting up the Repository
  195. -------------------------------------
  196. First you need to fork the Celery repository, a good introduction to this
  197. is in the Github Guide: `Fork a Repo`_.
  198. After you have cloned the repository you should checkout your copy
  199. to a directory on your machine::
  200. $ git clone git@github.com:username/celery.git
  201. When the repository is cloned enter the directory to set up easy access
  202. to upstream changes::
  203. $ cd celery
  204. $ git remote add upstream git://github.com/ask/celery.git
  205. $ git fetch upstream
  206. If you need to pull in new changes from upstream you should
  207. always use the :option:`--rebase` option to ``git pull``::
  208. git pull --rebase upstream master
  209. With this option you don't clutter the history with merging
  210. commit notes. See `Rebasing merge commits in git`_.
  211. If you want to learn more about rebasing see the `Rebase`_
  212. section in the Github guides.
  213. If you need to work on a different branch than ``master`` you can
  214. fetch and checkout a remote branch like this::
  215. git checkout --track -b 3.0-devel origin/3.0-devel
  216. For a list of branches see :ref:`git-branches`.
  217. .. _`Fork a Repo`: http://help.github.com/fork-a-repo/
  218. .. _`Rebasing merge commits in git`:
  219. http://notes.envato.com/developers/rebasing-merge-commits-in-git/
  220. .. _`Rebase`: http://help.github.com/rebase/
  221. .. _contributing-testing:
  222. Running the Unit Test Suite
  223. ---------------------------
  224. To run the Celery test suite you need to install a few dependencies.
  225. A complete list of the dependencies needed are located in
  226. :file:`requirements/test.txt`.
  227. Installing the test requirements::
  228. $ pip -E $VIRTUAL_ENV install -U -r requirements/test.txt
  229. When installation of dependencies is complete you can execute
  230. the test suite by calling ``nosetests``::
  231. $ nosetests
  232. Some useful options to :program:`nosetests` are:
  233. * :option:`-x`
  234. Stop running the tests at the first test that fails.
  235. * :option:`-s`
  236. Don't capture output
  237. * :option:`--nologcapture`
  238. Don't capture log output.
  239. * :option:`-v`
  240. Run with verbose output.
  241. If you want to run the tests for a single test file only
  242. you can do so like this::
  243. $ nosetests celery.tests.test_worker.test_worker_job
  244. .. _contributing-coverage:
  245. Calculating code coverage
  246. ~~~~~~~~~~~~~~~~~~~~~~~~~
  247. Code coverage in HTML::
  248. $ nosetests --with-coverage3 --cover3-html
  249. The coverage output will then be located at
  250. :file:`celery/tests/cover/index.html`.
  251. Code coverage in XML (Cobertura-style)::
  252. $ nosetests --with-coverage3 --cover3-xml --cover3-xml-file=coverage.xml
  253. The coverage XML output will then be located at :file:`coverage.xml`
  254. .. _contributing-tox:
  255. Running the tests on all supported Python versions
  256. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  257. There is a ``tox`` configuration file in the top directory of the
  258. distribution.
  259. To run the tests for all supported Python versions simply execute::
  260. $ tox
  261. If you only want to test specific Python versions use the :option:`-e`
  262. option::
  263. $ tox -e py25,py26
  264. .. _contributing-verify:
  265. Verifying your contribution
  266. ---------------------------
  267. To use these tools you need to install a few dependencies. These dependencies
  268. can be found in :file:`requirements/pkgutils.txt`.
  269. Installing the dependencies::
  270. $ pip -E $VIRTUAL_ENV install -U -r requirements/pkgutils.txt
  271. pyflakes & PEP8
  272. ~~~~~~~~~~~~~~~
  273. To ensure that your changes conform to PEP8 and to run pyflakes
  274. execute::
  275. $ paver flake8
  276. To not return a negative exit code when this command fails use the
  277. :option:`-E` option, this can be convenient while developing::
  278. $ paver flake8 -E
  279. API reference
  280. ~~~~~~~~~~~~~
  281. To make sure that all modules have a corresponding section in the API
  282. reference please execute::
  283. $ paver autodoc
  284. $ paver verifyindex
  285. If files are missing you can add them by copying an existing reference file.
  286. If the module is internal it should be part of the internal reference
  287. located in :file:`docs/internals/reference/`. If the module is public
  288. it should be located in :file:`docs/reference/`.
  289. For example if reference is missing for the module ``celery.worker.awesome``
  290. and this module is considered part of the public API, use the following steps::
  291. $ cd docs/reference/
  292. $ cp celery.schedules.rst celery.worker.awesome.rst
  293. $ vim celery.worker.awesome.rst
  294. # change every occurance of ``celery.schedules`` to
  295. # ``celery.worker.awesome``
  296. $ vim index.rst
  297. # Add ``celery.worker.awesome`` to the index.
  298. # Add the file to git
  299. $ git add celery.worker.awesome.rst
  300. $ git add index.rst
  301. $ git commit celery.worker.awesome.rst index.rst \
  302. -m "Adds reference for celery.worker.awesome"
  303. .. _coding-style:
  304. Coding Style
  305. ============
  306. You should probably be able to pick up the coding style
  307. from surrounding code, but it is a good idea to be aware of the
  308. following conventions.
  309. * All Python code must follow the `PEP-8`_ guidelines.
  310. `pep8.py`_ is an utility you can use to verify that your code
  311. is following the conventions.
  312. .. _`PEP-8`: http://www.python.org/dev/peps/pep-0008/
  313. .. _`pep8.py`: http://pypi.python.org/pypi/pep8
  314. * Docstrings must follow the `PEP-257`_ conventions, and use the following
  315. style.
  316. Do this:
  317. .. code-block:: python
  318. def method(self, arg):
  319. """Short description.
  320. More details.
  321. """
  322. or:
  323. .. code-block:: python
  324. def method(self, arg):
  325. """Short description."""
  326. but not this:
  327. .. code-block:: python
  328. def method(self, arg):
  329. """
  330. Short description.
  331. """
  332. .. _`PEP-257`: http://www.python.org/dev/peps/pep-0257/
  333. * Lines should not exceed 78 columns.
  334. You can enforce this in :program:`vim` by setting the ``textwidth`` option::
  335. .. code-block:: vim
  336. set textwidth=78
  337. If adhering to this limit makes the code less readable, you have one more
  338. character to go on, which means 78 is a soft limit, and 79 is the hard
  339. limit :)
  340. * Import order
  341. * Python standard library (`import xxx`)
  342. * Python standard library ('from xxx import`)
  343. * Third party packages.
  344. * Other modules from the current package.
  345. or in case of code using Django:
  346. * Python standard library (`import xxx`)
  347. * Python standard library ('from xxx import`)
  348. * Third party packages.
  349. * Django packages.
  350. * Other modules from the current package.
  351. Within these sections the imports should be sorted by module name.
  352. Example:
  353. .. code-block:: python
  354. import threading
  355. import time
  356. from collections import deque
  357. from Queue import Queue, Empty
  358. from .datastructures import TokenBucket
  359. from .utils import timeutils
  360. from .utils.compat import all, izip_longest, chain_from_iterable
  361. * Wildcard imports must not be used (`from xxx import *`).
  362. * For distributions where Python 2.5 is the oldest support version
  363. additional rules apply:
  364. * Absolute imports must be enabled at the top of every module::
  365. from __future__ import absolute_import
  366. * If the module uses the with statement it must also enable that::
  367. from __future__ import with_statement
  368. * Every future import must be on its own line, as older Python 2.5
  369. releases did not support importing multiple features on the
  370. same future import line::
  371. # Good
  372. from __future__ import absolute_import
  373. from __future__ import with_statement
  374. # Bad
  375. from __future__ import absolute_import, with_statement
  376. (Note that this rule does not apply if the package does not include
  377. support for Python 2.5)
  378. * Note that we use "new-style` relative imports when the distribution
  379. does not support Python versions below 2.5
  380. .. code-block:: python
  381. from . import submodule
  382. .. _release-procedure:
  383. Release Procedure
  384. =================
  385. Commands to make a new public stable release::
  386. $ paver releaseok # checks pep8, autodoc index and runs tests
  387. $ paver removepyc # Remove .pyc files.
  388. $ git clean -xdn # Check that there's no left-over files in the repository.
  389. $ python2.5 setup.py sdist upload # Upload package to PyPI
  390. $ paver upload_pypi_docs
  391. $ paver ghdocs # Build and upload documentation to Github.
  392. If this is a new release series then you also need to do the
  393. following:
  394. * Go to the Read The Docs management interface at:
  395. http://readthedocs.org/projects/celery/?fromdocs=celery
  396. * Enter "Edit project"
  397. Change default branch to the branch of this series, e.g. ``2.4``
  398. for series 2.4.
  399. * Also add the previous version under the "versions" tab.