python项目需要MANIFEST.in吗,里面应该有什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24727709/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 05:04:59  来源:igfitidea点击:

Do python projects need a MANIFEST.in, and what should be in it?

pythonsetuptools

提问by Neil Walker

The "Python Distribute" guide (was at python-distribute.org, but that registration has lapsed) tells me to include doc/txtfiles and .pyfiles are excluded in MANIFEST.infile

“Python 分发”指南(位于 python-distribute.org,但注册已失效)告诉我要包含doc/txt文件,并且.py文件被排除在MANIFEST.in文件中

The sourcedist documentationtells me only sdist uses MANIFEST.inand only includes file you specify and to include .pyfiles. It also tells me to use: python setup.py sdist --manifest-onlyto generate a MANIFEST, but python tells me this doesn't exist

sourcedist文档告诉我只有sdist用途MANIFEST.in,并只包括文件指定和包含.py文件。它还告诉我使用:python setup.py sdist --manifest-only生成一个MANIFEST,但是python告诉我这不存在

I appreciate these are from different versions of python and the distribution system is in a complete mess, but assuming I am using python 3 and setuptools(the new one that includes distribute but now called setuptools, not the old setuptools that was deprecated for distribute tools only to be brought back into distribute and distribute renamed to setuptools.....)

我很欣赏这些来自不同版本的 python 并且分发系统一团糟,但假设我使用的是 python 3 和setuptools(包括分发但现在称为 setuptools 的新版本,而不是旧的 setuptools,它已弃用仅用于分发工具重新分配并分发重命名为 setuptools .....)

and I'm following the 'standard' folder structure and setup.pyfile,

我遵循“标准”文件夹结构和setup.py文件,

  1. Do I need a MANIFEST.in?
  2. What should be in it ?
  3. When will all these different package systems and methods be made into one single simple process ?
  1. 我需要MANIFEST.in吗?
  2. 里面应该有什么?
  3. 什么时候将所有这些不同的包装系统和方法整合到一个简单的过程中?

采纳答案by Jan Vlcinsky

Re: "Do I need a MANIFEST.in?

回复:“我需要 MANIFEST.in 吗?

No, you do not have to use MANIFEST.in. Both, distutilsand setuptoolsare including in source distribution package all the files mentioned in setup.py- modules, package python files, README.txtand test/test*.py. If this is all you want to have in distribution package, you do not have to use MANIFEST.in.

不,您不必使用MANIFEST.in. 两者,distutils并且setuptools被包括在源分发包中提到的所有文件setup.py-的模块,包Python文件, README.txttest/test*.py。如果这是您希望在分发包中拥有的全部内容,则不必使用MANIFEST.in.

If you want to manipulate (add or remove) default files to include, you have to use MANIFEST.in.

如果要操作(添加或删除)要包含的默认文件,则必须使用MANIFEST.in.

Re: What should be in it?

回复:里面应该有什么?

The procedure is simple:

程序很简单:

  1. Make sure, in your setup.pyyou include (by means of setuparguments) all the files you feel important for the program to run (modules, packages, scripts ...)

  2. Clarify, if there are some files to add or some files to exclude. If neither is needed, then there is no need for using MANIFEST.in.

  3. If MANIFEST.inis needed, create it. Usually, you add there tests*/*.pyfiles, README.rstif you do not use README.txt, docsfiles and possibly some data files for test suite, if necessary.

  1. 确保在你的文件中setup.py包含(通过setup参数)你认为对程序运行很重要的所有文件(模块、包、脚本......)

  2. 澄清,如果有一些文件要添加或一些文件要排除。如果两者都不需要,则不需要使用MANIFEST.in.

  3. 如果MANIFEST.in需要,创建它。通常,您会在那里添加tests*/*.py文件,README.rst如果您不使用README.txt,docs文件和可能的测试套件的一些数据文件,如有必要。

For example:

例如:

include README.rst
include COPYING.txt

To test it, run python setup.py sdist, and examine the tarball created under dist/.

要测试它,请运行python setup.py sdist并检查在 下创建的 tarball dist/

When will all these different package systems ...

所有这些不同的包装系统何时会...

Comparing the situation today and 2 years ago - the situation is much much better - setuptoolsis the way to go. You can ignore the fact, distutilsis a bit broken and is low level base for setuptoolsas setuptoolsshall take care of hiding these things from you.

比较今天和两年前的情况——情况要好得多——setuptools是要走的路。你可以忽略这个事实,distutils它有点破碎并且是低级别的基础,setuptools因为setuptools应该照顾向你隐藏这些东西。

EDIT: Last few projects I use pbrfor building distribution packages with three line setup.pyand rest being in setup.cfgand requirements.txt. No need to care about MANIFEST.inand other strange stuff. Even though the package would deserve a bit more documentation. See http://docs.openstack.org/developer/pbr/

编辑:我pbr用于构建具有三行的分发包的最后几个项目setup.py,其余在setup.cfg和 中requirements.txt。无需关心MANIFEST.in和其他奇怪的东西。即使这个包应该得到更多的文档。请参阅http://docs.openstack.org/developer/pbr/

回答by Klaas van Schelven

Old question, new answer:

老问题,新答案:

No, you don't need MANIFEST.in. However, to get setuptoolsto do what you (usually) mean, you do need to use the setuptools_scm, which takes the role of MANIFEST.inin 2 key places:

不,你不需要MANIFEST.in。但是,要setuptools完成您(通常)的意思,您确实需要使用setuptools_scm,它MANIFEST.in在两个关键位置发挥作用:

  • It ensures all relevant files are packaged when running the sdistcommand (where all relevant files is defined as "all files under source control")
  • When using include_package_datato include package data as part of the buildor bdist_wheel. (again: files under source control)
  • 它确保在运行sdist命令时打包所有相关文件(其中所有相关文件被定义为“源代码控制下的所有文件”)
  • include_package_data用于将包数据包含为buildor 的一部分时bdist_wheel。(再次:源代码控制下的文件)

The historical understanding of MANIFEST.inis: when you don't have a source control system, you need some other mechanism to distinguish between "source files" and "files that happen to be in your working directory". However, your project is under source control (right??) so there's no need for MANIFEST.in. More info in this article.

历史上的理解MANIFEST.in是:当你没有源代码控制系统时,你需要一些其他的机制来区分“源文件”和“碰巧在你工作目录中的文件”。但是,您的项目受源代码控制(对吗??),因此不需要MANIFEST.in. 这篇文章中有更多信息