“Python/docs/3.9/distutils/sourcedist”的版本间差异

来自菜鸟教程
Python/docs/3.9/distutils/sourcedist
跳转至:导航、​搜索
(autoload)
 
(Page commit)
 
第1行: 第1行:
 +
{{DISPLAYTITLE:4. 创建源代码分发 — Python 文档}}
 
<div id="creating-a-source-distribution" class="section">
 
<div id="creating-a-source-distribution" class="section">
  
 
<span id="source-dist"></span>
 
<span id="source-dist"></span>
= <span class="section-number">4. </span>Creating a Source Distribution =
+
= 4. 创建源代码分发 =
  
 
<div class="admonition note">
 
<div class="admonition note">
  
注解
+
笔记
  
This document is being retained solely until the <code>setuptools</code> documentation
+
本文档仅保留到 https://setuptools.readthedocs.io/en/latest/setuptools.html 上的 <code>setuptools</code> 文档独立涵盖当前包含在此处的所有相关信息之前。
at https://setuptools.readthedocs.io/en/latest/setuptools.html
 
independently covers all of the relevant information currently included here.
 
  
  
 
</div>
 
</div>
As shown in section [[../introduction#distutils-simple-example|<span class="std std-ref">A Simple Example</span>]], you use the '''sdist''' command
+
[[../introduction#distutils-simple-example|简单示例]] 部分所示,您可以使用 '''sdist''' 命令创建源分发。 在最简单的情况下,
to create a source distribution. In the simplest case,
 
  
 
<div class="highlight-python3 notranslate">
 
<div class="highlight-python3 notranslate">
第21行: 第19行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>python setup.py sdist</pre>
+
<syntaxhighlight lang="python3">python setup.py sdist</syntaxhighlight>
  
 
</div>
 
</div>
  
 
</div>
 
</div>
(assuming you haven't specified any '''sdist''' options in the setup script
+
(假设您没有在安装脚本或配置文件中指定任何 '''sdist''' 选项),'''sdist''' 会为当前平台创建默认格式的存档。 默认格式在 Unix 上是 gzip 压缩的 tar 文件 (<code>.tar.gz</code>),在 Windows 上是 ZIP 文件。
or config file), '''sdist''' creates the archive of the default format for
 
the current platform. The default format is a gzip'ed tar file
 
(<code>.tar.gz</code>) on Unix, and ZIP file on Windows.
 
  
You can specify as many formats as you like using the <code>--formats</code>
+
您可以使用 <code>--formats</code> 选项指定任意数量的格式,例如:
option, for example:
 
  
 
<div class="highlight-python3 notranslate">
 
<div class="highlight-python3 notranslate">
第38行: 第32行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>python setup.py sdist --formats=gztar,zip</pre>
+
<syntaxhighlight lang="python3">python setup.py sdist --formats=gztar,zip</syntaxhighlight>
  
 
</div>
 
</div>
  
 
</div>
 
</div>
to create a gzipped tarball and a zip file. The available formats are:
+
创建一个 gzip 压缩包和一个 zip 文件。 可用的格式有:
  
 
{|
 
{|
!width="24%"| Format
+
!width="24%"| 格式
!width="56%"| Description
+
!width="56%"| 描述
!width="20%"| Notes
+
!width="20%"| 笔记
 
|-
 
|-
 
| <code>zip</code>
 
| <code>zip</code>
| zip file (<code>.zip</code>)
+
| 压缩文件 (<code>.zip</code>)
 
| (1),(3)
 
| (1),(3)
 
|-
 
|-
 
| <code>gztar</code>
 
| <code>gztar</code>
| gzip'ed tar file
+
| gzip 压缩的 tar 文件 (<code>.tar.gz</code>)
(<code>.tar.gz</code>)
 
 
| (2)
 
| (2)
 
|-
 
|-
 
| <code>bztar</code>
 
| <code>bztar</code>
| bzip2'ed tar file
+
| bzip2'ed tar 文件 (<code>.tar.bz2</code>)
(<code>.tar.bz2</code>)
 
 
|
 
|
 
|-
 
|-
 
| <code>xztar</code>
 
| <code>xztar</code>
| xz'ed tar file
+
| xz'ed tar 文件 (<code>.tar.xz</code>)
(<code>.tar.xz</code>)
 
 
|
 
|
 
|-
 
|-
 
| <code>ztar</code>
 
| <code>ztar</code>
| compressed tar file
+
| 压缩的 tar 文件 (<code>.tar.Z</code>)
(<code>.tar.Z</code>)
 
 
| (4)
 
| (4)
 
|-
 
|-
 
| <code>tar</code>
 
| <code>tar</code>
| tar file (<code>.tar</code>)
+
| tar 文件 (<code>.tar</code>)
 
|
 
|
 
|}
 
|}
第81行: 第71行:
 
<div class="versionchanged">
 
<div class="versionchanged">
  
<span class="versionmodified changed">3.5 版更改: </span>Added support for the <code>xztar</code> format.
+
<span class="versionmodified changed"> 3.5 版更改: </span> 增加了对 <code>xztar</code> 格式的支持。
  
  
 
</div>
 
</div>
Notes:
+
笔记:
  
# default on Windows
+
# Windows 上的默认设置
# default on Unix
+
# Unix 上的默认值
# requires either external '''zip''' utility or [[../../library/zipfile#module-zipfile|<code>zipfile</code>]] module (part of the standard Python library since Python 1.6)
+
# 需要外部 '''zip''' 实用程序或 [[../../library/zipfile#module-zipfile|zipfile]] 模块(自 Python 1.6 起成为标准 Python 库的一部分)
# requires the '''compress''' program. Notice that this format is now pending for deprecation and will be removed in the future versions of Python.
+
# 需要 '''compress''' 程序。 请注意,此格式现在正在等待弃用,并将在 Python 的未来版本中删除。
  
When using any <code>tar</code> format (<code>gztar</code>, <code>bztar</code>, <code>xztar</code>, <code>ztar</code> or
+
当使用任何 <code>tar</code> 格式(<code>gztar</code><code>bztar</code><code>xztar</code><code>ztar</code> <code>tar</code>)时,在 Unix 下你可以指定将为存档的每个成员设置的 <code>owner</code> <code>group</code> 名称。
<code>tar</code>), under Unix you can specify the <code>owner</code> and <code>group</code> names
 
that will be set for each member of the archive.
 
  
For example, if you want all files of the archive to be owned by root:
+
例如,如果您希望存档的所有文件都归根用户所有:
  
 
<div class="highlight-python3 notranslate">
 
<div class="highlight-python3 notranslate">
第102行: 第90行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>python setup.py sdist --owner=root --group=root</pre>
+
<syntaxhighlight lang="python3">python setup.py sdist --owner=root --group=root</syntaxhighlight>
  
 
</div>
 
</div>
第110行: 第98行:
  
 
<span id="manifest"></span>
 
<span id="manifest"></span>
== <span class="section-number">4.1. </span>Specifying the files to distribute ==
+
== 4.1. 指定要分发的文件 ==
  
If you don't supply an explicit list of files (or instructions on how to
+
如果您不提供明确的文件列表(或有关如何生成文件的说明),则 '''sdist''' 命令会将最小的默认设置放入源代码分发版中:
generate one), the '''sdist''' command puts a minimal default set into the
 
source distribution:
 
  
* all Python source files implied by the <code>py_modules</code> and <code>packages</code> options
+
* <code>py_modules</code> <code>packages</code> 选项隐含的所有 Python 源文件
* all C source files mentioned in the <code>ext_modules</code> or <code>libraries</code> options
+
* <code>ext_modules</code> <code>libraries</code> 选项中提到的所有 C 源文件
* scripts identified by the <code>scripts</code> option See [[../setupscript#distutils-installing-scripts|<span class="std std-ref">Installing Scripts</span>]].
+
* <code>scripts</code> 选项标识的脚本 请参阅 [[../setupscript#distutils-installing-scripts|安装脚本]]
* anything that looks like a test script: <code>test/test*.py</code> (currently, the Distutils don't do anything with test scripts except include them in source distributions, but in the future there will be a standard for testing Python module distributions)
+
* 任何看起来像测试脚本的东西:<code>test/test*.py</code>(目前,Distutils 不对测试脚本做任何事情,除了将它们包含在源代码分发中,但将来会有一个用于测试 Python 模块分发的标准)
* Any of the standard README files (<code>README</code>, <code>README.txt</code>, or <code>README.rst</code>), <code>setup.py</code> (or whatever you called your setup script), and <code>setup.cfg</code>.
+
* 任何标准 README 文件(<code>README</code><code>README.txt</code> <code>README.rst</code>)、<code>setup.py</code>(或任何您调用的安装脚本)和 <code>setup.cfg</code>
* all files that matches the <code>package_data</code> metadata. See [[../setupscript#distutils-installing-package-data|<span class="std std-ref">Installing Package Data</span>]].
+
* <code>package_data</code> 元数据匹配的所有文件。 请参阅 [[../setupscript#distutils-installing-package-data|安装包数据]]
* all files that matches the <code>data_files</code> metadata. See [[../setupscript#distutils-additional-files|<span class="std std-ref">Installing Additional Files</span>]].
+
* <code>data_files</code> 元数据匹配的所有文件。 请参阅 [[../setupscript#distutils-additional-files|安装附加文件]]
  
Sometimes this is enough, but usually you will want to specify additional files
+
有时这已经足够了,但通常您需要指定要分发的其他文件。 典型的做法是编写一个''清单模板'',默认名为<code>MANIFEST.in</code>。 清单模板只是一个关于如何生成清单文件的说明列表,<code>MANIFEST</code>,这是要包含在源分发中的文件的确切列表。 '''sdist''' 命令处理这个模板并根据它的指令和它在文件系统中找到的内容生成一个清单。
to distribute. The typical way to do this is to write a ''manifest template'',
 
called <code>MANIFEST.in</code> by default. The manifest template is just a list of
 
instructions for how to generate your manifest file, <code>MANIFEST</code>, which is
 
the exact list of files to include in your source distribution. The
 
'''sdist''' command processes this template and generates a manifest based
 
on its instructions and what it finds in the filesystem.
 
  
If you prefer to roll your own manifest file, the format is simple: one filename
+
如果您更喜欢滚动自己的清单文件,格式很简单:每行一个文件名,只有常规文件(或指向它们的符号链接)。 如果您确实提供自己的 <code>MANIFEST</code>,则必须指定所有内容:上述默认文件集不适用于这种情况。
per line, regular files (or symlinks to them) only. If you do supply your own
 
<code>MANIFEST</code>, you must specify everything: the default set of files
 
described above does not apply in this case.
 
  
 
<div class="versionchanged">
 
<div class="versionchanged">
  
<span class="versionmodified changed">3.1 版更改: </span>An existing generated <code>MANIFEST</code> will be regenerated without
+
<span class="versionmodified changed"> 3.1 版更改: </span> 将重新生成现有生成的 <code>MANIFEST</code>,无需 '''sdist''' 将其修改时间与 <code>MANIFEST.in</code> 或 [ X171X]。
'''sdist''' comparing its modification time to the one of
 
<code>MANIFEST.in</code> or <code>setup.py</code>.
 
  
  
第147行: 第122行:
 
<div class="versionchanged">
 
<div class="versionchanged">
  
<span class="versionmodified changed">在 3.1.3 版更改: </span><code>MANIFEST</code> files start with a comment indicating they are generated.
+
<span class="versionmodified changed">在 3.1.3 版更改:</span><code>MANIFEST</code> 文件以注释开头,表明它们是生成的。 没有此注释的文件不会被覆盖或删除。
Files without this comment are not overwritten or removed.
 
  
  
第154行: 第128行:
 
<div class="versionchanged">
 
<div class="versionchanged">
  
<span class="versionmodified changed">在 3.2.2 版更改: </span>'''sdist''' will read a <code>MANIFEST</code> file if no <code>MANIFEST.in</code>
+
<span class="versionmodified changed"> 在 3.2.2 版更改: </span>'''sdist''' 将读取 <code>MANIFEST</code> 文件,如果 <code>MANIFEST.in</code> 不存在,就像以前一样。
exists, like it used to do.
 
  
  
第161行: 第134行:
 
<div class="versionchanged">
 
<div class="versionchanged">
  
<span class="versionmodified changed">3.7 版更改: </span><code>README.rst</code> is now included in the list of distutils standard READMEs.
+
<span class="versionmodified changed"> 3.7 版更改:</span><code>README.rst</code> 现在包含在 distutils 标准自述文件列表中。
  
  
 
</div>
 
</div>
The manifest template has one command per line, where each command specifies a
+
清单模板每行有一个命令,其中每个命令指定一组要在源分发中包含或排除的文件。 例如,我们再次转向 Distutils 自己的清单模板:
set of files to include or exclude from the source distribution. For an
 
example, again we turn to the Distutils' own manifest template:
 
  
 
<div class="highlight-none notranslate">
 
<div class="highlight-none notranslate">
第173行: 第144行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>include *.txt
+
<pre class="none">include *.txt
 
recursive-include examples *.txt *.py
 
recursive-include examples *.txt *.py
 
prune examples/sample?/build</pre>
 
prune examples/sample?/build</pre>
第180行: 第151行:
  
 
</div>
 
</div>
The meanings should be fairly clear: include all files in the distribution root
+
含义应该相当清楚:包括分发根目录中匹配 <code>*.txt</code> 的所有文件,<code>examples</code> 目录下匹配 <code>*.txt</code> <code>*.py</code> 的所有文件,以及排除所有匹配 <code>examples/sample?/build</code> 的目录。 所有这一切都在 ''标准包含集之后完成'' ,因此您可以使用清单模板中的显式指令从标准集中排除文件。 (或者,您可以使用 <code>--no-defaults</code> 选项完全禁用标准集。)清单模板迷你语言中还有其他几个可用的命令; 请参阅部分 [[../commandref#sdist-cmd|创建源分发:sdist 命令]]
matching <code>*.txt</code>, all files anywhere under the <code>examples</code> directory
 
matching <code>*.txt</code> or <code>*.py</code>, and exclude all directories matching
 
<code>examples/sample?/build</code>. All of this is done ''after'' the standard
 
include set, so you can exclude files from the standard set with explicit
 
instructions in the manifest template. (Or, you can use the
 
<code>--no-defaults</code> option to disable the standard set entirely.) There are
 
several other commands available in the manifest template mini-language; see
 
section [[commandref.html#sdist-cmd|<span class="std std-ref">Creating a source distribution: the sdist command</span>]].
 
  
The order of commands in the manifest template matters: initially, we have the
+
清单模板中的命令顺序很重要:最初,我们有如上所述的默认文件列表,模板中的每个命令都会添加到该文件列表中或从中删除。 一旦我们完全处理了清单模板,我们就会删除不应包含在源代码分发中的文件:
list of default files as described above, and each command in the template adds
 
to or removes from that list of files. Once we have fully processed the
 
manifest template, we remove files that should not be included in the source
 
distribution:
 
  
* all files in the Distutils &quot;build&quot; tree (default <code>build/</code>)
+
* Distutils“构建”树中的所有文件(默认 <code>build/</code>
* all files in directories named <code>RCS</code>, <code>CVS</code>, <code>.svn</code>, <code>.hg</code>, <code>.git</code>, <code>.bzr</code> or <code>_darcs</code>
+
* 名为 <code>RCS</code><code>CVS</code><code>.svn</code><code>.hg</code><code>.git</code><code>.bzr</code> <code>_darcs</code>
  
Now we have our complete list of files, which is written to the manifest for
+
现在我们有了完整的文件列表,将其写入清单以供将来参考,然后用于构建源分发存档。
future reference, and then used to build the source distribution archive(s).
 
  
You can disable the default set of included files with the
+
您可以使用 <code>--no-defaults</code> 选项禁用默认的包含文件集,也可以使用 <code>--no-prune</code> 禁用标准排除集。
<code>--no-defaults</code> option, and you can disable the standard exclude set
 
with <code>--no-prune</code>.
 
  
Following the Distutils' own manifest template, let's trace how the
+
遵循 Distutils 自己的清单模板,让我们跟踪 '''sdist''' 命令如何构建要包含在 Distutils 源代码分发中的文件列表:
'''sdist''' command builds the list of files to include in the Distutils
 
source distribution:
 
  
# include all Python source files in the <code>distutils</code> and <code>distutils/command</code> subdirectories (because packages corresponding to those two directories were mentioned in the <code>packages</code> option in the setup script---see section [[../setupscript#setup-script|<span class="std std-ref">Writing the Setup Script</span>]])
+
# 包括 <code>distutils</code> <code>distutils/command</code> 子目录中的所有 Python 源文件(因为在安装脚本的 <code>packages</code> 选项中提到了对应于这两个目录的包——请参阅 [[../setupscript#setup-script|部分)编写安装脚本]])
# include <code>README.txt</code>, <code>setup.py</code>, and <code>setup.cfg</code> (standard files)
+
# 包括 <code>README.txt</code><code>setup.py</code> <code>setup.cfg</code>(标准文件)
# include <code>test/test*.py</code> (standard files)
+
# 包括 <code>test/test*.py</code>(标准文件)
# include <code>*.txt</code> in the distribution root (this will find <code>README.txt</code> a second time, but such redundancies are weeded out later)
+
# 在分布根目录中包含 <code>*.txt</code>(这将第二次找到 <code>README.txt</code>,但这种冗余稍后会被淘汰)
# include anything matching <code>*.txt</code> or <code>*.py</code> in the sub-tree under <code>examples</code>,
+
# <code>examples</code> 下的子树中包含与 <code>*.txt</code> <code>*.py</code> 匹配的任何内容,
# exclude all files in the sub-trees starting at directories matching <code>examples/sample?/build</code>---this may exclude files included by the previous two steps, so it's important that the <code>prune</code> command in the manifest template comes after the <code>recursive-include</code> command
+
# 排除从匹配 <code>examples/sample?/build</code> 的目录开始的子树中的所有文件——这可能会排除前两个步骤中包含的文件,因此清单模板中的 <code>prune</code> 命令很重要,在 [ X223X] 命令
# exclude the entire <code>build</code> tree, and any <code>RCS</code>, <code>CVS</code>, <code>.svn</code>, <code>.hg</code>, <code>.git</code>, <code>.bzr</code> and <code>_darcs</code> directories
+
# 排除整个 <code>build</code> 树,以及任何 <code>RCS</code><code>CVS</code><code>.svn</code><code>.hg</code><code>.git</code><code>.bzr</code> <code>_darcs</code> 目录
  
Just like in the setup script, file and directory names in the manifest template
+
就像在安装脚本中一样,清单模板中的文件和目录名称应始终以斜杠分隔; Distutils 将负责将它们转换为您平台上的标准表示。 这样,清单模板就可以跨操作系统移植。
should always be slash-separated; the Distutils will take care of converting
 
them to the standard representation on your platform. That way, the manifest
 
template is portable across operating systems.
 
  
  
第228行: 第179行:
  
 
<span id="manifest-options"></span>
 
<span id="manifest-options"></span>
== <span class="section-number">4.2. </span>Manifest-related options ==
+
== 4.2. 清单相关选项 ==
  
The normal course of operations for the '''sdist''' command is as follows:
+
'''sdist'''命令的正常操作过程如下:
  
* if the manifest file (<code>MANIFEST</code> by default) exists and the first line does not have a comment indicating it is generated from <code>MANIFEST.in</code>, then it is used as is, unaltered
+
* 如果清单文件(默认情况下为 <code>MANIFEST</code>)存在并且第一行没有注释表明它是从 <code>MANIFEST.in</code> 生成的,则按原样使用,未更改
* if the manifest file doesn't exist or has been previously automatically generated, read <code>MANIFEST.in</code> and create the manifest
+
* 如果清单文件不存在或之前已自动生成,请阅读 <code>MANIFEST.in</code> 并创建清单
* if neither <code>MANIFEST</code> nor <code>MANIFEST.in</code> exist, create a manifest with just the default file set
+
* 如果 <code>MANIFEST</code> <code>MANIFEST.in</code> 都不存在,则创建一个仅包含默认文件集的清单
* use the list of files now in <code>MANIFEST</code> (either just generated or read in) to create the source distribution archive(s)
+
* 现在使用 <code>MANIFEST</code> 中的文件列表(刚刚生成或读入)来创建源分发存档
  
There are a couple of options that modify this behaviour. First, use the
+
有几个选项可以修改此行为。 首先,使用 <code>--no-defaults</code> <code>--no-prune</code> 禁用标准的“包含”和“排除”集。
<code>--no-defaults</code> and <code>--no-prune</code> to disable the standard
 
&quot;include&quot; and &quot;exclude&quot; sets.
 
  
Second, you might just want to (re)generate the manifest, but not create a source
+
其次,您可能只想(重新)生成清单,而不是创建源分发:
distribution:
 
  
 
<div class="highlight-python3 notranslate">
 
<div class="highlight-python3 notranslate">
第248行: 第196行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>python setup.py sdist --manifest-only</pre>
+
<syntaxhighlight lang="python3">python setup.py sdist --manifest-only</syntaxhighlight>
  
 
</div>
 
</div>
  
 
</div>
 
</div>
<code>-o</code> is a shortcut for <code>--manifest-only</code>.
+
<code>-o</code> <code>--manifest-only</code> 的快捷方式。
  
  
第259行: 第207行:
  
 
</div>
 
</div>
 +
<div class="clearer">
  
[[Category:Python 3.9 中文文档]]
+
 
 +
 
 +
</div>
 +
 
 +
[[Category:Python 3.9 文档]]

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

4. 创建源代码分发

笔记

本文档仅保留到 https://setuptools.readthedocs.io/en/latest/setuptools.html 上的 setuptools 文档独立涵盖当前包含在此处的所有相关信息之前。


简单示例 部分所示,您可以使用 sdist 命令创建源分发。 在最简单的情况下,

python setup.py sdist

(假设您没有在安装脚本或配置文件中指定任何 sdist 选项),sdist 会为当前平台创建默认格式的存档。 默认格式在 Unix 上是 gzip 压缩的 tar 文件 (.tar.gz),在 Windows 上是 ZIP 文件。

您可以使用 --formats 选项指定任意数量的格式,例如:

python setup.py sdist --formats=gztar,zip

创建一个 gzip 压缩包和一个 zip 文件。 可用的格式有:

格式 描述 笔记
zip 压缩文件 (.zip) (1),(3)
gztar gzip 压缩的 tar 文件 (.tar.gz) (2)
bztar bzip2'ed tar 文件 (.tar.bz2)
xztar xz'ed tar 文件 (.tar.xz)
ztar 压缩的 tar 文件 (.tar.Z) (4)
tar tar 文件 (.tar)

3.5 版更改: 增加了对 xztar 格式的支持。


笔记:

  1. Windows 上的默认设置
  2. Unix 上的默认值
  3. 需要外部 zip 实用程序或 zipfile 模块(自 Python 1.6 起成为标准 Python 库的一部分)
  4. 需要 compress 程序。 请注意,此格式现在正在等待弃用,并将在 Python 的未来版本中删除。

当使用任何 tar 格式(gztarbztarxztarztartar)时,在 Unix 下你可以指定将为存档的每个成员设置的 ownergroup 名称。

例如,如果您希望存档的所有文件都归根用户所有:

python setup.py sdist --owner=root --group=root

4.1. 指定要分发的文件

如果您不提供明确的文件列表(或有关如何生成文件的说明),则 sdist 命令会将最小的默认设置放入源代码分发版中:

  • py_modulespackages 选项隐含的所有 Python 源文件
  • ext_moduleslibraries 选项中提到的所有 C 源文件
  • scripts 选项标识的脚本 请参阅 安装脚本
  • 任何看起来像测试脚本的东西:test/test*.py(目前,Distutils 不对测试脚本做任何事情,除了将它们包含在源代码分发中,但将来会有一个用于测试 Python 模块分发的标准)
  • 任何标准 README 文件(READMEREADME.txtREADME.rst)、setup.py(或任何您调用的安装脚本)和 setup.cfg
  • package_data 元数据匹配的所有文件。 请参阅 安装包数据
  • data_files 元数据匹配的所有文件。 请参阅 安装附加文件

有时这已经足够了,但通常您需要指定要分发的其他文件。 典型的做法是编写一个清单模板,默认名为MANIFEST.in。 清单模板只是一个关于如何生成清单文件的说明列表,MANIFEST,这是要包含在源分发中的文件的确切列表。 sdist 命令处理这个模板并根据它的指令和它在文件系统中找到的内容生成一个清单。

如果您更喜欢滚动自己的清单文件,格式很简单:每行一个文件名,只有常规文件(或指向它们的符号链接)。 如果您确实提供自己的 MANIFEST,则必须指定所有内容:上述默认文件集不适用于这种情况。

3.1 版更改: 将重新生成现有生成的 MANIFEST,无需 sdist 将其修改时间与 MANIFEST.in 或 [ X171X]。


在 3.1.3 版更改:MANIFEST 文件以注释开头,表明它们是生成的。 没有此注释的文件不会被覆盖或删除。


在 3.2.2 版更改: sdist 将读取 MANIFEST 文件,如果 MANIFEST.in 不存在,就像以前一样。


3.7 版更改:README.rst 现在包含在 distutils 标准自述文件列表中。


清单模板每行有一个命令,其中每个命令指定一组要在源分发中包含或排除的文件。 例如,我们再次转向 Distutils 自己的清单模板:

include *.txt
recursive-include examples *.txt *.py
prune examples/sample?/build

含义应该相当清楚:包括分发根目录中匹配 *.txt 的所有文件,examples 目录下匹配 *.txt*.py 的所有文件,以及排除所有匹配 examples/sample?/build 的目录。 所有这一切都在 标准包含集之后完成 ,因此您可以使用清单模板中的显式指令从标准集中排除文件。 (或者,您可以使用 --no-defaults 选项完全禁用标准集。)清单模板迷你语言中还有其他几个可用的命令; 请参阅部分 创建源分发:sdist 命令

清单模板中的命令顺序很重要:最初,我们有如上所述的默认文件列表,模板中的每个命令都会添加到该文件列表中或从中删除。 一旦我们完全处理了清单模板,我们就会删除不应包含在源代码分发中的文件:

  • Distutils“构建”树中的所有文件(默认 build/
  • 名为 RCSCVS.svn.hg.git.bzr_darcs

现在我们有了完整的文件列表,将其写入清单以供将来参考,然后用于构建源分发存档。

您可以使用 --no-defaults 选项禁用默认的包含文件集,也可以使用 --no-prune 禁用标准排除集。

遵循 Distutils 自己的清单模板,让我们跟踪 sdist 命令如何构建要包含在 Distutils 源代码分发中的文件列表:

  1. 包括 distutilsdistutils/command 子目录中的所有 Python 源文件(因为在安装脚本的 packages 选项中提到了对应于这两个目录的包——请参阅 部分)编写安装脚本)
  2. 包括 README.txtsetup.pysetup.cfg(标准文件)
  3. 包括 test/test*.py(标准文件)
  4. 在分布根目录中包含 *.txt(这将第二次找到 README.txt,但这种冗余稍后会被淘汰)
  5. examples 下的子树中包含与 *.txt*.py 匹配的任何内容,
  6. 排除从匹配 examples/sample?/build 的目录开始的子树中的所有文件——这可能会排除前两个步骤中包含的文件,因此清单模板中的 prune 命令很重要,在 [ X223X] 命令
  7. 排除整个 build 树,以及任何 RCSCVS.svn.hg.git.bzr_darcs 目录

就像在安装脚本中一样,清单模板中的文件和目录名称应始终以斜杠分隔; Distutils 将负责将它们转换为您平台上的标准表示。 这样,清单模板就可以跨操作系统移植。