开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
捐赠
捐赠前请先登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
1 Star 0 Fork 0

source-code-analysis/python3.7.4

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (1)
master
master
分支 (1)
master
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (1)
master
python3.7.4
/
Doc
/
distutils
/
sourcedist.rst
python3.7.4
/
Doc
/
distutils
/
sourcedist.rst
sourcedist.rst 9.47 KB
一键复制 编辑 原始数据 按行查看 历史
zhangweibo 提交于 2021年11月17日 13:49 +08:00 . git init

Creating a Source Distribution

As shown in section :ref:`distutils-simple-example`, you use the :command:`sdist` command to create a source distribution. In the simplest case,

python setup.py sdist

(assuming you haven't specified any :command:`sdist` options in the setup script or config file), :command:`sdist` creates the archive of the default format for the current platform. The default format is a gzip'ed tar file (:file:`.tar.gz`) on Unix, and ZIP file on Windows.

You can specify as many formats as you like using the :option:`!--formats` option, for example:

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

to create a gzipped tarball and a zip file. The available formats are:

Format Description Notes
zip zip file (:file:`.zip`) (1),(3)
gztar gzip'ed tar file (:file:`.tar.gz`) (2)
bztar bzip2'ed tar file (:file:`.tar.bz2`)
xztar xz'ed tar file (:file:`.tar.xz`)
ztar compressed tar file (:file:`.tar.Z`) (4)
tar tar file (:file:`.tar`)
.. versionchanged:: 3.5
 Added support for the ``xztar`` format.

Notes:

  1. default on Windows
  2. default on Unix
  3. requires either external :program:`zip` utility or :mod:`zipfile` module (part of the standard Python library since Python 1.6)
  4. requires the :program:`compress` program. Notice that this format is now pending for deprecation and will be removed in the future versions of Python.

When using any tar format (gztar, bztar, xztar, ztar or tar), under Unix you can specify the owner and group 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:

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

Specifying the files to distribute

If you don't supply an explicit list of files (or instructions on how to generate one), the :command:`sdist` command puts a minimal default set into the source distribution:

Sometimes this is enough, but usually you will want to specify additional files to distribute. The typical way to do this is to write a manifest template, called :file:`MANIFEST.in` by default. The manifest template is just a list of instructions for how to generate your manifest file, :file:`MANIFEST`, which is the exact list of files to include in your source distribution. The :command:`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 per line, regular files (or symlinks to them) only. If you do supply your own :file:`MANIFEST`, you must specify everything: the default set of files described above does not apply in this case.

.. versionchanged:: 3.1
 An existing generated :file:`MANIFEST` will be regenerated without
 :command:`sdist` comparing its modification time to the one of
 :file:`MANIFEST.in` or :file:`setup.py`.

.. versionchanged:: 3.1.3
 :file:`MANIFEST` files start with a comment indicating they are generated.
 Files without this comment are not overwritten or removed.

.. versionchanged:: 3.2.2
 :command:`sdist` will read a :file:`MANIFEST` file if no :file:`MANIFEST.in`
 exists, like it used to do.

.. versionchanged:: 3.7
 :file:`README.rst` is now included in the list of distutils standard READMEs.


The manifest template has one command per line, where each command specifies a set of files to include or exclude from the source distribution. For an example, again we turn to the Distutils' own manifest template:

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

The meanings should be fairly clear: include all files in the distribution root matching :file:`\*.txt`, all files anywhere under the :file:`examples` directory matching :file:`\*.txt` or :file:`\*.py`, and exclude all directories matching :file:`examples/sample?/build`. 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 :option:`!--no-defaults` option to disable the standard set entirely.) There are several other commands available in the manifest template mini-language; see section :ref:`sdist-cmd`.

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:

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 :option:`!--no-defaults` option, and you can disable the standard exclude set with :option:`!--no-prune`.

Following the Distutils' own manifest template, let's trace how the :command:`sdist` command builds the list of files to include in the Distutils source distribution:

  1. include all Python source files in the :file:`distutils` and :file:`distutils/command` subdirectories (because packages corresponding to those two directories were mentioned in the packages option in the setup script---see section :ref:`setup-script`)
  2. include :file:`README.txt`, :file:`setup.py`, and :file:`setup.cfg` (standard files)
  3. include :file:`test/test\*.py` (standard files)
  4. include :file:`\*.txt` in the distribution root (this will find :file:`README.txt` a second time, but such redundancies are weeded out later)
  5. include anything matching :file:`\*.txt` or :file:`\*.py` in the sub-tree under :file:`examples`,
  6. exclude all files in the sub-trees starting at directories matching :file:`examples/sample?/build`---this may exclude files included by the previous two steps, so it's important that the prune command in the manifest template comes after the recursive-include command
  7. exclude the entire :file:`build` tree, and any :file:`RCS`, :file:`CVS`, :file:`.svn`, :file:`.hg`, :file:`.git`, :file:`.bzr` and :file:`_darcs` directories

Just like in the setup script, file and directory names in the manifest template 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.

Manifest-related options

The normal course of operations for the :command:`sdist` command is as follows:

  • if the manifest file (:file:`MANIFEST` by default) exists and the first line does not have a comment indicating it is generated from :file:`MANIFEST.in`, then it is used as is, unaltered
  • if the manifest file doesn't exist or has been previously automatically generated, read :file:`MANIFEST.in` and create the manifest
  • if neither :file:`MANIFEST` nor :file:`MANIFEST.in` exist, create a manifest with just the default file set
  • use the list of files now in :file:`MANIFEST` (either just generated or read in) to create the source distribution archive(s)

There are a couple of options that modify this behaviour. First, use the :option:`!--no-defaults` and :option:`!--no-prune` to disable the standard "include" and "exclude" sets.

Second, you might just want to (re)generate the manifest, but not create a source distribution:

python setup.py sdist --manifest-only

:option:`!-o` is a shortcut for :option:`!--manifest-only`.

Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

暂无描述
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/python_sourcecode/python3.7.4.git
git@gitee.com:python_sourcecode/python3.7.4.git
python_sourcecode
python3.7.4
python3.7.4
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /