[Distutils] Adding entry points into Distutils ?

Ben Finney ben+python at benfinney.id.au
Thu May 7 23:53:03 CEST 2009


Doug Hellmann <doug.hellmann at gmail.com> writes:

> I write a python script call hello.py like this:
> 
> 	#!/usr/bin/env python
> 
> 	def main():
> 		print 'hello!'
> 
> 	if __name__ == '__main__':
> 		main()
> 
> Why make me define an entry point for that?  I can just put it in
> /usr/ bin or somewhere in the path on Windows and call it as
> "hello.py".

To address the issue raised elsewhere in this thread:

Why should the name of a *command* include the suffix ‘.py’? That just
begs for the situation down the line where one of these commands is
being used widely, by the name ‘hello.py’, and then someone wants to
provide an alternative implementation in another language.

A command implemented in Ruby named ‘hello.py’ (for backward
compatibility) is even more annoying that one implemented in Python.

This situation is entirely predictable, so naming it *without* a suffix
is the right way to go. It also makes the command less annoying to type.


The simple rule of thumb:

If it's primarily a module to be imported, name it ‘foo.py’, don't mark
it executable, and don't use the shebang line.

If it's primarily a command to be run as the main program, name it ‘foo’
with no ‘.py’ suffix, mark it executable, and use the shebang line.

-- 
 \     “I have had a perfectly wonderful evening, but this wasn't it.” |
  `\                                                     —Groucho Marx |
_o__)                                                                  |
Ben Finney



More information about the Distutils-SIG mailing list