Suppose I have a Python script that I want to distribute (not necessarily on PyPI, but I want people to be able to use pip to install it, e.g., with pip install . in a source checkout, or with pip install https://github.com/project/project/archive/master.zip).
Furthermore, I am excited about Python’s UTF-8 mode, finally allowing me to (mostly) not care about encodings anymore, because I adhere to the principle that the world should use UTF-8 ALWAYS, UTF-8 EVERYWHERE, UTF-8 ONLY.
Is there any way to ensure that when pip creates the wrapper for my script, it passes -X utf8 to the Python interpreter?
I don’t have an answer, but I do think it’s a good idea.
I also think there has got to be a way to set UTF-8 mode in your code, after Python startup, but can’t find that either
On the other hand, you can also add the encoding='utf-8' argument to all the open(), etc calls in your code, and that will solve most of the problems for your users.
One more note: pip itself does not setup the entry points – that’s done by the “build” tool – e.g. setuptools. So you might look there – and maybe post an issue here:
Maybe it is a question for the #packaging category.
If I am not mistaken, it is indeed the installer (pip for example) who is in charge of writing the script wrapper. And I believe that in pip’s case, it is done by distlib.scripts which is vendored in pip.
As far as I know pip does not offer any way to customize the shebang that it generates.
Thanks – looksl ike you are right (kinda – if you do the old fashioned setup.py install then setuptools does it – I guess that pip is doing it with wheels.
“You can pass an optional options dictionary to the make() method. This is meant to contain options which control script generation.”
…
" interpreter_args : If provided, this should be a list of strings which are added to the shebang line following the interpreter. If there are values with spaces, you will need to surround them with double quotes."
So – how to tell pip what you want it to do?? But it may not be pip directly, it may be how the wheel is built … so ??
Yes, you are more likely to find help in the Packaging topic – or on the pip (or setuptools or poetry or ??) gitHub issues.