Re: [Python-Dev] PEP 338 vs PEP 328 - a limitation of the -m switch

2006-06-18 Thread Phillip J. Eby
At 11:18 AM 6/18/2006 -0700, Guido van Rossum wrote:
On 6/18/06, Nick Coghlan [EMAIL PROTECTED] wrote:
  The 'bug fix' solution would be:
 
 1. Change main.c and PySys_SetPath so that '' is NOT prepended to 
 sys.path
  when the -m switch is used
 2. Change runpy.run_module to add a __pkg_name__ attribute if the module
  being executed is inside a package
 3. Change import.c to check for __pkg_name__ if (and only if) 
 __name__ ==
  '__main__' and use __pkg_name__ if it is found.

That's pretty heavy-handed for a pretty esoteric use case. (Except #1,
which I think should be done regardless as otherwise we'd get a
messed-up sys.path.)

Since the -m module is being run as a script, shouldn't it put the module's 
directory as the first entry on sys.path?  I don't think we should change 
the fact that *some* directory is always inserted at the beginning of 
sys.path -- and all the precedents at the moment say script directory, if 
you consider -c and the interactive interpreter to be scripts in the 
current directory.  :)

___
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/archive%40mail-archive.com


Re: [Python-Dev] PEP 338 vs PEP 328 - a limitation of the -m switch

2006-06-18 Thread Guido van Rossum
On 6/18/06, Phillip J. Eby [EMAIL PROTECTED] wrote:
 At 11:18 AM 6/18/2006 -0700, Guido van Rossum wrote:
 On 6/18/06, Nick Coghlan [EMAIL PROTECTED] wrote:
   The 'bug fix' solution would be:
  
  1. Change main.c and PySys_SetPath so that '' is NOT prepended to
  sys.path
   when the -m switch is used
  2. Change runpy.run_module to add a __pkg_name__ attribute if the 
   module
   being executed is inside a package
  3. Change import.c to check for __pkg_name__ if (and only if)
  __name__ ==
   '__main__' and use __pkg_name__ if it is found.
 
 That's pretty heavy-handed for a pretty esoteric use case. (Except #1,
 which I think should be done regardless as otherwise we'd get a
 messed-up sys.path.)

 Since the -m module is being run as a script, shouldn't it put the module's
 directory as the first entry on sys.path?

Yes for a top-level module. No if it's executing a module inside a
package; it's really evil to have a package directory on sys.path.

 I don't think we should change
 the fact that *some* directory is always inserted at the beginning of
 sys.path -- and all the precedents at the moment say script directory, if
 you consider -c and the interactive interpreter to be scripts in the
 current directory.  :)

You have a point about sys.path[0] being special. It could be the
current directory instead of the package directory.

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)
___
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/archive%40mail-archive.com


Re: [Python-Dev] PEP 338 vs PEP 328 - a limitation of the -m switch

2006-06-18 Thread Phillip J. Eby
At 02:03 PM 6/18/2006 -0700, Guido van Rossum wrote:
On 6/18/06, Phillip J. Eby [EMAIL PROTECTED] wrote:
  At 11:18 AM 6/18/2006 -0700, Guido van Rossum wrote:
  On 6/18/06, Nick Coghlan [EMAIL PROTECTED] wrote:
The 'bug fix' solution would be:
   
   1. Change main.c and PySys_SetPath so that '' is NOT prepended to
   sys.path
when the -m switch is used
   2. Change runpy.run_module to add a __pkg_name__ attribute if 
 the module
being executed is inside a package
   3. Change import.c to check for __pkg_name__ if (and only if)
   __name__ ==
'__main__' and use __pkg_name__ if it is found.
  
  That's pretty heavy-handed for a pretty esoteric use case. (Except #1,
  which I think should be done regardless as otherwise we'd get a
  messed-up sys.path.)
 
  Since the -m module is being run as a script, shouldn't it put the module's
  directory as the first entry on sys.path?

Yes for a top-level module. No if it's executing a module inside a
package; it's really evil to have a package directory on sys.path.

  I don't think we should change
  the fact that *some* directory is always inserted at the beginning of
  sys.path -- and all the precedents at the moment say script directory, if
  you consider -c and the interactive interpreter to be scripts in the
  current directory.  :)

You have a point about sys.path[0] being special. It could be the
current directory instead of the package directory.

Mightn't that be a security risk, in that it introduces an import hole for 
secure scripts run with -m?  Not that I know of any such scripts existing 
as yet...

If it's not the package directory, perhaps it could be a copy of whatever 
sys.path entry the package was found under - that wouldn't do anything but 
make nearby imports faster.

___
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/archive%40mail-archive.com


Re: [Python-Dev] PEP 338 vs PEP 328 - a limitation of the -m switch

2006-06-18 Thread Guido van Rossum
On 6/18/06, Phillip J. Eby [EMAIL PROTECTED] wrote:
 You have a point about sys.path[0] being special. It could be the
 current directory instead of the package directory.

 Mightn't that be a security risk, in that it introduces an import hole for
 secure scripts run with -m?  Not that I know of any such scripts existing
 as yet...

That sounds like an invented use case if I ever heard of one. YAGNI, please!

 If it's not the package directory, perhaps it could be a copy of whatever
 sys.path entry the package was found under - that wouldn't do anything but
 make nearby imports faster.

But it could theoretically affect search order for other modules. I
still see nothing wrong with . After all that's also the default if
you run a script using python path/to/file.py .

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)
___
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/archive%40mail-archive.com


Re: [Python-Dev] PEP 338 vs PEP 328 - a limitation of the -m switch

2006-06-18 Thread Nick Coghlan
Guido van Rossum wrote:
 If it's not the package directory, perhaps it could be a copy of whatever
 sys.path entry the package was found under - that wouldn't do anything but
 make nearby imports faster.
 
 But it could theoretically affect search order for other modules. I
 still see nothing wrong with . After all that's also the default if
 you run a script using python path/to/file.py .

No problem - inserting '' is what the switch does currently. A security 
conscious script should really be clobbering sys.path anyway so that it only 
contains the locations the script needs.

As for the other part (requiring absolute imports), I can put a footnote in 
the tutorial somewhere.

If anyone complains bitterly about the limitation, there's always 2.6 :)

Cheers,
Nick.


-- 
Nick Coghlan   |   [EMAIL PROTECTED]   |   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/archive%40mail-archive.com