从 PyPI 安装我的 sdist 会将文件放在意外的位置

2024-04-21

我的问题是,当我将 Python 包上传到 PyPI,然后使用 pip 从那里安装它时,我的应用程序会崩溃,因为它将我的文件安装到与我简单地从本地 sdist 安装完全相同的包时完全不同的位置。

从本地 sdist 安装会将文件放在我的系统上,如下所示:

/Python27/
  Lib/
    site-packages/
      gloopy-0.1.alpha-py2.7.egg/ (egg and install info files)
        data/ (images and shader source)
        doc/ (html)
        examples/ (.py scripts that use the library)
        gloopy/ (source)

这正如我所期望的,并且工作得很好(例如,我的源可以找到我的数据目录,因为它们彼此相邻,就像它们在开发中一样。)

如果我将相同的 sdist 上传到 PyPI,然后使用 pip 从那里安装它,那么事情看起来会非常不同:

/Python27/
  data/ (images and shader source)
  doc/ (html)
  Lib/
    site-packages/
      gloopy-0.1.alpha-py2.7.egg/ (egg and install info files)
      gloopy/ (source files)
  examples/ (.py scripts that use the library)

这根本不起作用 - 我的应用程序找不到它的数据文件,而且显然它一团糟,用我的所有垃圾污染了顶级 /python27 目录。

我究竟做错了什么?如何使 pip 安装的行为类似于本地 sdist 安装?这就是我应该努力实现的目标吗?

Details

我安装了 setuptools,并且还进行了分发,并且我正在调用 allocate_setup.use_setuptools()

WindowsXP、Python2.7。

我的开发目录如下所示:

/gloopy
  /data (image files and GLSL shader souce read at runtime)
  /doc (html files)
  /examples (some scripts to show off the library)
  /gloopy (the library itself)

我的 MANIFEST.in 提到了我想要包含在 sdist 中的所有文件,包括 data、examples 和 doc 目录中的所有内容:

recursive-include data *.*
recursive-include examples *.py
recursive-include doc/html *.html *.css *.js *.png
include LICENSE.txt
include TODO.txt

我的 setup.py 非常冗长,但我想最好的办法是将它包含在这里,对吧?我还包括对 MANIFEST.in 中提到的相同 data/doc/examples 目录的重复引用,因为我知道这是为了在安装过程中将这些文件从 sdist 复制到系统所必需的。

NAME = 'gloopy'
VERSION= __import__(NAME).VERSION
RELEASE = __import__(NAME).RELEASE
SCRIPT = None
CONSOLE = False

def main():
    import sys
    from pprint import pprint

    from setup_utils import distribute_setup
    from setup_utils.sdist_setup import get_sdist_config
    distribute_setup.use_setuptools()
    from setuptools import setup

    description, long_description = read_description()
    config = dict(
        name=name,
        version=version,
        description=description,
        long_description=long_description,
        keywords='',
        packages=find_packages(),
        data_files=[
            ('examples', glob('examples/*.py')),
            ('data/shaders', glob('data/shaders/*.*')),
            ('doc', glob('doc/html/*.*')),
            ('doc/_images', glob('doc/html/_images/*.*')),
            ('doc/_modules', glob('doc/html/_modules/*.*')),
            ('doc/_modules/gloopy', glob('doc/html/_modules/gloopy/*.*')),
            ('doc/_modules/gloopy/geom', glob('doc/html/_modules/gloopy/geom/*.*')),
            ('doc/_modules/gloopy/move', glob('doc/html/_modules/gloopy/move/*.*')),
            ('doc/_modules/gloopy/shapes', glob('doc/html/_modules/gloopy/shapes/*.*')),
            ('doc/_modules/gloopy/util', glob('doc/html/_modules/gloopy/util/*.*')),
            ('doc/_modules/gloopy/view', glob('doc/html/_modules/gloopy/view/*.*')),
            ('doc/_static', glob('doc/html/_static/*.*')),
            ('doc/_api', glob('doc/html/_api/*.*')),
        ],
        classifiers=[
            'Development Status :: 1 - Planning',
            'Intended Audience :: Developers',
            'License :: OSI Approved :: BSD License',
            'Operating System :: Microsoft :: Windows',
            'Programming Language :: Python :: 2.7',
        ],    
        # see classifiers http://pypi.python.org/pypi?:action=list_classifiers
    ) 

    config.update(dict(
        author='Jonathan Hartley',
        author_email='tartle[email protected] /cdn-cgi/l/email-protection',
        url='http://bitbucket.org/tartley/gloopy',
        license='New BSD',
    ) )

    if '--verbose' in sys.argv:
        pprint(config)

    setup(**config)


if __name__ == '__main__':
    main()

The data_files参数适用于不属于包的数据文件。你可能应该使用package_data反而。

See https://docs.python.org/3/distutils/setupscript.html#installing-package-data https://docs.python.org/3/distutils/setupscript.html#installing-package-data

这不会将数据安装在 site-packages/data 中,但在我看来,这不是应该安装的地方。您不会知道它属于哪个包。它应该安装在site-packages//gloopy-0.1.alpha-py2.7.egg/[data|doc|examples] IMO.

如果您确实认为数据不是包数据,那么您应该使用data_files在这种情况下,pip 会正确安装它,而我会声称setup.py install将其安装在错误的位置。但在我看来,在这种情况下,它是package_data,因为它与包相关,并且不被其他软件使用。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

从 PyPI 安装我的 sdist 会将文件放在意外的位置 的相关文章

随机推荐