making symlinks with distutils

  • Thread starter Michele Simionato
  • Start date
M

Michele Simionato

I want to distribute a pure Python package with this structure:
mypackage
__init__.py
module1.py
module2.py
...
myexecutable.py

In particular, myexecutable.py is a script which is intended to be used
from the command line via the shebang trick. I want to distribute on
Unices.
and I want a symlink

/usr/bin/myexecutable -> <package-path>/mypackage/myexecutable.py

to be made at installation time, when the user runs "python setup.py
install".

What is the recommanded way to do that? Do I need a postinstallation
script or something like that?

I could do that in various way, but I don't see the obvious one,
maybe because I am not a Dutch ;)


Michele Simionato
 
S

Sylvain Thenault

I want to distribute a pure Python package with this structure:


In particular, myexecutable.py is a script which is intended to be used
from the command line via the shebang trick. I want to distribute on
Unices.
and I want a symlink

/usr/bin/myexecutable -> <package-path>/mypackage/myexecutable.py

to be made at installation time, when the user runs "python setup.py
install".

What is the recommanded way to do that? Do I need a postinstallation
script or something like that?

I could do that in various way, but I don't see the obvious one, maybe
because I am not a Dutch ;)

i'm not sure there is a standard way to do so with distutils.
My current way to handle executable scripts is to have a run() function in
the myexecutable.py module, and then to have a very simple myexecutable
script with the following content:

#!/usr/bin/python
from mypackage import myexecutable
myexecutable.run()

And then register this script using distutils'"scripts" keyword argument.
This has the advantage that I can also create a very simple .bat file for
windows users without code duplication.
 
M

Michele Simionato

From what I see in the docs, registering a script just normalize the
shebang line, but does not install it in
/usr/bin, nor make any symbolic links, so it is not
what I am looking for.
I guess I need to add a os.link(src, dst) somewhere in the
setup.py script or in a postinstallation script but I am not exactly
sure where.

M.S.
 
S

Sylvain Thenault

shebang line, but does not install it in /usr/bin, nor make any symbolic
links, so it is not what I am looking for.

Actually it does install it is $PREFIX/bin.
 
M

Michele Simionato

Sylvain Thenault:
Actually it does install it is $PREFIX/bin.

Aha! And how do I set $PREFIX? Is it a Unix environment variable or is
it
a keyword argument in setup? Something like setup( prefix="/usr") ?
 
S

Sylvain Thenault

Sylvain Thenault:

Aha! And how do I set $PREFIX? Is it a Unix environment variable or is it
a keyword argument in setup? Something like setup( prefix="/usr") ?

it's a command line argument of the "install" command:

python setup.py install --prefix=~/

or

python setup.py install --home=~/

(the difference between --home and --prefix is that the former will
install library in $PREFIX/lib/pythonX.Y/site-packages while the latter
will install it in $PREFIX/lib/python/
 
C

Christos TZOTZIOY Georgiou

I guess I need to add a os.link(src, dst) somewhere in the
setup.py script or in a postinstallation script but I am not exactly
sure where.

Since you want to make a symbolic link, you probably want to use os.symlink()
and not os.link(), but that seems to be the least of your troubles.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top