配置 pyflakes 以使用 Zope 的“脚本 (python)” 文件系统上的对象

发布于 2024-07-25 07:20:35 字数 652 浏览 2 评论 0原文

当我在 Zope 文件系统目录视图文件上运行 pyflakes 时(在 plone 中发现很多),它总是返回很多警告,指出我的参数和特殊值(如“context”)未定义,如果它是真正的 python,则这是真的脚本,但对于文件系统目录视图脚本,它们是由顶部的魔术注释定义的,例如:

## 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

除了Zope之外,这种Python是否在任何地方使用?

是吗?或者是否可以得到 pyflakes、pylint 或类似工具的支持?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

塔塔猫 2024-08-01 07:20:35

我刚刚尝试过的一种可能的方法是预处理 zope fspython 脚本,使其有效。 我使用了一些对 sed 的调用(如下):

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

最好用一个包装 pyflakes 的 python 脚本替换它,并且不会改变正常的 python 脚本。

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.

离笑几人歌 2024-08-01 07:20:35

不,除了 Zope 之外,这种 Python 没有在任何地方使用,事实上现在几乎只在 Plone 中使用。 Plone 社区正在放弃它,因为它有很多缺点,这就是其中之一。

Pyflakes 的可配置性不是很好,至少不是以文档化的方式。 Pylint 可以配置为跳过一些错误消息,但您需要跳过的错误消息将是最有用的,因此这可能也没有帮助。

所以简短的回答是:不,你不能对它们进行语法检查。 另一方面,您不需要重新启动服务器来运行它们,因此语法检查不会为您节省那么多时间,而 Zope 世界中的其他 Python 代码则会节省很多时间。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文