submitting-patches.txt 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. ==================
  2. Submitting patches
  3. ==================
  4. We're always grateful for patches to Django's code. Indeed, bug reports
  5. with associated patches will get fixed *far* more quickly than those
  6. without patches.
  7. Typo fixes and trivial documentation changes
  8. --------------------------------------------
  9. If you are fixing a really trivial issue, for example changing a word in the
  10. documentation, the preferred way to provide the patch is using GitHub pull
  11. requests without a Trac ticket. Trac tickets are still acceptable.
  12. See the :doc:`working-with-git` for more details on how to use pull requests.
  13. "Claiming" tickets
  14. ------------------
  15. In an open-source project with hundreds of contributors around the world, it's
  16. important to manage communication efficiently so that work doesn't get
  17. duplicated and contributors can be as effective as possible.
  18. Hence, our policy is for contributors to "claim" tickets in order to let other
  19. developers know that a particular bug or feature is being worked on.
  20. If you have identified a contribution you want to make and you're capable of
  21. fixing it (as measured by your coding ability, knowledge of Django internals
  22. and time availability), claim it by following these steps:
  23. * `Create an account`_ to use in our ticket system. If you have an account
  24. but have forgotten your password, you can reset it using the
  25. `password reset page`_.
  26. * If a ticket for this issue doesn't exist yet, create one in our
  27. `ticket tracker`_.
  28. * If a ticket for this issue already exists, make sure nobody else has
  29. claimed it. To do this, look at the "Owned by" section of the ticket.
  30. If it's assigned to "nobody," then it's available to be claimed.
  31. Otherwise, somebody else is working on this ticket, and you either find
  32. another bug/feature to work on, or contact the developer working on the
  33. ticket to offer your help.
  34. * Log into your account, if you haven't already, by clicking "Login" in
  35. the upper right of the ticket page.
  36. * Claim the ticket:
  37. 1. click the "assign to myself" radio button under "Action" near the bottom of the
  38. page,
  39. 2. then click "Submit changes."
  40. .. note::
  41. The Django software foundation requests that anyone contributing more than
  42. a trivial patch to Django sign and submit a `Contributor License
  43. Agreement`_, this ensures that the Django Software Foundation has clear
  44. license to all contributions allowing for a clear license for all users.
  45. .. _Create an account: https://www.djangoproject.com/accounts/register/
  46. .. _password reset page: https://www.djangoproject.com/accounts/password/reset/
  47. .. _Contributor License Agreement: https://www.djangoproject.com/foundation/cla/
  48. Ticket claimers' responsibility
  49. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  50. Once you've claimed a ticket, you have a responsibility to work on that ticket
  51. in a reasonably timely fashion. If you don't have time to work on it, either
  52. unclaim it or don't claim it in the first place!
  53. If there's no sign of progress on a particular claimed ticket for a week or
  54. two, another developer may ask you to relinquish the ticket claim so that it's
  55. no longer monopolized and somebody else can claim it.
  56. If you've claimed a ticket and it's taking a long time (days or weeks) to code,
  57. keep everybody updated by posting comments on the ticket. If you don't provide
  58. regular updates, and you don't respond to a request for a progress report,
  59. your claim on the ticket may be revoked.
  60. As always, more communication is better than less communication!
  61. Which tickets should be claimed?
  62. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  63. Of course, going through the steps of claiming tickets is overkill in some
  64. cases.
  65. In the case of small changes, such as typos in the documentation or
  66. small bugs that will only take a few minutes to fix, you don't need to jump
  67. through the hoops of claiming tickets. Just submit your patch and be done with
  68. it.
  69. Of course, it is *always* acceptable, regardless whether someone has claimed it
  70. or not, to submit patches to a ticket if you happen to have a patch ready.
  71. .. _patch-style:
  72. Patch style
  73. -----------
  74. Make sure that any contribution you do fulfills at least the following
  75. requirements:
  76. * The code required to fix a problem or add a feature is an essential part
  77. of a patch, but it is not the only part. A good patch should also include a
  78. :doc:`regression test <unit-tests>` to validate the behavior that has been
  79. fixed and to prevent the problem from arising again. Also, if some tickets
  80. are relevant to the code that you've written, mention the ticket numbers in
  81. some comments in the test so that one can easily trace back the relevant
  82. discussions after your patch gets committed, and the tickets get closed.
  83. * If the code associated with a patch adds a new feature, or modifies
  84. behavior of an existing feature, the patch should also contain
  85. documentation.
  86. You can use either GitHub branches and pull requests or direct patches
  87. to publish your work. If you use the Git workflow, then you should
  88. announce your branch in the ticket by including a link to your branch.
  89. When you think your work is ready to be merged in create a pull request.
  90. See the :doc:`working-with-git` documentation for mode details.
  91. You can also use patches in Trac. When using this style, follow these
  92. guidelines.
  93. * Submit patches in the format returned by the ``git diff`` command.
  94. An exception is for code changes that are described more clearly in
  95. plain English than in code. Indentation is the most common example; it's
  96. hard to read patches when the only difference in code is that it's
  97. indented.
  98. * Attach patches to a ticket in the `ticket tracker`_, using the "attach
  99. file" button. Please *don't* put the patch in the ticket description
  100. or comment unless it's a single line patch.
  101. * Name the patch file with a ``.diff`` extension; this will let the ticket
  102. tracker apply correct syntax highlighting, which is quite helpful.
  103. Regardless of the way you submit your work, follow these steps.
  104. * Make sure your code matches our :doc:`coding-style`.
  105. * Check the "Has patch" box on the ticket details. This will make it
  106. obvious that the ticket includes a patch, and it will add the ticket to
  107. the `list of tickets with patches`_.
  108. Non-trivial patches
  109. -------------------
  110. A "non-trivial" patch is one that is more than a simple bug fix. It's a patch
  111. that introduces Django functionality and makes some sort of design decision.
  112. If you provide a non-trivial patch, include evidence that alternatives have
  113. been discussed on |django-developers|.
  114. If you're not sure whether your patch should be considered non-trivial, just
  115. ask.
  116. .. _deprecating-a-feature:
  117. Deprecating a feature
  118. ---------------------
  119. There are a couple reasons that code in Django might be deprecated:
  120. * If a feature has been improved or modified in a backwards-incompatible way,
  121. the old feature or behavior will be deprecated.
  122. * Sometimes Django will include a backport of a Python library that's not
  123. included in a version of Python that Django currently supports. When Django
  124. no longer needs to support the older version of Python that doesn't include
  125. the library, the library will be deprecated in Django.
  126. As the :ref:`deprecation policy<internal-release-deprecation-policy>` describes,
  127. the first release of Django that deprecates a feature (``A.B``) should raise a
  128. ``RemovedInDjangoXXWarning`` (where XX is the Django version where the feature
  129. will be removed) when the deprecated feature is invoked. Assuming we have good
  130. test coverage, these warnings are converted to errors when :ref:`running the
  131. test suite <running-unit-tests>` with warnings enabled:
  132. ``python -Wall runtests.py``. Thus, when adding a ``RemovedInDjangoXXWarning``
  133. you need to eliminate or silence any warnings generated when running the tests.
  134. The first step is to remove any use of the deprecated behavior by Django itself.
  135. Next you can silence warnings in tests that actually test the deprecated
  136. behavior by using the ``ignore_warnings`` decorator, either at the test or class
  137. level:
  138. #) In a particular test::
  139. from django.test import ignore_warnings
  140. from django.utils.deprecation import RemovedInDjangoXXWarning
  141. @ignore_warnings(category=RemovedInDjangoXXWarning)
  142. def test_foo(self):
  143. ...
  144. #) For an entire test case::
  145. from django.test import ignore_warnings
  146. from django.utils.deprecation import RemovedInDjangoXXWarning
  147. @ignore_warnings(category=RemovedInDjangoXXWarning)
  148. class MyDeprecatedTests(unittest.TestCase):
  149. ...
  150. .. versionchanged:: 1.8
  151. Previous versions of Django had some ``Ignore*DeprecationWarningsMixin``
  152. classes to prevent warnings from appearing. These have been replaced by the
  153. ``ignore_warnings`` decorator.
  154. You can also add a test for the deprecation warning. You'll have to disable the
  155. "warning as error" behavior in your test by doing::
  156. import warnings
  157. def test_foo_deprecation_warning(self):
  158. with warnings.catch_warnings(record=True) as warns:
  159. warnings.simplefilter('always') # prevent warnings from appearing as errors
  160. # invoke deprecated behavior
  161. self.assertEqual(len(warns), 1)
  162. msg = str(warns[0].message)
  163. self.assertEqual(msg, 'Expected deprecation message')
  164. Finally, there are a couple of updates to Django's documentation to make:
  165. #) If the existing feature is documented, mark it deprecated in documentation
  166. using the ``.. deprecated:: A.B`` annotation. Include a short description
  167. and a note about the upgrade path if applicable.
  168. #) Add a description of the deprecated behavior, and the upgrade path if
  169. applicable, to the current release notes (``docs/releases/A.B.txt``) under
  170. the "Features deprecated in A.B" heading.
  171. #) Add an entry in the deprecation timeline (``docs/internals/deprecation.txt``)
  172. under the ``A.B+2`` version describing what code will be removed.
  173. Once you have completed these steps, you are finished with the deprecation.
  174. In each major release, all ``RemovedInDjangoXXWarning``\s matching the new
  175. version are removed.
  176. Javascript patches
  177. ------------------
  178. Django's admin system leverages the jQuery framework to increase the
  179. capabilities of the admin interface. In conjunction, there is an emphasis on
  180. admin javascript performance and minimizing overall admin media file size.
  181. Serving compressed or "minified" versions of javascript files is considered
  182. best practice in this regard.
  183. To that end, patches for javascript files should include both the original
  184. code for future development (e.g. ``foo.js``), and a compressed version for
  185. production use (e.g. ``foo.min.js``). Any links to the file in the codebase
  186. should point to the compressed version.
  187. Compressing JavaScript
  188. ~~~~~~~~~~~~~~~~~~~~~~
  189. To simplify the process of providing optimized javascript code, Django
  190. includes a handy python script which should be used to create a "minified"
  191. version. To run it::
  192. python django/contrib/admin/bin/compress.py
  193. Behind the scenes, ``compress.py`` is a front-end for Google's
  194. `Closure Compiler`_ which is written in Java. However, the Closure Compiler
  195. library is not bundled with Django directly, so those wishing to contribute
  196. complete javascript patches will need to download and install the library
  197. independently. The Closure Compiler library requires `Java`_ 7 or higher.
  198. Please don't forget to run ``compress.py`` and include the ``diff`` of the
  199. minified scripts when submitting patches for Django's javascript.
  200. .. _Closure Compiler: https://developers.google.com/closure/compiler/
  201. .. _list of tickets with patches: https://code.djangoproject.com/query?status=new&status=assigned&status=reopened&has_patch=1&order=priority
  202. .. _ticket tracker: https://code.djangoproject.com/newticket
  203. .. _Java: https://www.java.com
  204. .. _patch-review-checklist:
  205. Patch review checklist
  206. ----------------------
  207. Use this checklist to review a pull request. If you are reviewing a pull
  208. request that is not your own and it passes all the criteria below, please set
  209. the "Triage Stage" on the corresponding Trac ticket to "Ready for checkin".
  210. If you've left comments for improvement on the pull request, please tick the
  211. appropriate flags on the Trac ticket based on the results of your review:
  212. "Patch needs improvement", "Needs documentation", and/or "Needs tests". As time
  213. and interest permits, core developers do final reviews of "Ready for checkin"
  214. tickets and will either commit the patch or bump it back to "Accepted" if
  215. further works need to be done. If you're looking to become a core developer,
  216. doing thorough reviews of patches is a great way to earn trust.
  217. Looking for a patch to review? Check out the "Patches needing review" section
  218. of the `Django Development Dashboard <https://dashboard.djangoproject.com/>`_.
  219. Looking to get your patch reviewed? Ensure the Trac flags on the ticket are
  220. set so that the ticket appears in that queue.
  221. Documentation
  222. ~~~~~~~~~~~~~
  223. * Does the documentation build without any errors (``make html``, or
  224. ``make.bat html`` on Windows, from the ``docs`` directory)?
  225. * Does the documentation follow the writing style guidelines in
  226. :doc:`/internals/contributing/writing-documentation`?
  227. * Are there any :ref:`spelling errors <documentation-spelling-check>`?
  228. Bugs
  229. ~~~~
  230. * Is there a proper regression test (the test should fail before the fix
  231. is applied)?
  232. New Features
  233. ~~~~~~~~~~~~
  234. * Are there tests to "exercise" all of the new code?
  235. * Is there a release note in ``docs/releases/A.B.txt``?
  236. * Is there documentation for the feature and is it annotated appropriately with
  237. ``.. versionadded:: A.B`` or ``.. versionchanged:: A.B``?
  238. Deprecating a feature
  239. ~~~~~~~~~~~~~~~~~~~~~
  240. See the :ref:`deprecating-a-feature` guide.
  241. All code changes
  242. ~~~~~~~~~~~~~~~~
  243. * Does the :doc:`coding style
  244. </internals/contributing/writing-code/coding-style>` conform to our
  245. guidelines? Are there any ``flake8`` errors?
  246. * If the change is backwards incompatible in any way, is there a note
  247. in the release notes (``docs/releases/A.B.txt``)?
  248. * Is Django's test suite passing? Ask in ``#django-dev`` for a core dev
  249. to build the pull request against our continuous integration server.
  250. All tickets
  251. ~~~~~~~~~~~
  252. * Is the pull request a single squashed commit with a message that follows our
  253. :ref:`commit message format <committing-guidelines>`?
  254. * Are you the patch author and a new contributor? Please add yourself to the
  255. ``AUTHORS`` file and submit a `Contributor License Agreement`_.
  256. .. _Contributor License Agreement: https://www.djangoproject.com/foundation/cla/