[Product-Developers] RFC: Venusian-based Python-syntax alternative for ZCML-configuration

Mikko Ohtamaa mikko+plone at redinnovation.com
Mon Jan 6 11:47:37 UTC 2014

On 6 January 2014 09:25, Asko Soukka <asko.soukka at iki.fi> wrote:

> Hi Dylan,
> Dylan Jay wrote:
>> If you have conditional imports scan doesn't work so well. I had this
>> problem recently with a pyramid project where I didn't want a file
>> imported otherwise it caused a syntax error.
> I do use conditional imports and I don't see the real issue here (yet).
> I think, this is mainly a problem from recursive scan. If you do scan per
> file, you can have conditions just normally. With Grok,
> you can already use:
>     <grok:grok module=".foobar" zcml:condition="installed ..." />
> Of course, in Python, you need to be more verbose:
>     try:
>         pkg_resources.get_distribution('...')
>     except pkg_resources.DistributionNotFound:
>         HAS_SOMETHING = False
>     else:
>         HAS_SOMETHING = True
>        import module
>        scan(module)

Python can make things pretty for you.

This could be shortcutted as a context manager:

with has_package("plone.app.z3cform", version=">1.3.0"):
      # do something

Also all scans should be explicit, preferably not executed on the module
body level. If you put things to a function e.g.

def configurare():
      ... configure my package...

And then those configure()s are executed in well-known order, the package
author has more leverage and tools in the possession to tackle potential
conflict issues (E.g. as the last resolt monkey-patch another configure())

Mikko Ohtamaa
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.plone.org/pipermail/plone-product-developers/attachments/20140106/169533ff/attachment.html>

More information about the Product-Developers mailing list