[Zconfig] python eggs and ZConfig

Duncan McGreggor duncan.mcgreggor at gmail.com
Mon Nov 14 09:29:24 EST 2005


Fred, I see that you just updated svn with support for python eggs...  
it looks like the code is designed to allow importing eggs. However, I  
think I have a different egg issue...

My application is using ZConfig, and there are python egg resource  
files that I want ZConfig to have access to. They are not in a package,  
but rather in a "conf/" directory in the egg. The application's main  
ZConfig schema (schema.xml) file performs the following import:

<import src="schema-services.xml" />

All the doctests tests pass with flying colors. However, as soon as I  
create an egg, ZConfig pukes when it tries to do this import from  
inside the egg, giving an error that it can't find the file in a  
temporary egg location, one that was created during the egg build  
process (Traceback below).

I use setuptools to get this info via python like so:

schema_filename = resource_filename(
     Requirement.parse("PyMonitor"),"conf/schema.xml")
config_filename = resource_filename(
     Requirement.parse("PyMonitor"),"conf/example-pymon.conf")
schema = ZConfig.loadSchema(schema_filename)
cfg, nil = ZConfig.loadConfig(schema, config_filename)

conf is not part of a packge, nor should it be -- it's a user-editable  
file (even though it's in an egg right now, the app will later look to  
PREFIX/conf for overrides to the packaged config file).

So, my question is this: is there any way for ZConfig to use  
non-package, relative-path files from inside an egg right now?

If so, can you provide any pointers? If no, what do you think it would  
take to do add this functionality?

Thanks!

d

P.S. Here's the traceback:

Traceback (most recent call last):
   File  
"/System/Library/Frameworks/Python.framework/Versions/2.3/bin/pymon",  
line 5, in ?
     pkg_resources.run_script('PyMonitor==0.3.2', 'pymon')
   File  
"/Library/Python/2.3/setuptools-0.6a7-py2.3.egg/pkg_resources.py", line  
407, in run_script
     self.require(requires)[0].run_script(script_name, ns)
   File  
"/Library/Python/2.3/setuptools-0.6a7-py2.3.egg/pkg_resources.py", line  
927, in run_script
     exec script_code in namespace, namespace
   File  
"/System/Library/Frameworks/Python.framework/Versions/2.3/bin/pymon",  
line 8, in ?

   File "build/bdist.darwin-7.9.0-Power_Macintosh/egg/pymon/config.py",  
line 9, in ?
   File  
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ 
python2.3/site-packages/ZConfig/loader.py", line 32, in loadSchema
     return SchemaLoader().loadURL(url)
   File  
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ 
python2.3/site-packages/ZConfig/loader.py", line 66, in loadURL
     return self.loadResource(r)
   File  
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ 
python2.3/site-packages/ZConfig/loader.py", line 187, in loadResource
     schema = ZConfig.schema.parseResource(resource, self)
   File  
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ 
python2.3/site-packages/ZConfig/schema.py", line 27, in parseResource
     xml.sax.parse(resource.file, parser)
   File  
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ 
python2.3/site-packages/_xmlplus/sax/__init__.py", line 31, in parse
     parser.parse(filename_or_stream)
   File  
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ 
python2.3/site-packages/_xmlplus/sax/expatreader.py", line 109, in  
parse
     xmlreader.IncrementalParser.parse(self, source)
   File  
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ 
python2.3/site-packages/_xmlplus/sax/xmlreader.py", line 123, in parse
     self.feed(buffer)
   File  
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ 
python2.3/site-packages/_xmlplus/sax/expatreader.py", line 216, in feed
     self._parser.Parse(data, isFinal)
   File  
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ 
python2.3/site-packages/_xmlplus/sax/expatreader.py", line 312, in  
start_element
     self._cont_handler.startElement(name, AttributesImpl(attrs))
   File  
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ 
python2.3/site-packages/ZConfig/schema.py", line 103, in startElement
     getattr(self, "start_" + name)(attrs)
   File  
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ 
python2.3/site-packages/ZConfig/schema.py", line 299, in start_import
     schema = self._loader.loadURL(src)
   File  
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ 
python2.3/site-packages/ZConfig/loader.py", line 64, in loadURL
     r = self.openResource(url)
   File  
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ 
python2.3/site-packages/ZConfig/loader.py", line 107, in openResource
     self._raise_open_error(url, str(e))
   File  
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ 
python2.3/site-packages/ZConfig/loader.py", line 119, in  
_raise_open_error
     url)
ZConfig.ConfigurationError: error opening file  
/Users/oubiwann/.python-eggs/PyMonitor-0.3.2-py2.3.egg-tmp/conf/schema- 
services.xml: [Errno 2] No such file or directory:  
'/Users/oubiwann/.python-eggs/PyMonitor-0.3.2-py2.3.egg-tmp/conf/ 
schema-services.xml'



More information about the ZConfig mailing list