distutils:如何将用户定义的参数传递给setup.py? [英] distutils: How to pass a user defined parameter to setup.py?
问题描述
请提示我如何将命令行和setup.cfg配置文件中的用户定义参数传递给distutils的setup.py脚本。我想编写一个setup.py脚本,该脚本接受我的程序包特定参数。例如:
Please prompt me how to pass a user-defined parameter both from the command line and setup.cfg configuration file to distutils' setup.py script. I want to write a setup.py script, which accepts my package specific parameters. For example:
python setup.py install -foo myfoo
谢谢,
Mher
Thank you,
Mher
推荐答案
由于对Setuptools / Distuils的记录非常糟糕,所以我自己找不到答案。但是最终我偶然发现了这个示例。另外,此类似问题也很有帮助。基本上,带有选项的自定义命令如下所示:
As Setuptools/Distuils are horribly documented, I had problems finding the answer to this myself. But eventually I stumbled across this example. Also, this similar question was helpful. Basically, a custom command with an option would look like:
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,
}
)
这篇关于distutils:如何将用户定义的参数传递给setup.py?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!