[Distutils] Replacing pip.exe with a Python script

Tim Golden mail at timgolden.me.uk
Wed Jul 17 21:22:37 CEST 2013


On 17/07/2013 20:12, Paul Moore wrote:
> On 17 July 2013 19:55, Steve Dower <Steve.Dower at microsoft.com> wrote:
>
>>> I'm afraid exe files as wrappers are probably the only viable option.
>> The basic
>>> reason is that the OS recognises exe files in all context, with no
>> special
>>> configuration needed. This is not true of any other file type. So
>> anything else
>>> will have corner cases that will give unexpected results.
>>
>> No reason to be afraid of this, exe wrappers are totally the best option.
>>
>> As for updating .exes while they're running, the best approach is to
>> rename the running one (e.g. 'pip.exe' -> 'pip.exe.deleteme') in the same
>> folder and either:
>> * delete any existing .deleteme files on next run, or
>> * delete an existing pip.exe.deleteme file immediately before trying to
>> rename to it
>>
>> Any other approach will also have corner cases, but this will be the most
>> reliable in the context of multiple users/permissions/environment variables.
>>
> The problem issue remaining is recognising when we need to do this. In
> terms of code paths, pip install -U pip is no different from (for example)
> pip install -U flask. But it needs to be handled specially just because
> it's pip.

I don't think it does: in essence, any distribution which installs an 
.exe wrapper for some entry point can (possibly should) be treated the 
same way. Assuming that flask installed some kind of "run-flask.exe" in 
scripts/ you'd do the same thing: rename in-place so that the old one 
could keep running; write the new one under the old name; delete the old 
one (if you can).

The issue of deleting the .deleteme versions of arbitrary scripts is 
that you don't know when they might be delete-able. In the Flask 
example, assume that someone was actually using run-flask.exe to run a 
Flask app, you can rename the .exe but you won't be able to delete it 
until it had finished running. Unless you have a watchdog script which 
watches the file / folder then you just have to call it .deleteme and 
clean up as best you can the next time round.

TJG


More information about the Distutils-SIG mailing list