Force options to python interpretion with commands

2019-07-21 15:22发布

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条回答
神经病院院长
2楼-- · 2019-07-21 15:49

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()
查看更多
登录 后发表回答