package with executable

Jeff McNeil jeff at jmcneil.net
Tue May 19 16:47:28 EDT 2009


On May 19, 2:54 pm, Stefano Costa <st... at iosa.it> wrote:
> Hi,
> my name is Stefano Costa, I am an archaeologist and I am developing
> GNUCal, a radiocarbon calibration program released under the GNU GPL.
> [1][2]
>
> Currently the program consists of a small "library", largely based on
> Matplotlib and Numpy, and a command line program. My goal is to create a
> distributable package, that should ideally contain both the "gnucal"
> package and the command line program.
>
> As you can see in the source code [3], I am following some sort of
> standard layout for my project, but some things aren't still clear to
> me, even after reading setuptools' documentation and looking to the
> source of some known Python packages (like sphinx, pastescript, django):
>       * where should the executable module be wrt setup.py and/or the
>         package directory in the source tree
>       * how should I format the console_scripts entry in setup() to make
>         the executable module available to the system PATH after
>         installing
>       * how should I call the "gnucal" package from inside the
>         executable script (currently I'm using "from gnucal import core"
>         but it doesn't seem to work)
>
> I'm using virtualenv to create testing environments for the install
> process, and my Python is 2.5.4 on Debian Sid.
>
> Any suggestion is appreciated, particularly if there are some real
> examples to draw from.
>
> thanks,
> steko
>
> [1]http://gnucal.iosa.it/
> [2]http://en.wikipedia.org/wiki/Radiocarbon_dating#Calibration
> [3]http://bitbucket.org/steko/gnucal/
>
> --
> Stefano Costahttp://www.iosa.it/Open Archaeology
>
>  signature.asc
> < 1KViewDownload

So, I've got a couple packages where I've used the same method.
Generally, I've formatted my entry_points argument as follows:

entry_points = {
      'console_scripts': [ 'xmlrpctool =
hostapi.clients.xmlrpc:main' ]
   },

It's just a dictionary with a 'console_scripts' key. The value is a
list of wrapper scripts that are to be installed along with the
library files. In this scenario, I'm installing a wrapper script
called 'xmlrpctool' which calls a function named main in the xmlrpc
module within my hostapi.clients package. SetupTools generates that
wrapper for you.

That main function can be any callable. Looking at the way you've
formatted your gnucal.py script, I'm not sure it's going to work
without a bit of modification.

My personal approach would be to move that code into your gnucal
directory, either as it's own module or within one of the existing,
and implement it as a "main" function.

Then an entry_points line such as the following will make sure
'gnucal' gets installed in a directory on your path:

entry_points = {
      'console_scripts': [ 'gnucal = gnucal.core:main' ]
   },

This, of course, assumes that you move your main function into
'gnucal.core.'

HTH,

Jeff
mcjeff.blogspot.com




More information about the Python-list mailing list