Force options to python interpretion with commands defined using entry points

孤街醉人 提交于 2019-12-24 04:14:08

问题


I want to force a script to be run with python -S, I'm defining the script using entry_points in the setup.py. Is there an option for this?

Thanks!


回答1:


I don't think there is such option in setuptools. You could create a stub script and specify it in the scripts distutils option instead. Bases on Is it possible to set the python -O (optimize) flag within a script?:

#!/usr/bin/env python
from your_package.script import main

if __name__=="__main__":
   import os, sys
   sentinel_option = '--dont-add-no-site-option'
   if sentinel_option not in sys.argv:
      sys.argv.append(sentinel_option)
      os.execl(sys.executable, sys.executable, '-S', *sys.argv)
   else:
      sys.argv.remove(sentinel_option)
      main()


来源:https://stackoverflow.com/questions/12965426/force-options-to-python-interpretion-with-commands-defined-using-entry-points

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!