如何将其他文件添加到转盘? [英] How do you add additional files to a wheel?

查看:135
本文介绍了如何将其他文件添加到转盘?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何控制转盘中包含哪些文件?看来python setup.py bdist_wheel未使用MANIFEST.in.

How do control what files are included in a wheel? It appears MANIFEST.in isn't used by python setup.py bdist_wheel.

更新:

我错了从源tarball安装与安装轮子之间的区别.源分发包含MANIFEST.in中指定的文件,但已安装的程序包仅包含python文件.无论是通过源分发,egg还是wheel安装,都需要采取步骤来确定应安装的其他文件.即,其他包文件需要 package_data ,而

I was wrong about the difference between installing from a source tarball vs a wheel. The source distribution includes files specified in MANIFEST.in, but the installed package only has python files. Steps are needed to identify additional files that should be installed, whether the install is via source distribution, egg, or wheel. Namely, package_data is needed for additional package files, and data_files for files outside your package like command line scripts or system config files.

我有一个一个项目,我一直在其中使用python setup.py sdist来构建我的包,MANIFEST.in以控制包含和排除的文件,以及 pyroma

I have a project where I've been using python setup.py sdist to build my package, MANIFEST.in to control the files included and excluded, and pyroma and check-manifest to confirm my settings.

我最近将其转换为Python 2/3双代码,并添加了setup.cfg与

I recently converted it to dual Python 2 / 3 code, and added a setup.cfg with

[bdist_wheel]
universal = 1

我可以用python setup.py bdist_wheel制作一个轮子,并且它似乎是所需的通用轮子.但是,它不包括MANIFEST.in中指定的所有文件.

I can build a wheel with python setup.py bdist_wheel, and it appears to be a universal wheel as desired. However, it doesn't include all of the files specified in MANIFEST.in.

我更深入地研究了,现在对包装和车轮有了更多的了解.这是我学到的:

I dug deeper, and now know more about packaging and wheel. Here's what I learned:

我将两个软件包文件上传到PyPi上的 multigtfs项目:

I upload two package files to the multigtfs project on PyPi:

  • multigtfs-0.4.2.tar.gz-源tar球,包括MANIFEST.in中的所有文件.
  • multigtfs-0.4.2-py2.py3-none-any.whl-有问题的二进制分发.
  • multigtfs-0.4.2.tar.gz - the source tar ball, which includes all the files in MANIFEST.in.
  • multigtfs-0.4.2-py2.py3-none-any.whl - The binary distribution in question.

我用Python 2.7.5创建了两个新的虚拟环境,并安装了每个软件包(pip install multigtfs-0.4.2.tar.gz).两种环境几乎相同.它们具有不同的.pyc文件,它们是已编译"的Python文件.有些日志文件记录了磁盘上的不同路径.从源tar球进行的安装包括一个详细说明安装的文件夹multigtfs-0.4.2-py27.egg-info,而轮式安装具有一个multigtfs-0.4.2.dist-info文件夹,其中包含该过程的详细信息.但是,从使用multigtfs项目的代码的角度来看,两种安装方法之间没有什么区别.

I created two new virtual environments, both with Python 2.7.5, and installed each package (pip install multigtfs-0.4.2.tar.gz). The two environments are almost identical. They have different .pyc files, which are the "compiled" Python files. There are log files which record the different paths on disk. The install from the source tar ball includes a folder multigtfs-0.4.2-py27.egg-info, detailing the installation, and the wheel install has a multigtfs-0.4.2.dist-info folder, with the details of that process. However, from the point of view of code using the multigtfs project, there is no difference between the two installation methods.

明确地,我的测试都没有使用.zip文件,因此测试套件将失败:

Explicitly, neither has the .zip files used by my test, so the test suite will fail:

$ django-admin startproject demo
$ cd demo
$ pip install psycopg2  # DB driver for PostGIS project
$ createdb demo         # Create PostgreSQL database
$ psql -d demo -c "CREATE EXTENSION postgis" # Make it a PostGIS database 
$ vi demo/settings.py   # Add multigtfs to INSTALLED_APPS,
                        # Update DATABASE to set ENGINE to django.contrib.gis.db.backends.postgis
                        # Update DATABASE to set NAME to test
$ ./manage.py test multigtfs.tests  # Run the tests
...
IOError: [Errno 2] No such file or directory: u'/Users/john/.virtualenvs/test/lib/python2.7/site-packages/multigtfs/tests/fixtures/test3.zip'

指定其他文件

使用答案中的建议,我向setup.py添加了一些其他指令:

Specifying additional files

Using the suggestions from the answers, I added some additional directives to setup.py:

from __future__ import unicode_literals
# setup.py now requires some funky binary strings
...
setup(
    name='multigtfs',
    packages=find_packages(),
    package_data={b'multigtfs': ['test/fixtures/*.zip']},
    include_package_data=True,
    ...
)

这会将zip文件(以及自述文件)安装到该文件夹​​中,并且测试现在可以正确运行.感谢您的建议!

This installs the zip files (as well as the README) to the folder, and tests now run correctly. Thanks for the suggestions!

推荐答案

您是否尝试过在setup.py中使用package_data? MANIFEST.in似乎是针对python版本< = 2.6的,我不确定是否还会使用更高版本.

Have you tried using package_data in your setup.py? MANIFEST.in seems targetted for python versions <= 2.6, I'm not sure if higher versions even look at it.

浏览 https://github.com/pypa/sampleproject 后,他们的MANIFEST.in说:

# If using Python 2.6 or less, then have to include package data, even though
# it's already declared in setup.py
include sample/*.dat

似乎暗示此方法已过时.同时,他们在setup.py中声明:

which seems to imply this method is outdated. Meanwhile, in setup.py they declare:

setup(
    name='sample',
    ...
    # If there are data files included in your packages that need to be
    # installed, specify them here.  If using Python 2.6 or less, then these
    # have to be included in MANIFEST.in as well.
    package_data={
        'sample': ['package_data.dat'],
    },
    ...
)

(我不确定为什么他们在MANIFEST.in中选择通配符,在setup.py中选择文件名.它们引用相同的文件)

(I'm not sure why they chose a wildcard in MANIFEST.in and a filename in setup.py. They refer to the same file)

这不仅简单,而且再次暗示package_data路由优于MANIFEST.in方法.好吧,除非您必须支持2.6,在这种情况下,我的祈祷会向您发出.

Which, along with being simpler, again seems to imply that the package_data route is superior to the MANIFEST.in method. Well, unless you have to support 2.6 that is, in which case my prayers go out to you.

这篇关于如何将其他文件添加到转盘?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