pip setup.py不会将额外的数据文件复制到目标,尽管它们存在于源包中

时间:2016-01-05 06:20:42

标签: python python-2.7 pip setuptools

在我的包中,我需要部署一些辅助js和json文件。

在我的MANIFEST.IN文件中,我指定了:

include config/*.json
include bin/*.js
include lib/*.js

运行python setup.py sdist后,我使用tar txvf dist/mypackage-1.2.1.tar.gz检查内容。我可以看到json和js文件。

但是当我运行pip install /path/to/sdist/file/mypackage-1.2.1.tar.gz时,它只会将python文件安装到site-packages/mypackage位置。我需要做什么才能复制其他文件?

import os
import shutil
import subprocess
import json

from setuptools import setup
from setuptools.command.install import install
from distutils.sysconfig import get_python_lib


class Installer(install):

    def run(self):
        install.run(self)
        install_folder = '%s/mypackage' % get_python_lib()
        # Just to check what I got
        for n, ds, fs in os.walk(install_folder):
            print n, d, fs


setup(name='mypackage',
      version='1.2.1',
      description='mypackage',
      url='https://github.com/myrepo/mypackage',
      author='me',
      author_email='i@me.com',
      license='MIT',
      packages=['mypackage'],
      package_data={'js': ['config/*json', 'lib/*js', 'bin/*js']},
      include_package_data=True,
      cmdclass={'install': Installer})

这是pip setup.py sdist

的输出
$ python setup.py sdist                                                                                                                                
running sdist
running egg_info
writing mypackage.egg-info/PKG-INFO
writing top-level names to mypackage.egg-info/top_level.txt
writing dependency_links to mypackage.egg-info/dependency_links.txt
reading manifest file 'mypackage.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'mypackage.egg-info/SOURCES.txt'
warning: sdist: standard file not found: should have one of README, README.rst, README.txt

running check
creating mypackage-1.2.2
creating mypackage-1.2.2/bin
creating mypackage-1.2.2/config
creating mypackage-1.2.2/mypackage
creating mypackage-1.2.2/mypackage.egg-info
creating mypackage-1.2.2/lib
making hard links in mypackage-1.2.2...
hard linking MANIFEST.in -> mypackage-1.2.2
hard linking package.json -> mypackage-1.2.2
hard linking setup.py -> mypackage-1.2.2
hard linking bin/cli.js -> mypackage-1.2.2/bin
hard linking config/appengine-endpoint.json -> mypackage-1.2.2/config
hard linking config/bugsense.json -> mypackage-1.2.2/config
hard linking config/youtube.json -> mypackage-1.2.2/config
hard linking mypackage/__init__.py -> mypackage-1.2.2/mypackage
hard linking mypackage.egg-info/PKG-INFO -> mypackage-1.2.2/mypackage.egg-info
hard linking mypackage.egg-info/SOURCES.txt -> mypackage-1.2.2/mypackage.egg-info
hard linking mypackage.egg-info/dependency_links.txt -> mypackage-1.2.2/mypackage.egg-info
hard linking mypackage.egg-info/pbr.json -> mypackage-1.2.2/mypackage.egg-info
hard linking mypackage.egg-info/top_level.txt -> mypackage-1.2.2/mypackage.egg-info
hard linking lib/mypackage.js -> mypackage-1.2.2/lib
hard linking lib/templater.js -> mypackage-1.2.2/lib
Writing mypackage-1.2.2/setup.cfg
Creating tar archive
removing 'mypackage-1.2.2' (and everything under it)

1 个答案:

答案 0 :(得分:0)

更改您的package_data,使其相对于包目录,如下所示:

package_data={'mypackage': ['config/*json', 'lib/*js', 'bin/*js']}