Making directories and zip files executable
The local patch I have for PEP 366 is somewhat stale, and before I bring it up to date with SVN head, I'd like to close out the issue raised a while back regarding making zip files executable [1]. The original proposal was for a new command line switch, but PJE came up with a patch (attached to the roundup tracker item) that uses the existing import machinery to avoid the need for the extra command line switch (by checking if the argument is a valid sys.path entry before checking to see if it is an executable script). I personally like the idea (and PJE's approach), and the performance impact on script startup time appears to be negligible (although I haven't performed any high precision measurements - I'm just using the Linux time utility on a short test script with and without the patch). Are there any objections to my committing this? Cheers, Nick. [1] http://bugs.python.org/issue1739468 -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia --------------------------------------------------------------- http://www.boredomandlaziness.org
I could use a refresher on how PJE's patch solves Andy's problem. On 9/11/07, Nick Coghlan <ncoghlan@gmail.com> wrote:
The local patch I have for PEP 366 is somewhat stale, and before I bring it up to date with SVN head, I'd like to close out the issue raised a while back regarding making zip files executable [1].
The original proposal was for a new command line switch, but PJE came up with a patch (attached to the roundup tracker item) that uses the existing import machinery to avoid the need for the extra command line switch (by checking if the argument is a valid sys.path entry before checking to see if it is an executable script).
I personally like the idea (and PJE's approach), and the performance impact on script startup time appears to be negligible (although I haven't performed any high precision measurements - I'm just using the Linux time utility on a short test script with and without the patch).
Are there any objections to my committing this?
Cheers, Nick.
[1] http://bugs.python.org/issue1739468
-- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia --------------------------------------------------------------- http://www.boredomandlaziness.org _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/guido%40python.org
-- --Guido van Rossum (home page: http://www.python.org/~guido/)
Guido van Rossum wrote:
I could use a refresher on how PJE's patch solves Andy's problem.
I'm not sure if you're asking about how you would execute a zip file after the patch has been applied, or about the mechanics of how the patch works. PJE's last post covered the former question, so I'll cover the gist of the latter. The patch works by passing the script argument to the import machinery to see if it is recognised as a valid sys.path entry (i.e. either a directory or a zip file in a default Python installation). If it is, then add that location to the front of sys.path and use the -m switch support to execute the "__main__" module directly. If the filename passed in isn't recognised as a sys.path entry, then it is executed as a script as normal. Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia --------------------------------------------------------------- http://www.boredomandlaziness.org
On 9/12/07, Nick Coghlan <ncoghlan@gmail.com> wrote:
Guido van Rossum wrote:
I could use a refresher on how PJE's patch solves Andy's problem.
I'm not sure if you're asking about how you would execute a zip file after the patch has been applied, or about the mechanics of how the patch works. PJE's last post covered the former question, so I'll cover the gist of the latter.
The patch works by passing the script argument to the import machinery to see if it is recognised as a valid sys.path entry (i.e. either a directory or a zip file in a default Python installation).
Ah, this is the crux! I didn't understand Phillips wording of "an importable path". I still didn't understand your wording "recognised as a valid sys.path entry"; both wordings suggest a link between sys.argv[0] and the current value of sys.path, which isn't the case -- it is whether they are recognized by the "meta import hook"! This only became clear after I re-read the patch with Phillip's and your words in the back of my head. I now like and approve of the patch, and said so on the tracker. --Guido
If it is, then add that location to the front of sys.path and use the -m switch support to execute the "__main__" module directly.
If the filename passed in isn't recognised as a sys.path entry, then it is executed as a script as normal.
Cheers, Nick.
-- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia --------------------------------------------------------------- http://www.boredomandlaziness.org
-- --Guido van Rossum (home page: http://www.python.org/~guido/)
participants (2)
-
Guido van Rossum -
Nick Coghlan