如何将用户定义的参数从命令行和 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/