Phillip J. Eby | 1 Feb 2005 06:08
Gravatar

Re: Live attributes

At 12:42 PM 1/31/05 -0600, Ian Bicking wrote:
>A while ago I posted about a problem with descriptors not knowing what 
>class or name they were bound to: 
>http://blog.ianbicking.org/descriptor-nit.html
>
>Phillip, you noted that PEAK had something like this, IActiveDescriptor 
>and activateInClass.  Anyway, I'm finally getting around to refactoring 
>SQLObject to do this, and I don't want to just invent my own names, and 
>since I find this basic pattern really useful it would be nice to have 
>some cross-library convention on how to do this.  OTOH, I don't want to 
>add a PyProtocols/adaptation requirement to SQLObject for this small 
>feature.  Somehow activateInClass doesn't seem magic enough without 
>adaptation, though at the same time maybe it doesn't matter; is there 
>really likely to be a name conflict.  OTOH, without adaptation it's 
>only  outwardly similar to PEAK, it's certainly not a drop-in replacement.
>
>Any thoughts?

Well, I could change to a generic function and just look for the attribute.

One caveat: be aware that a descriptor can be placed in more than one 
class.  Part of what PEAK's descriptors do is immediately replace 
themselves with another object that knows the attribute name, so that if 
the descriptor is placed in multiple classes, they don't all think they're 
in the same class with the same name.

I don't know that there's that much utility to a cross-library version of 
this; if somebody needs to use both SQLObject and PEAK they can always 
register an adapter from the SQLObject types to PEAK's interface(s), and 
then use PEAK's binding.activateClass() function to activate them.
(Continue reading)

alexander smishlajev | 1 Feb 2005 20:11
Favicon

Re: Packaging peak apps

Phillip J. Eby wrote, at 08.10.2004 20:33:
> 
> 'config.fileNearModule()' is 
> now deprecated and its usage in the PEAK libraries has been converted to 
> 'config.packageFile()', which is able to work with PEP 302 loaders that 
> have a 'get_data()' method (such as the zipfile import loader in Python 
> 2.3 and up).

with current cvs checkout, i cannot run PEAK from zip file:

   File "peak\running\commands.pyc", line 342, in __call__
   File "peak\running\commands.pyc", line 432, in interpret
   File "peak\binding\components.pyc", line 397, in lookupComponent
   File "peak\naming\names.pyc", line 198, in findComponent
   File "peak\naming\api.pyc", line 53, in lookup
   File "peak\naming\api.pyc", line 34, in InitialContext
   File "peak\naming\spi.pyc", line 61, in getInitialContext
   File "peak\core.pyc", line 235, in __call__
   File "peak\config\config_components.pyc", line 402, in lookup
peak.exceptions.NameNotFound: peak.naming.initialContextFactory 
[resolvedObj=<peak.running.commands.ZConfigInterpreter object at 
0x00CBDB50>]

if i add moduleName to self.path in ImportLoaderFactory, this name is 
found (zipfile contains peak.ini is in 'peak' package directory).

best wishes,
alex.
Phillip J. Eby | 1 Feb 2005 20:48
Gravatar

Re: Packaging peak apps

At 09:11 PM 2/1/05 +0200, alexander smishlajev wrote:
>Phillip J. Eby wrote, at 08.10.2004 20:33:
>>'config.fileNearModule()' is now deprecated and its usage in the PEAK 
>>libraries has been converted to 'config.packageFile()', which is able to 
>>work with PEP 302 loaders that have a 'get_data()' method (such as the 
>>zipfile import loader in Python 2.3 and up).
>
>with current cvs checkout, i cannot run PEAK from zip file:
>
>   File "peak\running\commands.pyc", line 342, in __call__
>   File "peak\running\commands.pyc", line 432, in interpret
>   File "peak\binding\components.pyc", line 397, in lookupComponent
>   File "peak\naming\names.pyc", line 198, in findComponent
>   File "peak\naming\api.pyc", line 53, in lookup
>   File "peak\naming\api.pyc", line 34, in InitialContext
>   File "peak\naming\spi.pyc", line 61, in getInitialContext
>   File "peak\core.pyc", line 235, in __call__
>   File "peak\config\config_components.pyc", line 402, in lookup
>peak.exceptions.NameNotFound: peak.naming.initialContextFactory 
>[resolvedObj=<peak.running.commands.ZConfigInterpreter object at 0x00CBDB50>]
>
>if i add moduleName to self.path in ImportLoaderFactory, this name is 
>found (zipfile contains peak.ini is in 'peak' package directory).

Yeah, I just found out about this the other day, when I realized I had 
misread PEP 302's specification about how the paths are supposed to 
work.  More precisely, what needs to be added is the module's __file__.  I 
will try to fix that this evening.

