[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: howto pack python programs



On Sun, Mar 26, 2006 at 04:33:37PM +0200, Bastian Venthur wrote:
> Is the location /usr/share/$PACKAGE OK? Should I create the symlinks
> without the py-extension, like:
>   /usr/bin/ex1 -> /u/s/ex1.py

I think this is the better solution. A "/usr/bin/ex1.py" would take
away some freedom. Maybe you decide later to use a wrapper script
/usr/bin/ex1 (shell script or python script).

However, there's even a more portable, generic, better solution
I'll try to explain.

> Next problem, lintian is complaining (W) about non-executable scripts in
> /usr/share/$PACKAGE -- can I ignore this?

You shouldn't. I don't believe that your Python code really belongs
there.

You should consider providing a setup.py script, and use this to install
your code. But I'm not sure whether this is in the spirit of the Debian
Python policy.

setup.py would install your python code into:
    ...usr/lib/python2.3/site-packages/

To avoid cluttering the "site-packages/" you may consider using a
"python package", i.e. a sub directory containing your *.py files.


I suggest you to layout your source directory like this:

    myprog/foo.py
    myprog/baz.py
    myprog/ex1.py
    myprog/ex2.py
    myprog/ex3.py
    setup.py
    ex1.py
    ex2.py
    ex3.py

Where ex*.py are executable and myprog/ex*.py aren't.
The ex*.py are wrappers that look like this:

    #!/usr/bin/env python
    import myprog.ex3

or like this, depending on your code:

    #!/usr/bin/env python
    import myprog.ex3
    myprog.ex3.main()

These wrappers may be able to run from the source directory as
well as from /usr/bin/ (provided that your myprog/ package is
installed to .../site-packages/)

However, if your myprog/ex*.py file *are* currently just wrappers
to the functionality of foo.py, baz.py, etc., then just put them
directly into your source package an install them to /usr/bin, i.e.

    myprog/foo.py
    myprog/baz.py
    setup.py
    ex1.py
    ex2.py
    ex3.py

Everything I described until here has nothing to do with
Debian, it's just to provide a source package for general use.
Maybe there are better recommendations in the net, "best
practices". If you find some, please let me know, I didn't
find any. :-)

For Debian, put the ex*.py files to /usr/bin/ex* (without ".py")
and the rest to whatever setup.py recommends, i.e. just do:

    ./setup.py install --prefix="debian/tmp/usr"

If your setup.py looks like this:

    #!/usr/bin/env python

    from distutils.core import setup

    setup(name='MyProgs tools',
          version='1.0',
          description='cool progs',
          author='Bastian Venthur',
          author_email='me@privacy.org.invalid',
          url='http://my-cool.progs.invalid/',

          packages=['myprog'],
          
         )



... then it will install your modules to .../site-packages/myprog/*
and your ex*.py files to .../usr/bin/. Distutils will also adjust the
sh'bang line of your ex*.py to the current interpreter location.

However, it won't rename your ex*.py to ex*, so you'd have to do
this in your "debian/myprog.install" with something like this:

    usr/lib/python*
    usr/bin/ex1.py  usr/bin/ex1

(maybe ... I'm not sure)

see also:

    http://docs.python.org/inst/
    http://docs.python.org/dist/


Whatever you do, I'm very interested in your result. I'll have a similar
challenge to master when I find more time. My current recommendations
on a similar problem can be found at:

    http://wiki.python.de/Pfade_f%C3%BCr_Dateien

(how to deal with non-python files, where to put them, etc. in a
platform independent manner)

It's currently only in german, but I'd translate this if someone is
interested.


Greets,

    Volker

-- 
Volker Grabsch
---<<(())>>---
Administrator
NotJustHosting GbR



Reply to: