[Distutils] Improving distutils' script and GUI app handling

Phillip J. Eby pje at telecommunity.com
Sat Sep 17 03:24:54 CEST 2005

At 11:19 AM 9/15/2005 -0400, Phillip J. Eby wrote:
>Every so often, there's a perennial debate on the distutils-sig about
>script filenames.  Should they have .py extensions or not?  What about .pyw
>apps on Windows?  What about Mac OS?  and so on.
>So, if these "main" functions were simply declared as entry points in the
>project's setup script, then EasyInstall could automatically generate stub
>scripts for them, in a platform-appropriate fashion, with no need for '-m',
>"__name__=='__main__'", or fiddling with file extensions.  For example,
>if  PyUnit were distributed as an egg, with the following entry points:
>      [distutils.console_apps]
>      unittest = unittest:main
>Then EasyInstall could create a 'unittest' script with a #! line on
>Unix-like OSes, and a 'unittest.py', 'unittest.bat', or 'unittest.exe' on
>Windows.  In each case, the generated program would simply load and run the
>entry point with no arguments.

FYI, I've now implemented console script generation in the CVS version of 
setuptools, except that I decided to call the entry point group 
"console_scripts".  There is a custom .exe launcher for Windows, too.  The 
whole thing was surprisingly easy to implement, and the docs are updated in 
CVS as well.  I'll probably implement the find_package_data() thing this 
weekend as well, and put it out as an 0.6a2 release.

Note that generated scripts can't be run with -m, but then again neither 
can a lot of things.  ;)  Using -m scripts means your eggs can't be 
installed compressed anyway, so these "new-style" scripts are superior in 
almost every way.  You don't need an if __name__=='__main__', you don't 
need separate scripts, just write your "main" function in a module 
somewhere and list the entry point in your setup().

Anyway, for backward-compatibility I'm still allowing "python -m 
easy_install" in the next release or two, but a warning is printed to the 
console.  Later, this feature will be removed so that it's possible to 
install setuptools in compressed form.

More information about the Distutils-SIG mailing list