简体   繁体   English

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

[英]Tox can't copy non-python file while installing the module

This is the tree structure of the module I'm writing the setup.py file for: 这是我正在编写setup.py文件的模块的树结构:

ls .

LICENSE
README.md
bin
examples
module
scratch
setup.py
tests
tox.ini

I configured my setup.py as follows: 我配置我的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.
)

If I install the package from my python environment (also a virtualenv) 如果我从我的python环境安装包(也是virtualenv)

pip install .

the LICENSE file gets correctly installed. LICENSE文件已正确安装。

But running tox : 但是运行tox

[tox]
envlist = py27, py35

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

commands = py.test \
    {posargs}

I get this error: 我收到此错误:

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

Removing the data_files part from the setup.py makes tox running correctly. 从setup.py中删除data_files部分使得tox正常运行。

Your issue here is that setuptools is not able to find the 'LICENSE' file in the files that have been included for building the source distribution. 您的问题是setuptools无法在为构建源代码分发而包含的文件中找到“LICENSE”文件。 You have 2 options, to tell setuptools to include that file (both have been pointed to here): 你有2个选项,告诉setuptools包含该文件(两者都在这里指出):

Using MANIFEST.in is often simpler and easier to verify due to https://pypi.org/project/check-manifest/ , making it possible to use automation to verify that things are indeed correct (if you use a VCS like Git or SVN). 由于https://pypi.org/project/check-manifest/ ,使用MANIFEST.in通常更简单,更容易验证,因此可以使用自动化来验证事情确实是正确的(如果您使用像Git这样的VCS或SVN)。


pip install . builds a wheel using python setup.py bdist_wheel which is installed by simply unpacking it appropriately, as defined in the Wheel Specification: https://www.python.org/dev/peps/pep-0427/ 使用python setup.py bdist_wheel构建一个轮子,通过简单地解python setup.py bdist_wheel它来安装,如轮规范中所定义: httpspython setup.py bdist_wheel

tox builds a source distribution using python setup.py sdist , which is then unpacked and installed using python setup.py install . tox使用python setup.py sdist构建源代码分发,然后使用python setup.py install解压缩并python setup.py install

That might be a reason for the difference in behavior for you. 这可能是您行为不同的原因。

I have some resource files inside my packages which I use during the execution. 我在我的包中有一些资源文件,我在执行期间使用它们。 To make setup store them in a package with python code, I use include_package_data=True and I access them using importlib.resources . 为了使安装程序将它们存储在包含python代码的包中,我使用include_package_data=True并使用importlib.resources访问它们。 You can use backport for an older Python version than 3.7 or another library. 您可以将backport用于比3.7更旧的Python版本或其他库。

Before each release I have a script which verifies, that all files I need are placed inside a bdist wheel to be sure that everything is on the place. 在每次发布之前,我都有一个脚本来验证,我需要的所有文件都放在一个bdist轮中,以确保一切都在这个地方。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM