2

In Python 3, it's my understanding that the recommended way to build a Python command line script is to treat it as an "entry point" into a python package, and then use setup.py in order to auto-generate the actual script itself, based upon a main() function found somewhere within in the package.

I've found some decent tutorials here, here and here which explain exactly how to do that.

The problem with auto-generating the script is that I'm not sure how to control the contents of the "shebang" line (e.g., #!/usr/bin/env python) which would typically appear near the top of the script--that part is auto-generated for me.

I would like to design the command line script so that the "shebang" line automatically calls python with certain python flags enabled by default

In particular, I want to run the script as python -u in order to turn off stdout buffering as described here.

What would I need to put in my setup.py file in order to tell setuptools to do that for me? Of course I could just edit the auto-generated script by hand afterward, but that seems like it would utterly defeat the purpose of having a system to auto-generate console scripts in the first place. Is there a way to do it, or is this just a fundamental limitation of the "package entry point" model for creating command line scripts?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
stachyra
  • 4,423
  • 4
  • 20
  • 34

1 Answers1

0

There are various ways this topic is treated on Stack Overflow. I will list two examples:

Community
  • 1
  • 1
AlexV
  • 578
  • 8
  • 19