如何使用setuptools将Python标签添加到bdist_wheel命令? [英] How do I add a Python tag to the bdist_wheel command using setuptools?

查看:108
本文介绍了如何使用setuptools将Python标签添加到bdist_wheel命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个简单的库,该库使用 setuptools 进行打包和分发。在这种情况下,该库还需要最低版本的Python 3.6,这意味着我的setup.py如下所示:

Let's say I have a simple library which uses setuptools for packaging and distributing. The library in this case also requires a minimum version of Python 3.6, meaning my setup.py would be something like as follows:

from setuptools import setup, find_packages

setup(
    name='something',
    version='0.0.1',

    description='description',
    long_description=long_description,

    # More metadata

    packages=find_packages(exclude=['tests', 'docs']),

    python_requires='>=3.6'
)

现在,当我运行 python setup.py bdist_wheel ,我得到一个名为 something-0.0.1-py3-none-any.whl 。如此处所示,在确定我的转轮的Python标记时,转轮忽略了 setuptools 中的 python_requires 选项(应该是 py36 ,但默认为 py3 )。显然,我意识到我可以从命令行传递-python-tag py36 来完成这项工作,但是我正在使用的连续部署服务我的图书馆只接受我正在使用的发行版的名称( bdist_wheel )。因此,我无法传递任何命令行参数。

Now, when I run python setup.py bdist_wheel, I get a file named something-0.0.1-py3-none-any.whl. As evident here, wheel is ignoring the python_requires option in setuptools when determining the Python tag for my wheel (it should be py36 but is the default py3). Obviously, I realize that I can just pass in --python-tag py36 from the command line, which will do the job, but the continuous deployment service I am using for deploying my library only takes in the name of the distribution I am using (bdist_wheel). As such, I cannot pass any command line parameters.

经过大量研究,发现我可以继承 bdist_wheel 类并覆盖 python_tag 成员变量,但根据方向盘自述文件:

After doing a bit of research, I found that I could inherit from the bdist_wheel class and override the python_tag member variable, but according to the wheel README:


应该注意,wheel并非要用作库,因此没有稳定的公共API。

It should be noted that wheel is not intended to be used as a library, and as such there is no stable, public API.

因此,我想避免从 bdist_wheel 类继承,这可能会迫使我在每次中断时重写类会发生变化。

Because of this, I want to avoid inheriting from the bdist_wheel class which might force me to rewrite my class every time some breaking change occurs.

是否有其他可通过setuptools的方式允许我传递车轮的Python标记?

Is there any alternative way through setuptools which allows me to pass in the Python tag for a wheel?

推荐答案

每个 distutils 命令的每个命令行参数都可以保存在安装配置文件中。在您的 setup.py 所在的同一目录中创建一个名为 setup.cfg 的文件,并存储自定义的 bdist_wheel 在那里的配置:

Every command line argument for every distutils command can be persisted in setup config file. Create a file named setup.cfg in the same directory your setup.py resides in and store the custom bdist_wheel configuration in there:

# setup.cfg
[bdist_wheel]
python-tag=py36

现在运行 python setup.py bdist_wheel 与运行 python setup.py bdist_wheel --python-tag py36 基本相同。

Now running python setup.py bdist_wheel will be essentially the same as running python setup.py bdist_wheel --python-tag py36.

distutils 中的相关文章:编写安装程序配置文件

Relevant article in the distutils docs: Writing the Setup Configuration File.

这篇关于如何使用setuptools将Python标签添加到bdist_wheel命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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