[Python-Dev] Utility scripts (Was: '-m' option) (original) (raw)
Paul Moore p.f.moore at gmail.com
Mon Oct 4 20:15:52 CEST 2004
- Previous message: '-m' option (was RE: [Python-Dev] ConfigParser patches)
- Next message: [Python-Dev] Utility scripts (Was: '-m' option)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
The problem here is really one of packaging. How should utility scripts be distributed, either with Python, or with extensions? There are many different approaches:
- a library module with useful behaviour in the main block.
- a script in sys.prefix + '/scripts' with no extension and a #! line
- a script as above, but with a .py extension
- a script as (2) plus a .bat wrapper for Windows
- a script as (3) plus a .bat wrapper for Windows
However, none of these give the best behaviour, uniformly across all Windows platforms (the Unix story is far better, as there is a consistent and useful behaviour across all shells).
While case (1) is a bit of an anomaly, Guido's script would probably cover it, if a really acceptable solution for scripts could be found.
Accepting that Unix is generally not an issue, let's look at Windows. On cmd.exe, at least on Windows 2000 and up, the following makes .py files "executable" by python:
assoc .py=Python.File
ftype Python.File=C:\Python23\python.exe "%1" %*
set PATHEXT=%PATHEXT%;.py
Can anyone test this on COMMAND.COM on Win9x? It works using the COMMAND.COM supplied with Windows 2000, whatever that proves :-)
Of these, the first two are set by the standard Windows install. The final one could be. With that change, simply putting a .py script into C:\Python23\Scripts would be enough (assuming C:\Python23\Scripts was on the user's PATH, which it isn't by default, but the user can add it).
Proposal:
- Change the Windows Python binary to add .py (and .pyw, maybe) to PATHEXT
- Add a variation of Guido's script to the standard install, as something like runmod.py
- Document that the way for extensions to include scripts is as .py files in the sys.prefix+'/scripts' directory, with a #! line for Unix
- For Unix users who don't like extensions, suggest (again in the docs) that a hardlink can be added without the extension. Maybe include a suitable setup.py snippet to show how.
- Possibly add sys.path+'/scripts' to the PATH - I'm not sure about this, as on Windows the installer seems to try hard to not modify PATH, so maybe this is a policy issue.
I'm punting on the issue of python.exe flags. If someone wants to run a supplied script as python -E -S -O script.py, I don't have a solution (other than doing so "longhand"). But I don't have a use case, either, so I'll leave that one for others...
Paul
- Previous message: '-m' option (was RE: [Python-Dev] ConfigParser patches)
- Next message: [Python-Dev] Utility scripts (Was: '-m' option)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]