FYI, on a related note, see 
(Continue reading)

Bob Ippolito | 1 Feb 2005 21:02
Gravatar

Re: Packaging peak apps

On Feb 1, 2005, at 14:48, Phillip J. Eby wrote:

> At 09:11 PM 2/1/05 +0200, alexander smishlajev wrote:
>> Phillip J. Eby wrote, at 08.10.2004 20:33:
>>> 'config.fileNearModule()' is now deprecated and its usage in the 
>>> PEAK libraries has been converted to 'config.packageFile()', which 
>>> is able to work with PEP 302 loaders that have a 'get_data()' method 
>>> (such as the zipfile import loader in Python 2.3 and up).
>>
>> with current cvs checkout, i cannot run PEAK from zip file:
>>
>>   File "peak\running\commands.pyc", line 342, in __call__
>>   File "peak\running\commands.pyc", line 432, in interpret
>>   File "peak\binding\components.pyc", line 397, in lookupComponent
>>   File "peak\naming\names.pyc", line 198, in findComponent
>>   File "peak\naming\api.pyc", line 53, in lookup
>>   File "peak\naming\api.pyc", line 34, in InitialContext
>>   File "peak\naming\spi.pyc", line 61, in getInitialContext
>>   File "peak\core.pyc", line 235, in __call__
>>   File "peak\config\config_components.pyc", line 402, in lookup
>> peak.exceptions.NameNotFound: peak.naming.initialContextFactory 
>> [resolvedObj=<peak.running.commands.ZConfigInterpreter object at 
>> 0x00CBDB50>]
>>
>> if i add moduleName to self.path in ImportLoaderFactory, this name is 
>> found (zipfile contains peak.ini is in 'peak' package directory).
>
> Yeah, I just found out about this the other day, when I realized I had 
> misread PEP 302's specification about how the paths are supposed to 
> work.  More precisely, what needs to be added is the module's 
(Continue reading)

Phillip J. Eby | 1 Feb 2005 23:32
Gravatar

Re: Packaging peak apps

At 03:02 PM 2/1/05 -0500, Bob Ippolito wrote:
>Note that it's not just about being able to run arbitrary extensions, that 
>is just a bonus.  It significantly cleans up the API for finding non-code 
>resources, allows for package selection based on version and platform 
>information, etc.  With the pkg_resources API you can (even with the 
>current primitive implementation) do:
>
>pkg_resources.resource_string('peak', 'peak.ini')
>
>and it will do the right thing, whether or not PEAK is in a zip file.

The reason I said it the way I did is that PEAK already has support for 
finding its own stuff in a .zip file, it's just broken.  :)  Fixing the bug 
that Alexander mentioned will allow PEAK to handle non-code resources 
correctly, so the main thing that .egg support adds (to PEAK) is supporting 
extensions, and files that have to be read from C code.

For non-PEAK applications, of course the rest of the pkg_resources API is 
also a bonus.  :)
Bob Ippolito | 2 Feb 2005 00:07
Gravatar

Re: Packaging peak apps


On Feb 1, 2005, at 17:32, Phillip J. Eby wrote:

> At 03:02 PM 2/1/05 -0500, Bob Ippolito wrote:
>> Note that it's not just about being able to run arbitrary extensions, 
>> that is just a bonus.  It significantly cleans up the API for finding 
>> non-code resources, allows for package selection based on version and 
>> platform information, etc.  With the pkg_resources API you can (even 
>> with the current primitive implementation) do:
>>
>> pkg_resources.resource_string('peak', 'peak.ini')
>>
>> and it will do the right thing, whether or not PEAK is in a zip file.
>
> The reason I said it the way I did is that PEAK already has support 
> for finding its own stuff in a .zip file, it's just broken.  :)  
> Fixing the bug that Alexander mentioned will allow PEAK to handle 
> non-code resources correctly, so the main thing that .egg support adds 
> (to PEAK) is supporting extensions, and files that have to be read 
> from C code.
>
> For non-PEAK applications, of course the rest of the pkg_resources API 
> is also a bonus.  :)

I also noticed that zipimport.zipimporter expects PEP 302 fullname's to 
be in 'foo/bar' format for module names, not 'foo.bar' (get_source, 
get_code, is_package).. which is probably a bug.

Do you know of any other importers?  I'm kinda tempted to make 
LoaderDistribution fix-up the fullname's for zipimport.zipimporter 
(Continue reading)

Phillip J. Eby | 2 Feb 2005 02:58
Gravatar

Re: Packaging peak apps

At 06:07 PM 2/1/05 -0500, Bob Ippolito wrote:
>I also noticed that zipimport.zipimporter expects PEP 302 fullname's to be 
>in 'foo/bar' format for module names, not 'foo.bar' (get_source, get_code, 
>is_package).. which is probably a bug.

