[Distutils] How to handle launcher script importability?
Vinay Sajip
vinay_sajip at yahoo.co.uk
Wed Aug 14 13:34:29 CEST 2013
Jason R. Coombs <jaraco <at> jaraco.com> writes:
> This means that instead of installing, for example:
>
> Scripts\my-command.exe
> Scripts\my-command-script.py
> Scripts\my-command.exe.manifest
>
Just to muddy the waters a little, I'd like to suggest an alternative
approach which doesn't appear to have been tried:
1. The installer just installs foo.exe on Windows for script 'foo',
where the foo.exe contains the actual script 'foo' as a resource.
2. The launcher, before looking for foo-script.py, examines its resources.
If a script resource is found, it is extracted and written to
foo-script.py in the same directory as foo.exe. If such a resource isn't
found, it continues to the next step.
3. The launcher looks for 'foo-script.py' in its directory, invokes it and
waits for it to complete.
4. If a 'foo-script.py' was written in step 2, it is deleted.
The launcher comes with an embedded manifest, so no external manifest is
needed.
The insertion of a script as a resource is easy to do using ctypes: I've
tested it using a suitably modified version of the current distlib launcher
and it seems to work as expected.
Advantages of this approach:
1. No additional file clutter: Just one installed file per script.
2. No need to worry about PATHEXT, or whether the PEP 397 launcher is
installed.
3. Since the script is foo-script.py, no import clashes will occur.
Disadvantages of this approach:
1. The scripts are hard to inspect because they're in the .exe. OTOH,
(a) we don't really want people to mess with the scripts, and (b) they
should be stock wrappers for other code which does the real work.
(There are developer tools which allow inspection of resources, if
really needed.)
2. Requires ctypes in the installer, so perhaps problematic for versions
of Python < 2.5.
3. Scripts take up more space than a .py-with-PEP 397-launcher solution,
but that approach can still give rise to the import issue, as well as
requiring PATHEXT setup.
Thoughts?
Regards,
Vinay Sajip
More information about the Distutils-SIG
mailing list