[distutils] Install script under a different name

N

Nikolaus Rath

Hello,

All my Python files have extension .py. However, I would like to install
scripts that are meant to be called by the user without the suffix, i.e.
the file scripts/doit.py should end up as /usr/bin/doit.

Apparently the scripts= option of the setup() function does not support
this directly. Is there a clever way to get what I want?


Best,

-Nikolaus
 
L

Lie Ryan

Hello,

All my Python files have extension .py. However, I would like to install
scripts that are meant to be called by the user without the suffix, i.e.
the file scripts/doit.py should end up as /usr/bin/doit.

Apparently the scripts= option of the setup() function does not support
this directly. Is there a clever way to get what I want?

if this is on windows, you should add ".py" to the PATHEXT environment
variable.

on linux/unix, you need to add the proper #! line to the top of any
executable scripts and of course set the executable bit permission
(chmod +x scriptname). In linux/unix there is no need to have the .py
extension for a file to be recognized as python script (i.e. just remove
it).
 
F

Floris Bruynooghe

on linux/unix, you need to add the proper #! line to the top of any
executable scripts and of course set the executable bit permission
(chmod +x scriptname). In linux/unix there is no need to have the .py
extension for a file to be recognized as python script (i.e. just remove
it).

The #! line will even get replaced by the interpreter used during
installation, so you can safely write "#!/usr/bin/env python" in your
development copy and get "#!/usr/bin/python" when users install it.
 
W

Wolodja Wentland

All my Python files have extension .py. However, I would like to install
scripts that are meant to be called by the user without the suffix, i.e.
the file scripts/doit.py should end up as /usr/bin/doit.
Apparently the scripts= option of the setup() function does not support
this directly. Is there a clever way to get what I want?

Just name the file you want to install 'doit' and not 'doit.py'. That
would be the easiest way. You might run into problems on Windows though,
which IIRC (it's been a while) heavily relies on file suffixes and not
on their content. That might have changed in the last 10 years though,
so better check that first.

You can also use entry points to create the executable at install time.
Have a look at [1] which explains how this is done. This requires using
Distribute/setuptools though, ...

[1] http://packages.python.org/distribute/setuptools.html#automatic-script-creation
--
.''`. Wolodja Wentland <[email protected]>
: :' :
`. `'` 4096R/CAF14EFC
`- 081C B7CD FF04 2BA9 94EA 36B2 8B7F 7D30 CAF1 4EFC

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iQIcBAEBCAAGBQJLGkYEAAoJEIt/fTDK8U781q4P/3oK/RZ3ncDUmYVFRXFlF5tv
5heq94i7BLoo6U5Lw6P0E/+oMxC7TeWtmzvsF7eRY4j31MbO5SU4J+nnN+3bHplT
tbBb7yHdE6bxBBpOg2recVcJAhYDP4bj1/VKsNq4mScNZaOF+uh8ZmxkQaas+b13
NVhLnGGV8fu3cI77nYfrHgd10tuQdeR7/TAMLGyI3zH0+f9XLy9nuB/XnCvnWIEo
2tfnkO+1816L1URHjJ50E69BGp56ONRk4wvsIeXOtqIAY7Fv+xBtZQHvVp+NWZVX
7j6+0+XXIqf52NsVC+M5GOdx9nD5IefrX5kV3E/MnQgD6dxu52JH4RnuAxRB6OdL
/WgCNjikCR1kXA05u3TlcFFXIlTdhtqZaxahdLQzCxwe1cwsgZBVPY7TF/AdNvDS
MtmG4G5CE0SgNO6cBldug4i9Z5LPvwY+Q2RZteeGbXHThXZAwanBouvfUFH2kgkX
dIBcZrHbBb5DKQfQYoUSLa8gXpP5TphUMAf9Xvw2dLqUugjY5BGrLaf3sz0uNPW0
5e+EntO4HK+n17g5iJjquVA/3uyDp+AuLtCJKl5vaCpN2avBpl/kCwFGEtlxfvEo
sYIZQlEgzR5OPeSIIgay2lMjmRvoDPV6yBjU2DwETfyglPcNKoEpMkD7sVdVBl4p
mpTAuHdQNCruR3VBj8rJ
=27c+
-----END PGP SIGNATURE-----
 
N

Nikolaus Rath

Lie Ryan said:
if this is on windows, you should add ".py" to the PATHEXT environment
variable.

on linux/unix, you need to add the proper #! line to the top of any
executable scripts and of course set the executable bit permission
(chmod +x scriptname). In linux/unix there is no need to have the .py
extension for a file to be recognized as python script (i.e. just
remove it).

Sorry, but I think this is totally unrelated to my question. I want to
rename files during the setup process. This is not going to happen by
adding/changing any #! lines or the permissions of the file.

I know that there is no need to have the .py extension, that's why I
want to install the scripts without this suffix. But in my source
distribution I want to keep the suffix for various reasons.

Best,

-Nikolaus
 
N

Nikolaus Rath

Wolodja Wentland said:
All my Python files have extension .py. However, I would like to install
scripts that are meant to be called by the user without the suffix, i.e.
the file scripts/doit.py should end up as /usr/bin/doit.
Apparently the scripts= option of the setup() function does not support
this directly. Is there a clever way to get what I want?

You can also use entry points to create the executable at install time.
Have a look at [1] which explains how this is done. This requires using
Distribute/setuptools though, ...

[1] http://packages.python.org/distribute/setuptools.html#automatic-script-creation

That looks perfect, thanks!


Best,

-Nikolaus
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top