如何在没有MANIFEST.in文件的情况下包含package_data?

时间:2021-01-22 17:41:53

How can I include package_data for sdist without a MANIFEST.in file?

如何在没有MANIFEST.in文件的情况下为sdist包含package_data?

My setup.py looks like this:

我的setup.py看起来像这样:

import setuptools

setuptools.setup(
    name='foo',
    version='2015.3',
    license='commercial',
    packages=setuptools.find_packages(),

    package_data={'': ['foo/bar.txt']},
)

Versions:

版本:

user@host> python
Python 2.7.6 (default, Mar 22 2014, 22:59:56) 
>>> import setuptools
>>> setuptools.version.__version__
'3.6'

I just can't get foo/bar.txt included.

我只是不能得到foo / bar.txt。

Or is this blog post still true? http://blog.codekills.net/2011/07/15/lies,-more-lies-and-python-packaging-documentation-on--package_data-/

或者这篇博文仍然是真的吗? http://blog.codekills.net/2011/07/15/lies,-more-lies-and-python-packaging-documentation-on--package_data-/

Over the last hour, though, I've learned that these statements are somewhere between “dangerously misleading” and “damn lies”. This is because the primary type of Python package is a source package, and the canonical method for creating a source package is by using setup.py sdist. However, the data specified in package_data are not included in source distributions — they are only included in binary (setup.py bdist) distributions and installs (setup.py install).

然而,在过去的一小时里,我了解到这些陈述介于“危险的误导”和“该死的谎言”之间。这是因为Python包的主要类型是源包,而创建源包的规范方法是使用setup.py sdist。但是,package_data中指定的数据不包含在源代码分发中 - 它们仅包含在二进制(setup.py bdist)分发和安装(setup.py install)中。

How can I include package_data for sdist without a MANIFEST.in file?

如何在没有MANIFEST.in文件的情况下为sdist包含package_data?

2 个解决方案

#1


27  

TL;DR: The keys in the package_data dictionaries are packages; the values are lists of globs. '' is not a valid name for any Python package.

TL; DR:package_data词典中的键是包;值是globs列表。 ''不是任何Python包的有效名称。

If you want to have bar.txt be installed next to the __init__.py of package foo, use

如果你想在包foo的__init__.py旁边安装bar.txt,请使用

 package_data={'foo': ['bar.txt']}

I have the layout:

我有布局:

foo/
        __init__.py
        bar.txt
setup.py

Now, if foo is a package like above, do:

现在,如果foo是上面的包,请执行:

import setuptools

setuptools.setup(
    name='foo',
    version='2015.3',
    license='commercial',
    packages=setuptools.find_packages(),
    package_data={'foo': ['bar.txt']},
)

And after python setup.py sdist, I check the contents of dist/foo-2015.3.tar.gz

在python setup.py sdist之后,我查看了dist / foo-2015.3.tar.gz的内容

% tar tfz dist/foo-2015.3.tar.gz
...
foo-2015.3/foo/bar.txt
...

However, if I run your setup.py with package_data={'': ['foo/bar.txt']}, I can concur that the foo/bar.txt will not be added to the source distribution, except if the foo-2015.3.egg-info/SOURCES.txt already has the line for foo/bar.txt - in that case the file will pop up in the source distribution too

但是,如果我使用package_data = {'':['foo / bar.txt']}运行你的setup.py,我可以同意foo / bar.txt不会添加到源代码发布中,除非foo -2015.3.egg-info / SOURCES.txt已经有foo / bar.txt的行 - 在这种情况下,该文件也将在源代码发行版中弹出

No manifest was used; the setuptools version was 3.6 (I deliberately installed the same, old version that you were using):

没有使用清单; setuptools版本是3.6(我故意安装了你正在使用的旧版本):

>>> import setuptools
>>> setuptools.__version__
'3.6'

The behaviour above also works in standard distutils: 2.6 Installing package data of the "legacy" distutils documentation; with a comment for 2.7, 3.1:

上述行为也适用于标准distutils:2.6安装“legacy”distutils文档的包数据;评论为2.7,3.1:

Changed in version [2.7, 3.1]: All the files that match package_data will be added to the MANIFEST file if no template is provided.

在版本[2.7,3.1]中更改:如果未提供模板,则所有与package_data匹配的文件将添加到MANIFEST文件中。

#2


6  

I had the same issue and fixed it be removing :

我有同样的问题,并修复它删除:

include_package_data=True

#1


27  

TL;DR: The keys in the package_data dictionaries are packages; the values are lists of globs. '' is not a valid name for any Python package.

TL; DR:package_data词典中的键是包;值是globs列表。 ''不是任何Python包的有效名称。

If you want to have bar.txt be installed next to the __init__.py of package foo, use

如果你想在包foo的__init__.py旁边安装bar.txt,请使用

 package_data={'foo': ['bar.txt']}

I have the layout:

我有布局:

foo/
        __init__.py
        bar.txt
setup.py

Now, if foo is a package like above, do:

现在,如果foo是上面的包,请执行:

import setuptools

setuptools.setup(
    name='foo',
    version='2015.3',
    license='commercial',
    packages=setuptools.find_packages(),
    package_data={'foo': ['bar.txt']},
)

And after python setup.py sdist, I check the contents of dist/foo-2015.3.tar.gz

在python setup.py sdist之后,我查看了dist / foo-2015.3.tar.gz的内容

% tar tfz dist/foo-2015.3.tar.gz
...
foo-2015.3/foo/bar.txt
...

However, if I run your setup.py with package_data={'': ['foo/bar.txt']}, I can concur that the foo/bar.txt will not be added to the source distribution, except if the foo-2015.3.egg-info/SOURCES.txt already has the line for foo/bar.txt - in that case the file will pop up in the source distribution too

但是,如果我使用package_data = {'':['foo / bar.txt']}运行你的setup.py,我可以同意foo / bar.txt不会添加到源代码发布中,除非foo -2015.3.egg-info / SOURCES.txt已经有foo / bar.txt的行 - 在这种情况下,该文件也将在源代码发行版中弹出

No manifest was used; the setuptools version was 3.6 (I deliberately installed the same, old version that you were using):

没有使用清单; setuptools版本是3.6(我故意安装了你正在使用的旧版本):

>>> import setuptools
>>> setuptools.__version__
'3.6'

The behaviour above also works in standard distutils: 2.6 Installing package data of the "legacy" distutils documentation; with a comment for 2.7, 3.1:

上述行为也适用于标准distutils:2.6安装“legacy”distutils文档的包数据;评论为2.7,3.1:

Changed in version [2.7, 3.1]: All the files that match package_data will be added to the MANIFEST file if no template is provided.

在版本[2.7,3.1]中更改:如果未提供模板,则所有与package_data匹配的文件将添加到MANIFEST文件中。

#2


6  

I had the same issue and fixed it be removing :

我有同样的问题,并修复它删除:

include_package_data=True