8

This is the tree structure of the module I'm writing the setup.py file for:

ls .

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

I configured my setup.py as follows:

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)

pip install .

the LICENSE file gets correctly installed.

But running 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.

rdbisme
  • 850
  • 1
  • 13
  • 39
  • Could you try to run `python setup.py install` and see what will happen? As far as I remember `pip install .` works the same as `python setup.py develop` and tox uses `install` command. – Eir Nym Oct 21 '18 at 01:45
  • What operating system is this run on (for the bounty)? – wallyk Oct 21 '18 at 01:51

2 Answers2

9

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. You have 2 options, to tell setuptools to include that file (both have been pointed to here):

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).


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/

tox builds a source distribution using python setup.py sdist, which is then unpacked and installed using python setup.py install.

That might be a reason for the difference in behavior for you.

pradyunsg
  • 18,287
  • 11
  • 43
  • 96
0

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. You can use backport for an older Python version than 3.7 or another library.

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.

Eir Nym
  • 1,515
  • 19
  • 30