Tox 安装模块时无法复制非 python 文件

DiT*_*TiD 5 python setuptools tox

这是我正在setup.py为其编写文件的模块的树结构:

ls .

LICENSE
README.md
bin
examples
module
scratch
setup.py
tests
tox.ini
Run Code Online (Sandbox Code Playgroud)

我的配置setup.py如下:

from setuptools import setup, find_packages

setup(
    name="package_name",
    version="0.1",
    packages=find_packages(),

    install_requires=[
        # [...]
    ],

    extras_require={
        # [...]

    },

    tests_require={
        'pytest',
        'doctest'
    },

    scripts=['bin/bootstrap'],

     data_files=[
        ('license', ['LICENSE']),
     ],

    # [...]
    # could also include long_description, download_url, classifiers, etc.
)
Run Code Online (Sandbox Code Playgroud)

如果我从我的 python 环境(也是一个 virtualenv)安装包

pip install .
Run Code Online (Sandbox Code Playgroud)

LICENSE文件被正确安装。

但是运行tox

[tox]
envlist = py27, py35

[testenv]
deps = 
    pytest
    git+https://github.com/djc/couchdb-python
    docopt

commands = py.test \
    {posargs}
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

running install_data
  creating build/bdist.macosx-10.11-x86_64/wheel/leafline-0.1.data
  creating build/bdist.macosx-10.11-x86_64/wheel/leafline-0.1.data/data
  creating build/bdist.macosx-10.11-x86_64/wheel/leafline-0.1.data/data/license
  error: can't copy 'LICENSE': doesn't exist or not a regular file
Run Code Online (Sandbox Code Playgroud)

data_files从 setup.py 中删除部分可以tox正确运行。

pra*_*nsg 6

您的问题是 setuptools 无法在用于构建源分发的文件中找到“许可证”文件。您有 2 个选项,可以告诉 setuptools 包含该文件(都已在此处指出):

MANIFEST.in由于https://pypi.org/project/check-manifest/,使用通常更简单,更容易验证,从而可以使用自动化来验证事情确实正确(如果您使用像 Git 或 SVN 这样的 VCS)。


pip install .使用python setup.py bdist_wheel它构建一个轮子,通过简单地将它适当地拆包来安装,如轮子规范中所定义:https : //www.python.org/dev/peps/pep-0427/

tox使用 构建源分发python setup.py sdist,然后使用 解压缩和安装python setup.py install

这可能是您行为差异的原因。


Eir*_*Nym 0

我的包中有一些在执行过程中使用的资源文件。为了让安装程序将它们存储在带有 python 代码的包中,我使用include_package_data=True并使用importlib.resources. 您可以对 3.7 之前的 Python 版本或其他库使用向后移植。

在每次发布之前,我都有一个脚本来验证我需要的所有文件是否都放置在bdist轮子内,以确保所有内容都就位。