python - distutils:如何将用户定义的参数传递给 setup.py?

标签 python distutils setup.py

如何将用户定义的参数从命令行和 setup.cfg 配置文件传递到 distutils 的 setup.py 脚本?

我想编写一个 setup.py 脚本,它接受我的包特定参数。例如:

python setup.py install -foo myfoo

最佳答案

由于 Setuptools/Distuils 的文档非常糟糕,我自己在寻找答案时遇到了问题。但最终我偶然发现了this例子。另外,this类似的问题很有帮助。基本上,带有选项的自定义命令如下所示:

from distutils.core import setup, Command

class InstallCommand(Command):
    description = "Installs the foo."
    user_options = [
        ('foo=', None, 'Specify the foo to bar.'),
    ]
    def initialize_options(self):
        self.foo = None
    def finalize_options(self):
        assert self.foo in (None, 'myFoo', 'myFoo2'), 'Invalid foo!'
    def run(self):
        install_all_the_things()

setup(
    ...,
    cmdclass={
        'install': InstallCommand,
    }
)

关于python - distutils:如何将用户定义的参数传递给 setup.py?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/677577/

相关文章:

python - 从 Python 中的 Amazon Kinesis 输出读取字节图像

Python distutils,如何获得将要使用的编译器?

python - py2exe导入错误: no module named <package I have impemented>

python - 在 setup.py 中安装另一个源发行版?

python - 如何在pandas中按值滚动窗口执行排除组中的当前日期?

python - 在 Python 中向 JSON 对象添加值

python - 为什么 `setup.py develop` 不起作用?

python - 当用户从 PyPI pip 安装您的软件包时,从 setup.py 中访问用户激活的虚拟环境

python - 在 Python 中安装 matplotlib 的问题

python - 无法在 pyspark 中加载模型并使用 grpc 提供服务