[Grok-dev] Using adaptation without running a web application.

Martijn Faassen faassen at startifact.com
Wed Jan 21 10:18:31 EST 2009


Hey,

Alec Munro wrote:
> I'm wondering what the best way to use adaptation in a script would
> be. I would guess I would have to have a central method that did all
> the necessary imports to set up the adapter registry, and run this at
> the beginning of every script. I would probably be able to get by with
> just Zope.interface.
> 
> But I'm very interested in suggestions for the best way to do this. I
> may have to make this a web application in the future, so if there's a
> way to make use of Grok's machinery without starting a web server,
> that might be an ideal solution.
> 
> I'm not sure if this is still the right mailing list for this kind of
> question, please let me know if it isn't.

Yes, this is the right mailing list as this is what grokcore.component 
can do for you. The Grok project wants its code to be reusable in other 
applications.

See this for my previous explanation:

http://mail.zope.org/pipermail/grok-dev/2008-December/006743.html

As I said there, it'd be great if someone could create a document based 
on this so we can put on grok.zope.org and/or include in 
grokcore.component's documentation. Lacko Roman was going to look into 
this but he wasn't as confident about this english.

One difference is that you're talking about a simple script as opposed 
to some larger application in a package that does this. My example 
requires some glue ZCML to get the stuff bootstrapped. You might be able 
to embed the ZCML in your script, and it's probably also possible to 
call the underlying APIs in zope.configuration and grokcore.component so 
you could skip the ZCML entirely.

If you have a single-file script which registers adapters, you'd need to 
modify the grok directive to just point to the script's module:

<grok:grok package="myscript" />

Anyway, that's how you'd do it with grokcore.component. You can go a 
layer deeper and just depend on zope.component of course, but then you'd 
need to register your adapters and utilities manually.

Regards,

Martijn



More information about the Grok-dev mailing list