We're always grateful for contributions to Django's code. Indeed, bug reports with associated contributions will get fixed far more quickly than those without a solution.
如果您正在修复一个非常微不足道的问题,例如更改文档中的一个单词,推荐的方法是使用 GitHub 提交拉取请求,而无需使用 Trac 工单。
有关如何使用拉取请求的更多详细信息,请参见 使用 Git 和 GitHub 工作 。
在一个全球有数百个贡献者的开源项目中,有效地管理沟通以避免重复工作并尽可能提高贡献者的效率是非常重要的。
因此,我们的政策是供贡献者“发布”工单,以便让其他开发人员知道正在处理特定的错误或功能。
如果您确定了要做出的贡献并且有能力解决(通过编程能力,Django内核知识水平和时间可用性来衡量),请按照以下步骤进行发表:
备注
The Django software foundation requests that anyone contributing more than a trivial change to Django sign and submit a Contributor License Agreement, this ensures that the Django Software Foundation has clear license to all contributions allowing for a clear license for all users.
发布工单后,您有责任以合理及时的方式处理该工单。 如果您没有时间来处理它,请先取消发布或不发布它!
如果一两周内没有任何关于特定已发布工单的进展迹象,则另一位开发人员可能会要求您放弃该发布了的工单,以使其不再被垄断,而其他人也可以发布。
如果您已发布工单,并且要花很长时间(几天或几周)编写代码,请通过在工单上发布评论来使每个人都保持最新状态。如果您不提供定期更新,并且不响应进度报告的请求,则您对工单的要求可能会被撤消。
与往常一样,多交流好过少交流!
在某些情况下,执行认领工单的步骤可能过于繁琐。
In the case of small changes, such as typos in the documentation or small bugs that will only take a few minutes to fix, you don't need to jump through the hoops of claiming tickets. Submit your changes directly and you're done!
It is always acceptable, regardless whether someone has claimed it or not, to link proposals to a ticket if you happen to have the changes ready.
确保您所做的任何贡献至少满足以下要求:
When you think your work is ready to be reviewed, send a GitHub pull request. If you can't send a pull request for some reason, you can also use patches in Trac. When using this style, follow these guidelines.
git diff
命令返回的格式提交补丁。.diff
命名补丁文件; 这将使工单跟踪系统应用正确的语法突出显示,这非常有帮助。无论您以何种方式提交工作成果,请按照以下步骤操作。
A "non-trivial" contribution is one that is more than a small bug fix. It's a change that introduces new Django functionality and makes some sort of design decision.
If you provide a non-trivial change, include evidence that alternatives have been discussed on the Django Forum or django-developers list.
If you're not sure whether your contribution should be considered non-trivial, ask on the ticket for opinions.
Django 中的代码可能被弃用的原因有几个:
正如 弃用政策 所描述的那样,第一个弃用某项功能的 Django 版本(A.B
)在调用被弃用功能时应该引发一个 RemovedInDjangoXXWarning
警告(其中 XX 是将要删除该功能的 Django 版本)。假设我们有良好的测试覆盖率,在启用警告的情况下,这些警告将在 运行测试套件 时转换为错误:python -Wa runtests.py
。因此,在添加 RemovedInDjangoXXWarning
时,您需要消除或消除运行测试时生成的任何警告。
第一步是通过 Django 自身去除对被弃用行为的使用。接下来,您可以使用 ignore_warnings
装饰器来消除测试中实际测试被弃用行为的警告,可以在测试或类级别使用它:
在一个特定的测试中:
from django.test import ignore_warnings
from django.utils.deprecation import RemovedInDjangoXXWarning
@ignore_warnings(category=RemovedInDjangoXXWarning)
def test_foo(self): ...
对于整个测试用例:
from django.test import ignore_warnings
from django.utils.deprecation import RemovedInDjangoXXWarning
@ignore_warnings(category=RemovedInDjangoXXWarning)
class MyDeprecatedTests(unittest.TestCase): ...
您还应该为弃用警告添加一个测试:
from django.utils.deprecation import RemovedInDjangoXXWarning
def test_foo_deprecation_warning(self):
msg = "Expected deprecation message"
with self.assertWarnsMessage(RemovedInDjangoXXWarning, msg) as ctx:
# invoke deprecated behavior
...
self.assertEqual(ctx.filename, __file__)
重要的是在没有警告引用但在弃用结束时需要更改或删除的代码上方包含一个 RemovedInDjangoXXWarning
注释。这可能包括已添加以保持先前行为的钩子,或在弃用结束时不再需要或未使用的独立项目。例如:
import warnings
from django.utils.deprecation import RemovedInDjangoXXWarning
# RemovedInDjangoXXWarning.
def old_private_helper():
# Helper function that is only used in foo().
pass
def foo():
warnings.warn(
"foo() is deprecated.",
category=RemovedInDjangoXXWarning,
stacklevel=2,
)
old_private_helper()
...
最后,还有一些更新需要进行,以更新 Django 的文档:
.. deprecated:: A.B
注解在文档中标记它为已弃用。如果适用,包括一个简短的描述和有关升级路径的说明。docs/releases/A.B.txt
)中,放在 "Features deprecated in A.B" 标题下。docs/internals/deprecation.txt
)中,描述将要被移除的代码。一旦完成了这些步骤,你就完成了弃用过程。在每个 特性发布 中,与新版本匹配的所有 RemovedInDjangoXXWarning
都会被移除。
For information on JavaScript contributions, see the JavaScript 补丁 documentation.
Patches aiming to deliver a performance improvement should provide benchmarks showing the before and after impact of the patch and sharing the commands for reviewers to reproduce.
django-asv
benchmarks¶django-asv monitors the performance of Django code over time. These
benchmarks can be run on a pull request by labeling the pull request with
benchmark
. Adding to these benchmarks is highly encouraged.
Use this checklist to review a pull request. If you are reviewing a pull request that is not your own and it passes all the criteria below, please set the "Triage Stage" on the corresponding Trac ticket to "Ready for checkin". If you've left comments for improvement on the pull request, please tick the appropriate flags on the Trac ticket based on the results of your review: "Patch needs improvement", "Needs documentation", and/or "Needs tests". As time and interest permits, mergers do final reviews of "Ready for checkin" tickets and will either commit the changes or bump it back to "Accepted" if further work needs to be done. If you're looking to become a merger, doing thorough reviews of contributions is a great way to earn trust.
Looking for a patch to review? Check out the "Patches needing review" section of the Django Development Dashboard.
Looking to get your pull request reviewed? Ensure the Trac flags on the ticket are set so that the ticket appears in that queue.
docs/releases/A.B.C.txt
中有一份发行说明?只会应用到主分支的 bug 修复不需要发行说明。docs/releases/A.B.txt
中有一份发行说明?.. versionadded:: A.B
或 .. versionchanged:: A.B
进行了 注释 ?black
、blacken-docs
、flake8
或 isort
错误?您可以安装 pre-commit 钩子来自动捕获这些错误。docs/releases/A.B.txt
)中有说明?9月 16, 2024