“Django/docs/3.0.x/internals/contributing/writing-code/submitting-patches”的版本间差异

来自菜鸟教程
Django/docs/3.0.x/internals/contributing/writing-code/submitting-patches
跳转至:导航、​搜索
(autoload)
 
(Page commit)
 
第1行: 第1行:
 +
{{DISPLAYTITLE:提交补丁 — Django 文档}}
 
<div id="submitting-patches" class="section">
 
<div id="submitting-patches" class="section">
  
= Submitting patches =
+
= 提交补丁 =
  
We're always grateful for patches to Django's code. Indeed, bug reports
+
我们总是感谢 Django 代码的补丁。 事实上,与没有补丁的错误报告相比,带有相关补丁的错误报告将更快地得到修复 ''far''
with associated patches will get fixed ''far'' more quickly than those
 
without patches.
 
  
 
<div id="typo-fixes-and-trivial-documentation-changes" class="section">
 
<div id="typo-fixes-and-trivial-documentation-changes" class="section">
  
== Typo fixes and trivial documentation changes ==
+
== 错别字修复和琐碎的文档更改 ==
  
If you are fixing a really trivial issue, for example changing a word in the
+
如果您正在修复一个非常微不足道的问题,例如更改文档中的一个词,提供补丁的首选方法是使用 GitHub 拉取请求,而无需使用 Trac 票证。
documentation, the preferred way to provide the patch is using GitHub pull
 
requests without a Trac ticket.
 
  
See the [[../working-with-git|<span class="doc">Working with Git and GitHub</span>]] for more details on how to use pull requests.
+
有关如何使用拉取请求的更多详细信息,请参阅 [[../working-with-git|使用 Git GitHub]]
  
  
第21行: 第18行:
 
<div id="claiming-tickets" class="section">
 
<div id="claiming-tickets" class="section">
  
== &quot;Claiming&quot; tickets ==
+
== “索取”门票 ==
  
In an open-source project with hundreds of contributors around the world, it's
+
在全球有数百名贡献者的开源项目中,有效管理沟通非常重要,这样工作就不会重复,贡献者才能尽可能高效。
important to manage communication efficiently so that work doesn't get
 
