我的应用程序可以从命令行调用,我使用Click来解析选项。但是,当我从PyCharm运行相同的main时,我必须添加PyCharm在运行pydevd.py时使用的额外选项。这使我的代码与无意义的选项和变量相关联。示例如下:
@click.command()
@click.option('--myOption1')
@click.option('--myOption2')
@click.option('--multiproc', default=True, is_flag=True) #this option is specific to pydev
@click.option('--qt-support',default=True, is_flag=True) #this option is specific to pydev
@click.option('--client') #this option is specific to pydev
@click.option('--port') #this option is specific to pydev
@click.option('--file') #this option is specific to pydev
def doStuff(myOptions1, myOption2,
#the following variables are set by click and have nothing to do with my app
multiproc, qt_support, client, port, file):
# myAppCode begins here....
def main():
doStuff()
if __name__ == '__main__':
main()
当PyCharm在调试器中调用它时,命令为
C:\Anaconda2\python.exe "C:\<aLooongPath>\pydevd.py" --multiproc --qt-support --client 127.0.0.1 --port 44001 --file C:/myModule.py
我怎样才能得到它以便我仍然可以运行调试器而不必将pydevd选项作为变量放入我的代码中?
答案 0 :(得分:0)
查看对类似问题的回答:Add unspecified options to cli command using python-click。
TL; DR;
@cli.command('foreach', context_settings=dict(ignore_unknown_options=True))