[Tutor] if __name__=='main' vs entry points: What to teach new comers?
eryk sun
eryksun at gmail.com
Wed Aug 2 17:25:20 EDT 2017
On Wed, Aug 2, 2017 at 4:06 PM, Wolfgang Maier
<wolfgang.maier at biologie.uni-freiburg.de> wrote:
> On 08/02/2017 04:57 PM, Steven D'Aprano wrote:
>
>> I have a module with a main() function and an "if __name__ == ..."
>> guard. Under what circumstances is that not sufficient, and I would want
>> console_scripts?
>
> If you install things using pip/setuptools and have defined a
> console_scripts entry point for it, then the corresponding wrapper
> script will be installed in whatever is considered the scripts directory
> at install time on that machine. With a bit of luck the entry point will
> thus be executable directly without any end-user intervention (like
> adding folders to $PATH and chmodding files).
> Personally, I always found it straightforward to write the wrapper
> script myself, then define this as a 'scripts' file in the package
> layout of my setup.py, but people's MMV.
For Windows, using frozen executables is preferred because
CreateProcess doesn't support shebangs. setuptools freezes entry-point
scripts with one of the following stub executables: console_scripts
(cli-32.exe, cli-64.exe) and gui_scripts (gui-32.exe, gui-64.exe).
Actually, it's better to create and install a wheel package, for which
pip uses the newer stubs from distlib: console_scripts (t32.exe,
t64.exe) and gui_scripts (w32.exe, w64.exe). Most Python 3
installations on Windows have at least two entry-point scripts:
pip.exe and easy_install.exe.
More information about the Tutor
mailing list