Function
zope.app.appsetup.appsetup.config

Signature

config(file, features=(), execute=True)

Documentation String

Execute the ZCML configuration file.

This procedure defines the global site setup. Optionally you can also provide a list of features that are inserted in the configuration context before the execution is started.

Let's create a trivial sample ZCML file.

>>> import tempfile
>>> fn = tempfile.mktemp('.zcml')
>>> zcml = open(fn, 'w')
>>> zcml.write('''
... <configure xmlns:meta="http://namespaces.zope.org/meta"
...            xmlns:zcml="http://namespaces.zope.org/zcml">
...   <meta:provides feature="myFeature" />
...   <configure zcml:condition="have myFeature2">
...     <meta:provides feature="myFeature4" />
...   </configure>
... </configure>
... ''')
>>> zcml.close()

We can now pass the file into the config() function:

# End an old interaction first >>> from zope.security.management import endInteraction >>> endInteraction()

>>> context = config(fn, features=('myFeature2', 'myFeature3'))
>>> context.hasFeature('myFeature')
True
>>> context.hasFeature('myFeature2')
True
>>> context.hasFeature('myFeature3')
True
>>> context.hasFeature('myFeature4')
True

Further, we should have access to the configuration file name and context now:

>>> getConfigSource() is fn
True
>>> getConfigContext() is context
True

Let's now clean up by removing the temporary file:

>>> import os
>>> os.remove(fn)