Well, it certainly doesn't match what PEP 302 says, so it's probably a bug.

>Do you know of any other importers?  I'm kinda tempted to make 
>LoaderDistribution fix-up the fullname's for zipimport.zipimporter 
>compatibility... but I'm not sure if it would break any other ones.

I'm not aware of any others.  Oddly, an awful lot of Google hits for "PEP 
302" point right back to this mailing list.  :)
alexander smishlajev | 2 Feb 2005 18:20
Favicon

loading ZConfig schema from zip file

hello!

with py2exe-packaged application, ZConfig loader fails on declarations 
like this:

  <import package="ank.BBS.MAC.TCP" />

to make it work, we have applied the following patch:

===================================================================
RCS file: /cvsroot/PEAK/src/peak/config/load_zconfig.py,v
retrieving revision 1.17
diff -u -r1.17 load_zconfig.py
--- load_zconfig.py	12 Nov 2004 18:21:10 -0000	1.17
+++ load_zconfig.py	2 Feb 2005 17:10:48 -0000
 <at>  <at>  -48,6 +48,10  <at>  <at> 
          result = super(SchemaLoader,self).loadResource(resource)
          return ConfigLoader(self.getParentComponent(), schema=result)

+    def schemaComponentSource(self, package, file):
+        file = file or "component.xml"
+        return "pkgfile:%s/%s" % (package, file)
+

  class ConfigLoader(BaseLoader,ZConfig.loader.ConfigLoader):

best wishes,
alex.
Phillip J. Eby | 2 Feb 2005 19:05
Gravatar

Re: loading ZConfig schema from zip file

At 07:20 PM 2/2/05 +0200, alexander smishlajev wrote:
>hello!
>
>with py2exe-packaged application, ZConfig loader fails on declarations 
>like this:
>
>  <import package="ank.BBS.MAC.TCP" />
>
>to make it work, we have applied the following patch:
>
>===================================================================
>RCS file: /cvsroot/PEAK/src/peak/config/load_zconfig.py,v
>retrieving revision 1.17
>diff -u -r1.17 load_zconfig.py
>--- load_zconfig.py     12 Nov 2004 18:21:10 -0000      1.17
>+++ load_zconfig.py     2 Feb 2005 17:10:48 -0000
> <at>  <at>  -48,6 +48,10  <at>  <at> 
>          result = super(SchemaLoader,self).loadResource(resource)
>          return ConfigLoader(self.getParentComponent(), schema=result)
>
>+    def schemaComponentSource(self, package, file):
>+        file = file or "component.xml"
>+        return "pkgfile:%s/%s" % (package, file)
>+

Very clever and an excellent fix; will add this when I fix the other .zip 
loading issue.
Phillip J. Eby | 3 Feb 2005 05:08
Gravatar

Re: Packaging peak apps

At 09:11 PM 2/1/05 +0200, alexander smishlajev wrote:
>Phillip J. Eby wrote, at 08.10.2004 20:33:
>>'config.fileNearModule()' is now deprecated and its usage in the PEAK 
>>libraries has been converted to 'config.packageFile()', which is able to 
>>work with PEP 302 loaders that have a 'get_data()' method (such as the 
>>zipfile import loader in Python 2.3 and up).
>
>with current cvs checkout, i cannot run PEAK from zip file:
>
>   File "peak\running\commands.pyc", line 342, in __call__
>   File "peak\running\commands.pyc", line 432, in interpret
>   File "peak\binding\components.pyc", line 397, in lookupComponent
>   File "peak\naming\names.pyc", line 198, in findComponent
>   File "peak\naming\api.pyc", line 53, in lookup
>   File "peak\naming\api.pyc", line 34, in InitialContext
>   File "peak\naming\spi.pyc", line 61, in getInitialContext
>   File "peak\core.pyc", line 235, in __call__
>   File "peak\config\config_components.pyc", line 402, in lookup
>peak.exceptions.NameNotFound: peak.naming.initialContextFactory 
>[resolvedObj=<peak.running.commands.ZConfigInterpreter object at 0x00CBDB50>]
>
>if i add moduleName to self.path in ImportLoaderFactory, this name is 
>found (zipfile contains peak.ini is in 'peak' package directory).

Okay, I've checked in the fix for this, the ZConfig problem, and the 
spurious Graph.txt error.  Please let me know if you have any further 
difficulties, as I am not yet set up to run PEAK from a zipfile myself.

By the way, I gather that PEAK's lazy module mechanism now works correctly 
with zipped modules under Python 2.4?  (There should also be a fix in 
(Continue reading)


Gmane