submitting-patches.txt 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. ========================
  2. Submitting contributions
  3. ========================
  4. We're always grateful for contributions to Django's code. Indeed, bug reports
  5. with associated contributions will get fixed *far* more quickly than those
  6. without a solution.
  7. .. _trivial-change:
  8. Typo fixes and trivial documentation changes
  9. ============================================
  10. If you are fixing a really trivial issue, for example changing a word in the
  11. documentation, the preferred way to provide the patch is using GitHub pull
  12. requests without a Trac ticket.
  13. See the :doc:`working-with-git` for more details on how to use pull requests.
  14. "Claiming" tickets
  15. ==================
  16. In an open-source project with hundreds of contributors around the world, it's
  17. important to manage communication efficiently so that work doesn't get
  18. duplicated and contributors can be as effective as possible.
  19. Hence, our policy is for contributors to "claim" tickets in order to let other
  20. developers know that a particular bug or feature is being worked on.
  21. If you have identified a contribution you want to make and you're capable of
  22. fixing it (as measured by your coding ability, knowledge of Django internals
  23. and time availability), claim it by following these steps:
  24. * `Login using your GitHub account`_ or `create an account`_ in our ticket
  25. system. If you have an account but have forgotten your password, you can
  26. reset it using the `password reset page`_.
  27. * If a ticket for this issue doesn't exist yet, create one in our
  28. `ticket tracker`_.
  29. * If a ticket for this issue already exists, make sure nobody else has
  30. claimed it. To do this, look at the "Owned by" section of the ticket.
  31. If it's assigned to "nobody," then it's available to be claimed.
  32. Otherwise, somebody else may be working on this ticket. Either find another
  33. bug/feature to work on, or contact the developer working on the ticket to
  34. offer your help. If a ticket has been assigned for weeks or months without
  35. any activity, it's probably safe to reassign it to yourself.
  36. * Log into your account, if you haven't already, by clicking "GitHub Login"
  37. or "DjangoProject Login" in the upper left of the ticket page. Once logged
  38. in, you can then click the "Modify Ticket" button near the bottom of the
  39. page.
  40. * Claim the ticket by clicking the "assign to" radio button in the "Action"
  41. section. Your username will be filled in the text box by default.
  42. * Finally click the "Submit changes" button at the bottom to save.
  43. .. note::
  44. The Django software foundation requests that anyone contributing more than
  45. a :ref:`trivial change <trivial-change>`, to Django sign and submit a
  46. `Contributor License Agreement`_, this ensures that the Django Software
  47. Foundation has clear license to all contributions allowing for a clear
  48. license for all users.
  49. .. _Login using your GitHub account: https://code.djangoproject.com/github/login
  50. .. _Create an account: https://www.djangoproject.com/accounts/register/
  51. .. _password reset page: https://www.djangoproject.com/accounts/password/reset/
  52. .. _Contributor License Agreement: https://www.djangoproject.com/foundation/cla/
  53. Ticket claimers' responsibility
  54. -------------------------------
  55. Once you've claimed a ticket, you have a responsibility to work on that ticket
  56. in a reasonably timely fashion. If you don't have time to work on it, either
  57. unclaim it or don't claim it in the first place!
  58. If there's no sign of progress on a particular claimed ticket for a week or
  59. two, another developer may ask you to relinquish the ticket claim so that it's
  60. no longer monopolized and somebody else can claim it.
  61. If you've claimed a ticket and it's taking a long time (days or weeks) to code,
  62. keep everybody updated by posting comments on the ticket. If you don't provide
  63. regular updates, and you don't respond to a request for a progress report,
  64. your claim on the ticket may be revoked.
  65. As always, more communication is better than less communication!
  66. Which tickets should be claimed?
  67. --------------------------------
  68. Going through the steps of claiming tickets is overkill in some cases.
  69. In the case of small changes, such as typos in the documentation or small bugs
  70. that will only take a few minutes to fix, you don't need to jump through the
  71. hoops of claiming tickets. Submit your changes directly and you're done!
  72. It is *always* acceptable, regardless whether someone has claimed it or not, to
  73. link proposals to a ticket if you happen to have the changes ready.
  74. .. _patch-style:
  75. Contribution style
  76. ==================
  77. Make sure that any contribution you do fulfills at least the following
  78. requirements:
  79. * The code required to fix a problem or add a feature is an essential part
  80. of a solution, but it is not the only part. A good fix should also include a
  81. :doc:`regression test <unit-tests>` to validate the behavior that has been
  82. fixed and to prevent the problem from arising again. Also, if some tickets
  83. are relevant to the code that you've written, mention the ticket numbers in
  84. some comments in the test so that one can easily trace back the relevant
  85. discussions after your patch gets committed, and the tickets get closed.
  86. * If the code adds a new feature, or modifies the behavior of an existing
  87. feature, the change should also contain documentation.
  88. When you think your work is ready to be reviewed, send :doc:`a GitHub pull
  89. request <working-with-git>`.
  90. If you can't send a pull request for some reason, you can also use patches in
  91. Trac. When using this style, follow these guidelines.
  92. * Submit patches in the format returned by the ``git diff`` command.
  93. * Attach patches to a ticket in the `ticket tracker`_, using the "attach
  94. file" button. Please *don't* put the patch in the ticket description
  95. or comment unless it's a single line patch.
  96. * Name the patch file with a ``.diff`` extension; this will let the ticket
  97. tracker apply correct syntax highlighting, which is quite helpful.
  98. Regardless of the way you submit your work, follow these steps.
  99. * Make sure your code fulfills the requirements in our :ref:`contribution
  100. checklist <patch-review-checklist>`.
  101. * Check the "Has patch" box on the ticket and make sure the "Needs
  102. documentation", "Needs tests", and "Patch needs improvement" boxes aren't
  103. checked. This makes the ticket appear in the "Patches needing review" queue
  104. on the `Development dashboard`_.
  105. .. _ticket tracker: https://code.djangoproject.com/
  106. .. _Development dashboard: https://dashboard.djangoproject.com/
  107. Contributions which require community feedback
  108. ==============================================
  109. A wider community discussion is required when a patch introduces new Django
  110. functionality and makes some sort of design decision. This is especially
  111. important if the approach involves a :ref:`deprecation <deprecating-a-feature>`
  112. or introduces breaking changes.
  113. The following are different approaches for gaining feedback from the community.
  114. The Django Forum or django-developers mailing list
  115. --------------------------------------------------
  116. You can propose a change on the `Django Forum`_ or |django-developers| mailing
  117. list. You should explain the need for the change, go into details of the
  118. approach and discuss alternatives.
  119. Please include a link to such discussions in your contributions.
  120. Third party package
  121. -------------------
  122. Django does not accept experimental features. All features must follow our
  123. :ref:`deprecation policy <internal-release-deprecation-policy>`. Hence, it can
  124. take months or years for Django to iterate on an API design.
  125. If you need user feedback on a public interface, it is better to create a
  126. third-party package first. You can iterate on the public API much faster, while
  127. also validating the need for the feature.
  128. Once this package becomes stable and there are clear benefits of incorporating
  129. aspects into Django core, starting a discussion on the `Django Forum`_ or
  130. |django-developers| mailing list would be the next step.
  131. Django Enhancement Proposal (DEP)
  132. ---------------------------------
  133. Similar to Python’s PEPs, Django has `Django Enhancement Proposals`_ or DEPs. A
  134. DEP is a design document which provides information to the Django community, or
  135. describes a new feature or process for Django. They provide concise technical
  136. specifications of features, along with rationales. DEPs are also the primary
  137. mechanism for proposing and collecting community input on major new features.
  138. Before considering writing a DEP, it is recommended to first open a discussion
  139. on the `Django Forum`_ or |django-developers| mailing list. This allows the
  140. community to provide feedback and helps refine the proposal. Once the DEP is
  141. ready the :ref:`Steering Council <steering-council>` votes on whether to accept
  142. it.
  143. Some examples of DEPs that have been approved and fully implemented:
  144. * `DEP 181: ORM Expressions <https://github.com/django/deps/blob/main/final/0181-orm-expressions.rst>`_
  145. * `DEP 182: Multiple Template Engines <https://github.com/django/deps/blob/main/final/0182-multiple-template-engines.rst>`_
  146. * `DEP 201: Simplified routing syntax <https://github.com/django/deps/blob/main/final/0201-simplified-routing-syntax.rst>`_
  147. .. _Django Forum: https://forum.djangoproject.com/
  148. .. _Django Enhancement Proposals: https://github.com/django/deps
  149. .. _deprecating-a-feature:
  150. Deprecating a feature
  151. =====================
  152. There are a couple of reasons that code in Django might be deprecated:
  153. * If a feature has been improved or modified in a backwards-incompatible way,
  154. the old feature or behavior will be deprecated.
  155. * Sometimes Django will include a backport of a Python library that's not
  156. included in a version of Python that Django currently supports. When Django
  157. no longer needs to support the older version of Python that doesn't include
  158. the library, the library will be deprecated in Django.
  159. As the :ref:`deprecation policy<internal-release-deprecation-policy>` describes,
  160. the first release of Django that deprecates a feature (``A.B``) should raise a
  161. ``RemovedInDjangoXXWarning`` (where XX is the Django version where the feature
  162. will be removed) when the deprecated feature is invoked. Assuming we have good
  163. test coverage, these warnings are converted to errors when :ref:`running the
  164. test suite <running-unit-tests>` with warnings enabled:
  165. ``python -Wa runtests.py``. Thus, when adding a ``RemovedInDjangoXXWarning``
  166. you need to eliminate or silence any warnings generated when running the tests.
  167. The first step is to remove any use of the deprecated behavior by Django itself.
  168. Next you can silence warnings in tests that actually test the deprecated
  169. behavior by using the ``ignore_warnings`` decorator, either at the test or class
  170. level:
  171. #) In a particular test::
  172. from django.test import ignore_warnings
  173. from django.utils.deprecation import RemovedInDjangoXXWarning
  174. @ignore_warnings(category=RemovedInDjangoXXWarning)
  175. def test_foo(self): ...
  176. #) For an entire test case::
  177. from django.test import ignore_warnings
  178. from django.utils.deprecation import RemovedInDjangoXXWarning
  179. @ignore_warnings(category=RemovedInDjangoXXWarning)
  180. class MyDeprecatedTests(unittest.TestCase): ...
  181. You should also add a test for the deprecation warning::
  182. from django.utils.deprecation import RemovedInDjangoXXWarning
  183. def test_foo_deprecation_warning(self):
  184. msg = "Expected deprecation message"
  185. with self.assertWarnsMessage(RemovedInDjangoXXWarning, msg) as ctx:
  186. # invoke deprecated behavior
  187. ...
  188. self.assertEqual(ctx.filename, __file__)
  189. It's important to include a ``RemovedInDjangoXXWarning`` comment above code
  190. which has no warning reference, but will need to be changed or removed when the
  191. deprecation ends. This could include hooks which have been added to keep the
  192. previous behavior, or standalone items that are unnecessary or unused when the
  193. deprecation ends. For example::
  194. import warnings
  195. from django.utils.deprecation import RemovedInDjangoXXWarning
  196. # RemovedInDjangoXXWarning.
  197. def old_private_helper():
  198. # Helper function that is only used in foo().
  199. pass
  200. def foo():
  201. warnings.warn(
  202. "foo() is deprecated.",
  203. category=RemovedInDjangoXXWarning,
  204. stacklevel=2,
  205. )
  206. old_private_helper()
  207. ...
  208. Finally, there are a couple of updates to Django's documentation to make:
  209. #) If the existing feature is documented, mark it deprecated in documentation
  210. using the ``.. deprecated:: A.B`` annotation. Include a short description
  211. and a note about the upgrade path if applicable.
  212. #) Add a description of the deprecated behavior, and the upgrade path if
  213. applicable, to the current release notes (``docs/releases/A.B.txt``) under
  214. the "Features deprecated in A.B" heading.
  215. #) Add an entry in the deprecation timeline (``docs/internals/deprecation.txt``)
  216. under the appropriate version describing what code will be removed.
  217. Once you have completed these steps, you are finished with the deprecation.
  218. In each :term:`feature release <Feature release>`, all
  219. ``RemovedInDjangoXXWarning``\s matching the new version are removed.
  220. JavaScript contributions
  221. ========================
  222. For information on JavaScript contributions, see the :ref:`javascript-patches`
  223. documentation.
  224. Optimization patches
  225. ====================
  226. Patches aiming to deliver a performance improvement should provide benchmarks
  227. showing the before and after impact of the patch and sharing the commands for
  228. reviewers to reproduce.
  229. .. _django-asv-benchmarks:
  230. ``django-asv`` benchmarks
  231. -------------------------
  232. `django-asv`_ monitors the performance of Django code over time. These
  233. benchmarks can be run on a pull request by labeling the pull request with
  234. ``benchmark``. Adding to these benchmarks is highly encouraged.
  235. .. _django-asv: https://github.com/django/django-asv/
  236. .. _patch-review-checklist:
  237. Contribution checklist
  238. ======================
  239. Use this checklist to review a pull request. If this contribution would not be
  240. :ref:`considered trivial <trivial-change>`, first ensure it has an accepted
  241. ticket before proceeding with the review.
  242. If the pull request passes all the criteria below and is not your own, please
  243. set the "Triage Stage" on the corresponding Trac ticket to "Ready for checkin".
  244. If you've left comments for improvement on the pull request, please tick the
  245. appropriate flags on the Trac ticket based on the results of your review:
  246. "Patch needs improvement", "Needs documentation", and/or "Needs tests". As time
  247. and interest permits, mergers do final reviews of "Ready for checkin" tickets
  248. and will either commit the changes or bump it back to "Accepted" if further
  249. work needs to be done.
  250. If you're looking to become a member of the `triage & review team
  251. <https://www.djangoproject.com/foundation/teams/#triage-review-team>`_, doing
  252. thorough reviews of contributions is a great way to earn trust.
  253. Looking for a patch to review? Check out the "Patches needing review" section
  254. of the `Django Development Dashboard <https://dashboard.djangoproject.com/>`_.
  255. Looking to get your pull request reviewed? Ensure the Trac flags on the ticket
  256. are set so that the ticket appears in that queue.
  257. Documentation
  258. -------------
  259. * Does the documentation build without any errors (``make html``, or
  260. ``make.bat html`` on Windows, from the ``docs`` directory)?
  261. * Does the documentation follow the writing style guidelines in
  262. :doc:`/internals/contributing/writing-documentation`?
  263. * Are there any :ref:`spelling errors <documentation-spelling-check>`?
  264. Bugs
  265. ----
  266. * Is there a proper regression test (the test should fail before the fix
  267. is applied)?
  268. * If it's a bug that :ref:`qualifies for a backport <supported-versions-policy>`
  269. to the stable version of Django, is there a release note in
  270. ``docs/releases/A.B.C.txt``? Bug fixes that will be applied only to the main
  271. branch don't need a release note.
  272. New Features
  273. ------------
  274. * Are there tests to "exercise" all of the new code?
  275. * Is there a release note in ``docs/releases/A.B.txt``?
  276. * Is there documentation for the feature and is it :ref:`annotated
  277. appropriately <documenting-new-features>` with
  278. ``.. versionadded:: A.B`` or ``.. versionchanged:: A.B``?
  279. Deprecating a feature
  280. ---------------------
  281. See the :ref:`deprecating-a-feature` guide.
  282. All code changes
  283. ----------------
  284. * Does the :doc:`coding style
  285. </internals/contributing/writing-code/coding-style>` conform to our
  286. guidelines? Are there any ``black``, ``blacken-docs``, ``flake8``, or
  287. ``isort`` errors? You can install the :ref:`pre-commit
  288. <coding-style-pre-commit>` hooks to automatically catch these errors.
  289. * If the change is backwards incompatible in any way, is there a note
  290. in the release notes (``docs/releases/A.B.txt``)?
  291. * Is Django's test suite passing?
  292. All tickets
  293. -----------
  294. * Is the pull request a single squashed commit with a message that follows our
  295. :ref:`commit message format <committing-guidelines>`?
  296. * Are you the patch author and a new contributor? Please add yourself to the
  297. :source:`AUTHORS` file and submit a `Contributor License Agreement`_.
  298. * Does this have an accepted ticket on Trac? All contributions require a ticket
  299. unless the :ref:`change is considered trivial <trivial-change>`.
  300. .. _Contributor License Agreement: https://www.djangoproject.com/foundation/cla/