views:

107

answers:

2

Let's take the following project layout:

$ ls -R .
.:
package  setup.py

./package:
__init__.py  dir  file.dat  module.py

./package/dir:
tool1.dat  tool2.dat

And the following content for setup.py:

$ cat setup.py 
from distutils.core import setup


setup(name='pyproj',
      version='0.1',

      packages=[
          'package',
      ],
      package_data={
          'package': [
              '*',
              'dir/*',
          ],
      },
     )

As you can see, I want to include all non-Python files in package/ and package/dir/ directories. However, running setup.py install would raise the following error:

$ python setup.py install
running install
running build
running build_py
creating build
creating build/lib
creating build/lib/package
copying package/module.py -> build/lib/package
copying package/__init__.py -> build/lib/package
error: can't copy 'package/dir': doesn't exist or not a regular file

What gives?

+1  A: 

In your package_data, your '*' glob will match package/dir itself, and try to copy that dir as a file, resulting in a failure. Find a glob that won't match the directory package/dir, rewriting your setup.py along these lines:

from distutils.core import setup

setup(name='pyproj',
      version='0.1',

      packages=[
          'package',
      ],
      package_data={
          'package': [
              '*.dat',
              'dir/*'
          ],
      },
     )

Given your example, that's just changing '*' to '*.dat', although you'd probably need to refine your glob more than that, just ensure it won't match 'dir'

Jacob Oscarson
Ah. Thanks. Do you know if there's a more elegant way in specifying "include everything, recursively, in this package (on top of the modules)"?
Santa
You might get away by using a MANIFEST.in file, but it's unfortunately more difficult than ideal (as this search http://www.google.se/search?q=distutils+package_data+include+directory shows, a lot of people are asking this question, and not many get answers). The most comprehensive doc is this: http://docs.python.org/distutils/setupscript.html , but it's not very clearly written (to find your problem, I actually pdb'd into distutils source)
Jacob Oscarson
A: 

I am having the "not a regular file" issue with a -very- simple setup.py. There are no wildcards anywhere. What is not regular?

from distutils.core import setup

setup(
    name='xlsexport',
    version='0.3',

    py_modules=['xlsexport']
    )

$ uname -a
CYGWIN_NT-6.0-WOW64 pwatson 1.7.7(0.230/5/3) 2010-08-31 09:58 i686 Cygwin

$ python setup.py sdist
running sdist
warning: sdist: missing required meta-data: url
warning: sdist: missing meta-data: either (author and author_email) or (maintainer and maintainer_email) must be supplied
reading manifest file 'MANIFEST'
creating xlsexport-0.3
making hard links in xlsexport-0.3...
' not a regular file -- skipping
' not a regular file -- skipping
' not a regular file -- skipping
tar -cf dist/xlsexport-0.3.tar xlsexport-0.3
gzip -f9 dist/xlsexport-0.3.tar
removing 'xlsexport-0.3' (and everything under it)
Paul
You might have a better luck posting this as its own question.
Santa