At 08:56 PM 6/5/2001 -0400, Jay Love wrote:
>Chuck Esterbrook wrote:
>
>>I ran into a problem where an "import Foo" was picking up the Foo in 
>>WebKit. Launch.py was previously tweaked to fix this but then got tweaked 
>>back. However, we don't ever want "import Foo" to assume WebKit.
>
>Because WebKit is a package, any modules in the WebKit package that call 
>"import Foo" should get WebKit.Foo first.  The WebKit part is 
>automatically appended.  That is why it doesn't matter in your servlets if 
>you say "from WebKit import Page" or just "import Page".  Either way, if 
>you look in sys.modules, you'll see WebKit.Page.

Yes, modules in the WebKit directory can import modules in the same 
directory with "import Foo".  But servlets in different directories should 
NOT be able to do "import Page" to get WebKit.Page.  And I don't think most 
people put their servlets directly in the WebKit directory...


>>I made the following changes:
>>- Incorporated Geoff's path cleaning code from Cookie.py. No path ending 
>>in 'webkit' or equal to '.' is kept.
>>- '' is always the first sys.path element.
>
>Note that '' is not os.cwd.  '' is the directory the module calling 
>"import" is in.  Therefore, you ARE including WebKit, assuming you are 
>calling import from a module in the WebKit directory, or any subdirectory 
>(since its a package).  So that's not what you want.

Subpackages can NOT directly import things higher up in the directory tree 
-- you have to use a fully qualified package import.  Maybe this is where 
the confusion is coming from?

If I make the following files somewhere on my Python path:

MyPackage/__init__.py
MyPackage/MyModule.py
MyPackage/MySubPackage/__init__.py
MyPackage/MySubPackage/MySubModule.py

then MySubModule.py can NOT just do "import MyModule".  That causes an 
"ImportError: No module named MyModule" exception.  MySubModule.py must do 
"import MyPackage.MyModule".  I just tested this.  Just because something 
is in a subpackage does not give it special access to the package above it.


>>- The cur dir becomes Webware/
>
>
>Why don't we eliminate this reliance on the cwd?  Why are you insisting on 
>that?

Remember the whole reason for launch.py?  To avoid duplicate modules, we 
have to always treat modules in WebKit as package modules, even though we 
are launching a script _inside_ of the WebKit directory.  The way we got 
this to work is to change our cwd to the directory that contains WebKit 
(i.e. Webware), then import a module in WebKit as a package.  I don't think 
there's any other way to get this to work as long as the launcher script is 
_inside_ of the WebKit directory.  And Chuck wanted to keep that script 
inside of WebKit because it logically belongs there.


- Geoff


_______________________________________________
Webware-devel mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/webware-devel

Reply via email to