如何将用户定义的参数从命令行和 setup.cfg 配置文件传递到 distutils 的 setup.py 脚本?
我想编写一个 setup.py 脚本,它接受我的包特定参数。例如:
python setup.py install -foo myfoo
由于 Setuptools/Distuils 的文档非常多,我自己找不到答案。但最终我偶然发现this http://marc.merlins.org/linux/talks/SvnScalingGvn/svn-tree/gvn-release/setup.py例子。还,this https://stackoverflow.com/questions/1710839/custom-distutils-commands类似的问题很有帮助。基本上,带有选项的自定义命令如下所示:
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,
}
)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)