tags:

views:

94

answers:

2

When I run pyflakes on a Zope Filesystem Directory View file (as are found a lot in plone) it always returns lots of warnings that my parameters and special values like 'context' are not defined, which would be true if it were a real python script, but for a Filesystem Directory View script, they are defined by magic comments at the top, for example:

## Python Script "Name"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=foo, bar, baz
##
from AccessControl import getSecurityManager
user = getSecurityManager().getUser()

from Products.PythonScripts.standard import html_quote

request = container.REQUEST
RESPONSE = request.RESPONSE

return foo + bar + baz

Is this kind of python used anywhere except Zope?

Is it, or can it be supported by pyflakes, pylint or similar tools?

A: 

No, that kind of python is not used anywhere except Zope, and in fact almost exclusively in Plone nowadays. And the Plone community is moving away from it because it has many drawbacks, this being one of them.

Pyflakes isn't very configurable, at least not in a documented way. Pylint can be configured to skip some error messages, but the ones you need to skip would be the ones that are most useful, so that is probably not helpful either.

So the short answer is: No you can't syntax check them. On the other hand you don't need to restart the server to run them, so the syntax check won't save you that much time, which it will with other Python code in the Zope world.

Lennart Regebro
+1  A: 

A possible approach I just tried is to pre-process the zope fspython script so that it is vaild. I've used a few calls to sed (below):

#!/bin/bash
sed "s/\(^[^#]\)/  \1/" $1 | \
sed "s/^##bind [a-z]*=\([a-z][a-z]*\)$/import \1/" | \
sed "s/^##parameters=\(.*\)/def foo(\1):/" | pyflakes

It would be good to replace this with a python script that wraps around pyflakes and doesn't alter normal python scripts.

rjmunro