首页 > 解决方案 > 在 setup.py 中读取“--plat-name”参数

问题描述

setuptools bdist_wheel/bdist_egg命令有一个--plat-name允许覆盖主机平台名称的参数。该值被附加到结果文件的名称上,例如mypackage-1.2.3-py2.py3-none-manylinux1_x86_64.whl.

我怎样才能读到这个值setup.py?注意我不是在询问脚本运行的主机平台,例如platform.system(). 我想要 setuptools 正在使用的平台名称。

标签: pythonsetuptools

解决方案


bdist_egg(并且只有它;bdist_wheel只是运行bdist_egg--plat-name参数存储在self.plat_name. 因此,您可以bdist_egg使用自定义类覆盖并使用self.plat_name

from setuptools.command.bdist_egg import bdist_egg as _bdist_egg
from setuptools import setup

class bdist_egg(_bdist_egg):
    def run(self):
        # Use self.plat_name before building an egg…
        _bdist_egg.run(self)
        # …or after

setup(
    …
    cmdclass={
        'bdist_egg': bdist_egg,
    },
    …
)

推荐阅读