1

I have a python script that is part of a package. The script source file some_script.py contains the following hash-bang at the beginning,

#!/usr/bin/env -S python3 -u

but after installation via pip, the script installed to my pythons bin directory is installed with this line

#!/Users/wursth/opt/anaconda3/envs/py3.9/bin/python

whereas I want it installed with the unbufferd option, like this

#!/Users/wursth/opt/anaconda3/envs/py3.9/bin/python -u

The setup.py looks like this,

import setuptools

setuptools.setup(
  name="test-pkg",
  version="0.0.1",
  author="Hans Wurst",
  description="Test pkg",
  packages=["test"],
  scripts=['test/some_script.py'],
  install_requires=['numpy',
                    'dill',
                    'scipy',
                    ],
  python_requires='>=3.5',
  classifiers=['Programming Language :: Python :: 3.8',
               'License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)',
               'Operating System :: OS Independent'],
)

How can I achieve that a script is installed with the -u option passed to the python environment, when a user installs the python package via pip install ?

Hans Wurst
  • 227
  • 2
  • 15
  • 1
    Would this be close to what you're looking for? https://stackoverflow.com/questions/5443080/force-unbuffered-output-for-script-made-with-buildout-and-zc-recipe-eggscripts/5443807#5443807 – Thang Do Mar 15 '22 at 00:19
  • 1
    @ThangDo I wasn't aware of the linked question. It is essentially the same problem but I am looking for a particular solution. One that addresses how to pass interpreter options from the original scripts shebang line to the installed script using setuptools. The accepted answer does not mention this. I would also accept an answer explaining that this can't/should not be done as long as it gives good reasons and why the alternative should be used. I just don't know if I am using setuptools wrong or if it can't be done at all using setuptools. Shedding light on any of this would help. – Hans Wurst Mar 15 '22 at 07:50

0 Answers0