duplicated and contributors can be as effective as possible.
 
  
Hence, our policy is for contributors to &quot;claim&quot; tickets in order to let other
+
因此,我们的政策是让贡献者“申领”门票,以便让其他开发人员知道正在处理特定的错误或功能。
developers know that a particular bug or feature is being worked on.
 
  
If you have identified a contribution you want to make and you're capable of
+
如果你已经确定了你想要做出的贡献并且你有能力修复它(根据你的编码能力、Django 内部知识和时间可用性来衡量),请按照以下步骤声明它:
fixing it (as measured by your coding ability, knowledge of Django internals
 
and time availability), claim it by following these steps:
 
  
* [https://code.djangoproject.com/github/login Login using your GitHub account] or [https://www.djangoproject.com/accounts/register/ create an account] in our ticket system. If you have an account but have forgotten your password, you can reset it using the [https://www.djangoproject.com/accounts/password/reset/ password reset page].
+
* [https://code.djangoproject.com/github/login 使用您的GitHub帐户登录][https://www.djangoproject.com/accounts/register/ 在我们的票务系统中创建一个帐户]。 如果您有账户但忘记了密码,您可以使用[https://www.djangoproject.com/accounts/password/reset/ 密码重置页面]重置它。
* If a ticket for this issue doesn't exist yet, create one in our [https://code.djangoproject.com/ ticket tracker].
+
* 如果此问题的工单尚不存在,请在我们的 [https://code.djangoproject.com/ 工单跟踪器] 中创建一张工单。
* If a ticket for this issue already exists, make sure nobody else has claimed it. To do this, look at the &quot;Owned by&quot; section of the ticket. If it's assigned to &quot;nobody,&quot; then it's available to be claimed. Otherwise, somebody else may be working on this ticket. Either find another bug/feature to work on, or contact the developer working on the ticket to offer your help. If a ticket has been assigned for weeks or months without any activity, it's probably safe to reassign it to yourself.
+
* 如果此问题的票证已经存在,请确保没有其他人声明过它。 为此,请查看票证的“所有者”部分。 如果它被分配给“没有人”,那么它就可以被认领。 否则,其他人可能正在处理此票证。 要么找到另一个要处理的错误/功能,要么联系处理故障单的开发人员以提供帮助。 如果一张票已被分配了数周或数月而没有任何活动,则将其重新分配给自己可能是安全的。
* Log into your account, if you haven't already, by clicking &quot;GitHub Login&quot; or &quot;DjangoProject Login&quot; in the upper left of the ticket page.
+
* 登录您的帐户,如果您还没有,请单击票务页面左上角的“GitHub 登录”或“DjangoProject 登录”。
* Claim the ticket by clicking the &quot;assign to myself&quot; radio button under &quot;Action&quot; near the bottom of the page, then click &quot;Submit changes.&quot;
+
* 通过单击页面底部附近“操作”下的“分配给我自己”单选按钮索取票证,然后单击“提交更改”。
  
 
<div class="admonition note">
 
<div class="admonition note">
  
注解
+
笔记
  
The Django software foundation requests that anyone contributing more than
+
Django 软件基金会要求任何为 Django 贡献的不仅仅是一个简单补丁的人签署并提交 [https://www.djangoproject.com/foundation/cla/ 贡献者许可协议] ,这确保了 Django 软件基金会对所有贡献拥有明确的许可,从而为所有用户提供明确的许可.
a trivial patch to Django sign and submit a [https://www.djangoproject.com/foundation/cla/ Contributor License
 
Agreement], this ensures that the Django Software Foundation has clear
 
license to all contributions allowing for a clear license for all users.
 
  
  
第53行: 第42行:
 
<div id="ticket-claimers-responsibility" class="section">
 
<div id="ticket-claimers-responsibility" class="section">
  
=== Ticket claimers' responsibility ===
+
=== 购票人的责任 ===
  
Once you've claimed a ticket, you have a responsibility to work on that ticket
+
一旦您申领了一张罚单,您就有责任以合理的方式及时处理该罚单。 如果您没有时间处理它,要么取消它,要么首先不要声明它!
in a reasonably timely fashion. If you don't have time to work on it, either
 
unclaim it or don't claim it in the first place!
 
  
If there's no sign of progress on a particular claimed ticket for a week or
+
如果某张已领取的门票在一两周内没有任何进展迹象,另一位开发人员可能会要求您放弃该门票领取,以便它不再被垄断,其他人可以领取它。
two, another developer may ask you to relinquish the ticket claim so that it's
 
no longer monopolized and somebody else can claim it.
 
  
If you've claimed a ticket and it's taking a long time (days or weeks) to code,
+
如果您已经申领了一张票并且需要很长时间(几天或几周)来编码,请通过在票上发表评论来让每个人都了解最新情况。 如果您不提供定期更新,并且您不回应进度报告的请求,您对票的索赔可能会被撤销。
keep everybody updated by posting comments on the ticket. If you don't provide
 
regular updates, and you don't respond to a request for a progress report,
 
your claim on the ticket may be revoked.
 
  
As always, more communication is better than less communication!
+
一如既往,多交流总比少交流好!
  
  
第74行: 第56行:
 
<div id="which-tickets-should-be-claimed" class="section">
 
<div id="which-tickets-should-be-claimed" class="section">
  
=== Which tickets should be claimed? ===
+
=== 应该申领哪些门票? ===
  
Of course, going through the steps of claiming tickets is overkill in some
+
当然,在某些情况下,通过索取门票的步骤是矫枉过正的。
cases.
 
  
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 patch directly and you're done!
 
  
Of course, it is ''always'' acceptable, regardless whether someone has claimed it
+
当然, ''总是'' 可以接受,无论是否有人声称,如果您碰巧准备好补丁,则将补丁提交到票证。
or not, to submit patches to a ticket if you happen to have a patch ready.
 
  
  
第93行: 第71行:
  
 
<span id="id1"></span>
 
<span id="id1"></span>
== Patch style ==
+
== 补丁样式 ==
  
Make sure that any contribution you do fulfills at least the following
+
确保您所做的任何贡献至少满足以下要求:
requirements:
 
  
* The code required to fix a problem or add a feature is an essential part of a patch, but it is not the only part. A good patch should also include a [[../unit-tests|<span class="doc">regression test</span>]] to validate the behavior that has been fixed and to prevent the problem from arising again. Also, if some tickets are relevant to the code that you've written, mention the ticket numbers in some comments in the test so that one can easily trace back the relevant discussions after your patch gets committed, and the tickets get closed.
+
* 修复问题或添加功能所需的代码是补丁的重要部分,但不是唯一的部分。 一个好的补丁还应该包括 [[../unit-tests|回归测试]] 以验证已修复的行为并防止问题再次出现。 此外,如果某些工单与您编写的代码相关,请在测试中的某些注释中提及工单编号,以便在您提交补丁并关闭工单后可以轻松追溯相关讨论。
* If the code associated with a patch adds a new feature, or modifies behavior of an existing feature, the patch should also contain documentation.
+
* 如果与补丁相关联的代码添加了新功能,或修改了现有功能的行为,则补丁还应包含文档。
  
When you think your work is ready to be reviewed, send [[../working-with-git|<span class="doc">a GitHub pull
+
当您认为您的工作已准备好接受审查时,请发送 [[../working-with-git|GitHub 拉取请求]] 。 请先使用我们的 [[#patch-review-checklist|补丁审查清单]] 自己审查补丁。
request</span>]]. Please review the patch yourself using our
 
[[#patch-review-checklist|<span class="std std-ref">patch review checklist</span>]] first.
 
  
If you can't send a pull request for some reason, you can also use patches in
+
如果由于某种原因无法发送 pull request,也可以在 Trac 中使用补丁。 使用此样式时,请遵循以下准则。
Trac. When using this style, follow these guidelines.
 
  
* Submit patches in the format returned by the <code>git diff</code> command.
+
* <code>git diff</code> 命令返回的格式提交补丁。
* Attach patches to a ticket in the [https://code.djangoproject.com/ ticket tracker], using the &quot;attach file&quot; button. Please ''don't'' put the patch in the ticket description or comment unless it's a single line patch.
+
* 使用“附加文件”按钮将补丁附加到 [https://code.djangoproject.com/ 票务跟踪器] 中的票证。 请''不要''将补丁放入票证描述或评论中,除非它是单行补丁。
* Name the patch file with a <code>.diff</code> extension; this will let the ticket tracker apply correct syntax highlighting, which is quite helpful.
+
* 将补丁文件命名为 <code>.diff</code> 扩展名; 这将使票证跟踪器应用正确的语法突出显示,这非常有用。
  
Regardless of the way you submit your work, follow these steps.
+
无论您提交作品的方式如何,请按照以下步骤操作。
  
* Make sure your code fulfills the requirements in our [[#patch-review-checklist|<span class="std std-ref">patch review checklist</span>]].
+
* 确保您的代码满足我们的 [[#patch-review-checklist|补丁审查清单]] 中的要求。
* Check the &quot;Has patch&quot; box on the ticket and make sure the &quot;Needs documentation&quot;, &quot;Needs tests&quot;, and &quot;Patch needs improvement&quot; boxes aren't checked. This makes the ticket appear in the &quot;Patches needing review&quot; queue on the [https://dashboard.djangoproject.com/ Development dashboard].
+
* 检查票证上的“有补丁”框,并确保未选中“需要文档”、“需要测试”和“补丁需要改进”框。 这使得故障单出现在 [https://dashboard.djangoproject.com/ 开发仪表板] 上的“需要审查的补丁”队列中。
  
  
第121行: 第95行:
 
<div id="non-trivial-patches" class="section">
 
<div id="non-trivial-patches" class="section">
  
== Non-trivial patches ==
+
== 重要补丁 ==
  
A &quot;non-trivial&quot; patch is one that is more than a small bug fix. It's a patch
+
“非平凡”补丁不仅仅是一个小错误修复。 这是一个引入 Django 功能并做出某种设计决策的补丁。
that introduces Django functionality and makes some sort of design decision.
 
  
If you provide a non-trivial patch, include evidence that alternatives have
+
如果您提供了一个重要的补丁,请提供已经在 [[../../../mailing-lists#django-developers-mailing-list|django-developers]] 上讨论过替代方案的证据。
been discussed on [[../../../mailing-lists#django-developers-mailing-list|<span class="std std-ref">django-developers</span>]].
 
  
If you're not sure whether your patch should be considered non-trivial, ask on
+
如果您不确定您的补丁是否应该被视为非平凡,请在票证上征求意见。
the ticket for opinions.
 
  
  
第137行: 第108行:
  
 
<span id="id2"></span>
 
<span id="id2"></span>
== Deprecating a feature ==
+
== 弃用功能 ==
  
There are a couple of reasons that code in Django might be deprecated:
+
不推荐使用 Django 中的代码有几个原因:
  
* If a feature has been improved or modified in a backwards-incompatible way, the old feature or behavior will be deprecated.
+
* 如果某个功能以向后不兼容的方式进行了改进或修改,则旧功能或行为将被弃用。
* Sometimes Django will include a backport of a Python library that's not included in a version of Python that Django currently supports. When Django no longer needs to support the older version of Python that doesn't include the library, the library will be deprecated in Django.
+
* 有时 Django 会包含一个 Python 库的向后移植,该库不包含在 Django 当前支持的 Python 版本中。 当 Django 不再需要支持不包含该库的旧版 Python 时,该库将在 Django 中被弃用。
  
As the [[../../../release-process#internal-release-deprecation-policy|<span class="std std-ref">deprecation policy</span>]] describes,
+
正如 [[../../../release-process#internal-release-deprecation-policy|弃用政策]] 所描述的,弃用功能 (<code>A.B</code>) 的第一个 Django 版本应该引发 <code>RemovedInDjangoXXWarning</code>(其中 XX 是该功能所在的 Django 版本)删除)当不推荐使用的功能被调用时。 假设我们有良好的测试覆盖率,当 [[../unit-tests#running-unit-tests|在启用警告的情况下运行测试套件]] 时,这些警告将转换为错误:<code>python -Wa runtests.py</code>。 因此,在添加 <code>RemovedInDjangoXXWarning</code> 时,您需要消除或消除运行测试时生成的任何警告。
the first release of Django that deprecates a feature (<code>A.B</code>) should raise a
 
<code>RemovedInDjangoXXWarning</code> (where XX is the Django version where the feature
 
will be removed) when the deprecated feature is invoked. Assuming we have good
 
test coverage, these warnings are converted to errors when [[../unit-tests#running-unit-tests|<span class="std std-ref">running the
 
test suite</span>]] with warnings enabled:
 
<code>python -Wa runtests.py</code>. Thus, when adding a <code>RemovedInDjangoXXWarning</code>
 
you need to eliminate or silence any warnings generated when running the tests.
 
  
The first step is to remove any use of the deprecated behavior by Django itself.
+
第一步是删除 Django 本身对弃用行为的任何使用。 接下来,您可以在测试或类级别使用 <code>ignore_warnings</code> 装饰器在实际测试弃用行为的测试中消除警告:
Next you can silence warnings in tests that actually test the deprecated
 
behavior by using the <code>ignore_warnings</code> decorator, either at the test or class
 
level:
 
  
 
<ol>
 
<ol>
<li><p>In a particular test:</p>
+
<li><p>在特定测试中:</p>
 
<div class="highlight-default notranslate">
 
<div class="highlight-default notranslate">
  
 
<div class="highlight">
 
<div class="highlight">
  
<pre>from django.test import ignore_warnings
+
<syntaxhighlight lang="python">from django.test import ignore_warnings
 
from django.utils.deprecation import RemovedInDjangoXXWarning
 
from django.utils.deprecation import RemovedInDjangoXXWarning
  
 
@ignore_warnings(category=RemovedInDjangoXXWarning)
 
@ignore_warnings(category=RemovedInDjangoXXWarning)
 
def test_foo(self):
 
def test_foo(self):
     ...</pre>
+
     ...</syntaxhighlight>
  
 
</div>
 
</div>
  
 
</div></li>
 
</div></li>
<li><p>For an entire test case:</p>
+
<li><p>对于整个测试用例:</p>
 
<div class="highlight-default notranslate">
 
<div class="highlight-default notranslate">
  
 
<div class="highlight">
 
<div class="highlight">
  
<pre>from django.test import ignore_warnings
+
<syntaxhighlight lang="python">from django.test import ignore_warnings
 
from django.utils.deprecation import RemovedInDjangoXXWarning
 
from django.utils.deprecation import RemovedInDjangoXXWarning
  
 
@ignore_warnings(category=RemovedInDjangoXXWarning)
 
@ignore_warnings(category=RemovedInDjangoXXWarning)
 
class MyDeprecatedTests(unittest.TestCase):
 
class MyDeprecatedTests(unittest.TestCase):
     ...</pre>
+
     ...</syntaxhighlight>
  
 
</div>
 
</div>
第190行: 第151行:
 
</div></li></ol>
 
</div></li></ol>
  
You can also add a test for the deprecation warning:
+
您还可以为弃用警告添加测试:
  
 
<div class="highlight-default notranslate">
 
<div class="highlight-default notranslate">
第196行: 第157行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>from django.utils.deprecation import RemovedInDjangoXXWarning
+
<syntaxhighlight lang="python">from django.utils.deprecation import RemovedInDjangoXXWarning
  
 
def test_foo_deprecation_warning(self):
 
def test_foo_deprecation_warning(self):
 
     msg = 'Expected deprecation message'
 
     msg = 'Expected deprecation message'
 
     with self.assertWarnsMessage(RemovedInDjangoXXWarning, msg):
 
     with self.assertWarnsMessage(RemovedInDjangoXXWarning, msg):
         # invoke deprecated behavior</pre>
+
         # invoke deprecated behavior</syntaxhighlight>
  
 
</div>
 
</div>
  
 
</div>
 
</div>
Finally, there are a couple of updates to Django's documentation to make:
+
最后,对 Django 的文档进行了一些更新:
  
# If the existing feature is documented, mark it deprecated in documentation using the <code>.. deprecated:: A.B</code> annotation. Include a short description and a note about the upgrade path if applicable.
+
# 如果记录了现有功能,请使用 <code>.. deprecated:: A.B</code> 注释在文档中将其标记为已弃用。 如果适用,请包括有关升级路径的简短说明和注释。
# Add a description of the deprecated behavior, and the upgrade path if applicable, to the current release notes (<code>docs/releases/A.B.txt</code>) under the &quot;Features deprecated in A.B&quot; heading.
+
# 在当前版本说明 (<code>docs/releases/A.B.txt</code>) 的“AB 中弃用的功能”标题下添加对弃用行为的描述和升级路径(如果适用)。
# Add an entry in the deprecation timeline (<code>docs/internals/deprecation.txt</code>) under the appropriate version describing what code will be removed.
+
# 在相应版本下的弃用时间线 (<code>docs/internals/deprecation.txt</code>) 中添加一个条目,描述将删除哪些代码。
  
Once you have completed these steps, you are finished with the deprecation.
+
完成这些步骤后,您就完成了弃用。 在每个[[../../../release-process#term-Feature-release|功能版本]]中,与新版本匹配的所有<code>RemovedInDjangoXXWarning</code>都被删除。
In each [[../../../release-process#term-Feature-release|<span class="xref std std-term">feature release</span>]], all
 
<code>RemovedInDjangoXXWarning</code>s matching the new version are removed.
 
  
  
第220行: 第179行:
 
<div id="javascript-patches" class="section">
 
<div id="javascript-patches" class="section">
  
== JavaScript patches ==
+
== JavaScript 补丁 ==
  
For information on JavaScript patches, see the [[../javascript#javascript-patches|<span class="std std-ref">JavaScript patches</span>]]
+
有关 JavaScript 补丁的信息,请参阅 [[../javascript#javascript-patches|JavaScript 补丁]] 文档。
documentation.
 
  
  
第230行: 第188行:
  
 
<span id="id3"></span>
 
<span id="id3"></span>
== Patch review checklist ==
+
== 补丁审查清单 ==
  
Use this checklist to review a pull request. If you are reviewing a pull
+
使用此清单检查拉取请求。 如果您正在审查不是您自己的拉取请求并且它通过了以下所有标准,请将相应 Trac 票证上的“分类阶段”设置为“准备签入”。 如果您对拉取请求留下了改进意见,请根据您的审查结果在 Trac 票证上勾选相应的标志:“补丁需要改进”、“需要文档”和/或“需要测试”。 在时间和兴趣允许的情况下,提交者会对“准备签入”票据进行最终审查,如果需要做进一步的工作,他们将提交补丁或将其退回“已接受”。 如果您想成为提交者,对补丁进行彻底审查是赢得信任的好方法。
request that is not your own and it passes all the criteria below, please set
 
the &quot;Triage Stage&quot; on the corresponding Trac ticket to &quot;Ready for checkin&quot;.
 
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:
 
&quot;Patch needs improvement&quot;, &quot;Needs documentation&quot;, and/or &quot;Needs tests&quot;. As time
 
and interest permits, committers do final reviews of &quot;Ready for checkin&quot;
 
tickets and will either commit the patch or bump it back to &quot;Accepted&quot; if
 
further works need to be done. If you're looking to become a committer,
 
doing thorough reviews of patches is a great way to earn trust.
 
  
Looking for a patch to review? Check out the &quot;Patches needing review&quot; section
+
正在寻找要审查的补丁? 查看 [https://dashboard.djangoproject.com/ Django 开发仪表板] 的“需要审查的补丁”部分。 想要审核您的补丁? 确保设置了票证上的 Trac 标志,以便票证出现在该队列中。
of the [https://dashboard.djangoproject.com/ Django Development Dashboard].
 
Looking to get your patch reviewed? Ensure the Trac flags on the ticket are
 
set so that the ticket appears in that queue.
 
  
 
<div id="documentation" class="section">
 
<div id="documentation" class="section">
第252行: 第198行:
 
=== 文档 ===
 
=== 文档 ===
  
* Does the documentation build without any errors (<code>make html</code>, or <code>make.bat html</code> on Windows, from the <code>docs</code> directory)?
+
* 文档构建时是否没有任何错误(<code>make html</code> 或 Windows 上的 <code>make.bat html</code>,来自 <code>docs</code> 目录)?
* Does the documentation follow the writing style guidelines in [[../../writing-documentation|<span class="doc">编写文档</span>]]?
+
* 文档是否遵循 [[../../writing-documentation|Writing documentation]] 中的写作风格指南?
* Are there any [[../../writing-documentation#documentation-spelling-check|<span class="std std-ref">spelling errors</span>]]?
+
* 是否有任何 [[../../writing-documentation#documentation-spelling-check|拼写错误]]
  
  
第260行: 第206行:
 
<div id="bugs" class="section">
 
<div id="bugs" class="section">
  
=== Bugs ===
+
=== 错误 ===
  
* Is there a proper regression test (the test should fail before the fix is applied)?
+
* 是否有适当的回归测试(在应用修复之前测试应该失败)?
* If it's a bug that [[../../../release-process#supported-versions-policy|<span class="std std-ref">qualifies for a backport</span>]] to the stable version of Django, is there a release note in <code>docs/releases/A.B.C.txt</code>? Bug fixes that will be applied only to the master branch don't need a release note.
+
* 如果是 [[../../../release-process#supported-versions-policy|有资格向后移植]] 到稳定版 Django 的错误,那么 <code>docs/releases/A.B.C.txt</code> 中是否有发行说明? 仅适用于 master 分支的错误修复不需要发行说明。
  
  
第269行: 第215行:
 
<div id="new-features" class="section">
 
<div id="new-features" class="section">
  
=== New Features ===
+
=== 新功能 ===
  
* Are there tests to &quot;exercise&quot; all of the new code?
+
* 是否有测试可以“锻炼”所有新代码?
* Is there a release note in <code>docs/releases/A.B.txt</code>?
+
* <code>docs/releases/A.B.txt</code> 中是否有发行说明?
* Is there documentation for the feature and is it [[../../writing-documentation#documenting-new-features|<span class="std std-ref">annotated appropriately</span>]] with <code>.. versionadded:: A.B</code> or <code>.. versionchanged:: A.B</code>?
+
* 是否有该功能的文档,并且 [[../../writing-documentation#documenting-new-features|是否用 <code>.. versionadded:: A.B</code> <code>.. versionchanged:: A.B</code> 进行了适当的注释]] ?
  
  
第279行: 第225行:
 
<div id="id4" class="section">
 
<div id="id4" class="section">
  
=== Deprecating a feature ===
+
=== 弃用功能 ===
  
See the [[#deprecating-a-feature|<span class="std std-ref">Deprecating a feature</span>]] guide.
+
请参阅 [[#deprecating-a-feature|弃用功能]] 指南。
  
  
第287行: 第233行:
 
<div id="all-code-changes" class="section">
 
<div id="all-code-changes" class="section">
  
=== All code changes ===
+
=== 所有代码更改 ===
  
* Does the [[../coding-style|<span class="doc">coding style</span>]] conform to our guidelines? Are there any <code>flake8</code> errors?
+
* [[../coding-style|编码风格]] 是否符合我们的准则? 是否有任何 <code>flake8</code> 错误?
* If the change is backwards incompatible in any way, is there a note in the release notes (<code>docs/releases/A.B.txt</code>)?
+
* 如果更改以任何方式向后不兼容,发行说明 (<code>docs/releases/A.B.txt</code>) 中是否有说明?
* Is Django's test suite passing?
+
* Django 的测试套件通过了吗?
  
  
第297行: 第243行:
 
<div id="all-tickets" class="section">
 
<div id="all-tickets" class="section">
  
=== All tickets ===
+
=== 所有门票 ===
  
* Is the pull request a single squashed commit with a message that follows our [[../../committing-code#committing-guidelines|<span class="std std-ref">commit message format</span>]]?
+
* 拉取请求是否是单个压缩提交,其消息遵循我们的 [[../../committing-code#committing-guidelines|提交消息格式]]
* Are you the patch author and a new contributor? Please add yourself to the <code>AUTHORS</code> file and submit a [https://www.djangoproject.com/foundation/cla/ Contributor License Agreement].
+
* 您是补丁作者和新贡献者吗? 请将您自己添加到 <code>AUTHORS</code> 文件中并提交 [https://www.djangoproject.com/foundation/cla/ 贡献者许可协议]
  
  
第308行: 第254行:
  
 
</div>
 
</div>
 +
<div class="clearer">
  
[[Category:Django 3.0.x 中文文档]]
+
 
 +
 
 +
</div>
 +
 
 +
[[Category:Django 3.0.x 文档]]

2021年10月31日 (日) 04:08的最新版本

提交补丁

我们总是感谢 Django 代码的补丁。 事实上,与没有补丁的错误报告相比,带有相关补丁的错误报告将更快地得到修复 far

错别字修复和琐碎的文档更改

如果您正在修复一个非常微不足道的问题,例如更改文档中的一个词,提供补丁的首选方法是使用 GitHub 拉取请求,而无需使用 Trac 票证。

有关如何使用拉取请求的更多详细信息,请参阅 使用 Git 和 GitHub


“索取”门票

在全球有数百名贡献者的开源项目中,有效管理沟通非常重要,这样工作就不会重复,贡献者才能尽可能高效。

因此,我们的政策是让贡献者“申领”门票,以便让其他开发人员知道正在处理特定的错误或功能。

如果你已经确定了你想要做出的贡献并且你有能力修复它(根据你的编码能力、Django 内部知识和时间可用性来衡量),请按照以下步骤声明它:

  • 使用您的GitHub帐户登录在我们的票务系统中创建一个帐户。 如果您有账户但忘记了密码,您可以使用密码重置页面重置它。
  • 如果此问题的工单尚不存在,请在我们的 工单跟踪器 中创建一张工单。
  • 如果此问题的票证已经存在,请确保没有其他人声明过它。 为此,请查看票证的“所有者”部分。 如果它被分配给“没有人”,那么它就可以被认领。 否则,其他人可能正在处理此票证。 要么找到另一个要处理的错误/功能,要么联系处理故障单的开发人员以提供帮助。 如果一张票已被分配了数周或数月而没有任何活动,则将其重新分配给自己可能是安全的。
  • 登录您的帐户,如果您还没有,请单击票务页面左上角的“GitHub 登录”或“DjangoProject 登录”。
  • 通过单击页面底部附近“操作”下的“分配给我自己”单选按钮索取票证,然后单击“提交更改”。

笔记

Django 软件基金会要求任何为 Django 贡献的不仅仅是一个简单补丁的人签署并提交 贡献者许可协议 ,这确保了 Django 软件基金会对所有贡献拥有明确的许可,从而为所有用户提供明确的许可.


购票人的责任

一旦您申领了一张罚单,您就有责任以合理的方式及时处理该罚单。 如果您没有时间处理它,要么取消它,要么首先不要声明它!

如果某张已领取的门票在一两周内没有任何进展迹象,另一位开发人员可能会要求您放弃该门票领取,以便它不再被垄断,其他人可以领取它。

如果您已经申领了一张票并且需要很长时间(几天或几周)来编码,请通过在票上发表评论来让每个人都了解最新情况。 如果您不提供定期更新,并且您不回应进度报告的请求,您对票的索赔可能会被撤销。

一如既往,多交流总比少交流好!


应该申领哪些门票?

当然,在某些情况下,通过索取门票的步骤是矫枉过正的。

对于小的更改,例如文档中的拼写错误或只需几分钟即可修复的小错误,您无需跳过索取票的麻烦。 直接提交您的补丁就大功告成了!

当然, 总是 可以接受,无论是否有人声称,如果您碰巧准备好补丁,则将补丁提交到票证。


补丁样式

确保您所做的任何贡献至少满足以下要求:

  • 修复问题或添加功能所需的代码是补丁的重要部分,但不是唯一的部分。 一个好的补丁还应该包括 回归测试 以验证已修复的行为并防止问题再次出现。 此外,如果某些工单与您编写的代码相关,请在测试中的某些注释中提及工单编号,以便在您提交补丁并关闭工单后可以轻松追溯相关讨论。
  • 如果与补丁相关联的代码添加了新功能,或修改了现有功能的行为,则补丁还应包含文档。

当您认为您的工作已准备好接受审查时,请发送 GitHub 拉取请求 。 请先使用我们的 补丁审查清单 自己审查补丁。

如果由于某种原因无法发送 pull request,也可以在 Trac 中使用补丁。 使用此样式时,请遵循以下准则。

  • git diff 命令返回的格式提交补丁。
  • 使用“附加文件”按钮将补丁附加到 票务跟踪器 中的票证。 请不要将补丁放入票证描述或评论中,除非它是单行补丁。
  • 将补丁文件命名为 .diff 扩展名; 这将使票证跟踪器应用正确的语法突出显示,这非常有用。

无论您提交作品的方式如何,请按照以下步骤操作。

  • 确保您的代码满足我们的 补丁审查清单 中的要求。
  • 检查票证上的“有补丁”框,并确保未选中“需要文档”、“需要测试”和“补丁需要改进”框。 这使得故障单出现在 开发仪表板 上的“需要审查的补丁”队列中。


重要补丁

“非平凡”补丁不仅仅是一个小错误修复。 这是一个引入 Django 功能并做出某种设计决策的补丁。

如果您提供了一个重要的补丁,请提供已经在 django-developers 上讨论过替代方案的证据。

如果您不确定您的补丁是否应该被视为非平凡,请在票证上征求意见。


弃用功能

不推荐使用 Django 中的代码有几个原因:

  • 如果某个功能以向后不兼容的方式进行了改进或修改,则旧功能或行为将被弃用。
  • 有时 Django 会包含一个 Python 库的向后移植,该库不包含在 Django 当前支持的 Python 版本中。 当 Django 不再需要支持不包含该库的旧版 Python 时,该库将在 Django 中被弃用。

正如 弃用政策 所描述的,弃用功能 (A.B) 的第一个 Django 版本应该引发 RemovedInDjangoXXWarning(其中 XX 是该功能所在的 Django 版本)删除)当不推荐使用的功能被调用时。 假设我们有良好的测试覆盖率,当 在启用警告的情况下运行测试套件 时,这些警告将转换为错误:python -Wa runtests.py。 因此,在添加 RemovedInDjangoXXWarning 时,您需要消除或消除运行测试时生成的任何警告。

第一步是删除 Django 本身对弃用行为的任何使用。 接下来,您可以在测试或类级别使用 ignore_warnings 装饰器在实际测试弃用行为的测试中消除警告:

  1. 在特定测试中:

    from django.test import ignore_warnings
    from django.utils.deprecation import RemovedInDjangoXXWarning
    
    @ignore_warnings(category=RemovedInDjangoXXWarning)
    def test_foo(self):
        ...
  2. 对于整个测试用例:

    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):
        # invoke deprecated behavior

最后,对 Django 的文档进行了一些更新:

  1. 如果记录了现有功能,请使用 .. deprecated:: A.B 注释在文档中将其标记为已弃用。 如果适用,请包括有关升级路径的简短说明和注释。
  2. 在当前版本说明 (docs/releases/A.B.txt) 的“AB 中弃用的功能”标题下添加对弃用行为的描述和升级路径(如果适用)。
  3. 在相应版本下的弃用时间线 (docs/internals/deprecation.txt) 中添加一个条目,描述将删除哪些代码。

完成这些步骤后,您就完成了弃用。 在每个功能版本中,与新版本匹配的所有RemovedInDjangoXXWarning都被删除。


JavaScript 补丁

有关 JavaScript 补丁的信息,请参阅 JavaScript 补丁 文档。


补丁审查清单

使用此清单检查拉取请求。 如果您正在审查不是您自己的拉取请求并且它通过了以下所有标准,请将相应 Trac 票证上的“分类阶段”设置为“准备签入”。 如果您对拉取请求留下了改进意见,请根据您的审查结果在 Trac 票证上勾选相应的标志:“补丁需要改进”、“需要文档”和/或“需要测试”。 在时间和兴趣允许的情况下,提交者会对“准备签入”票据进行最终审查,如果需要做进一步的工作,他们将提交补丁或将其退回“已接受”。 如果您想成为提交者,对补丁进行彻底审查是赢得信任的好方法。

正在寻找要审查的补丁? 查看 Django 开发仪表板 的“需要审查的补丁”部分。 想要审核您的补丁? 确保设置了票证上的 Trac 标志,以便票证出现在该队列中。

文档

  • 文档构建时是否没有任何错误(make html 或 Windows 上的 make.bat html,来自 docs 目录)?
  • 文档是否遵循 Writing documentation 中的写作风格指南?
  • 是否有任何 拼写错误


错误

  • 是否有适当的回归测试(在应用修复之前测试应该失败)?
  • 如果是 有资格向后移植 到稳定版 Django 的错误,那么 docs/releases/A.B.C.txt 中是否有发行说明? 仅适用于 master 分支的错误修复不需要发行说明。


新功能


弃用功能

请参阅 弃用功能 指南。


所有代码更改

  • 编码风格 是否符合我们的准则? 是否有任何 flake8 错误?
  • 如果更改以任何方式向后不兼容,发行说明 (docs/releases/A.B.txt) 中是否有说明?
  • Django 的测试套件通过了吗?


所有门票

  • 拉取请求是否是单个压缩提交,其消息遵循我们的 提交消息格式
  • 您是补丁作者和新贡献者吗? 请将您自己添加到 AUTHORS 文件中并提交 贡献者许可协议