我应该如何调试 Trac 插件?
我即将开始大量工作来扩展 Trac 以满足我们的业务需求。 到目前为止,我已经使用 pythonWin 和 Netbeans 6.5 作为开发环境 - 这些似乎都没有提供任何调试我正在开发的插件的方法。
我对 Python 完全陌生,所以可能还没有设置开发环境,如何配置它以进行调试。
我错过了一些明显的东西吗? 必须诉诸于将调试消息打印到 Trac 日志似乎有点过时,这就是我目前调试的方式。
I'm about to start a fair amount of work extending Trac to fit our business requirements.
So far I've used pythonWin and now Netbeans 6.5 as the development environments - neither of these seem to provide any way of debugging the plugin I am working on.
I'm totally new to Python so probably have not set up the development environment how it could be congfigured to get it debugging.
Am I missing something obvious? It seems a bit archaic to have to resort to printing debug messages to the Trac log, which is how I'm debugging at the moment.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以创建包装器 wsgi 脚本并在调试器中运行它。 例如:
您可以在调试器中运行此脚本,并且可以使用lighttpd作为Web应用程序的前端,并通过如下简单配置:
只需在调试器中运行fcgi wsgi包装器,在插件中设置断点,然后打开网页。
You can create a wrapper wsgi script and run it in a debugger. For example:
You would run this script in the debugger, and you can use lighttpd as a frontend for the web application with a trivial config like this one:
Just run the fcgi wsgi wrapper in the debugger, set the breakpoints in your plugin, and open the web page.
通常,我们首先进行单元测试。
然后,我们编写日志消息来诊断问题。
我们通常不会严重依赖调试,因为在 Python 脚本嵌入到较大产品中的情况下通常很难做到这一点。
Usually, we unit test first.
Then, we write log messages to diagnose problems.
We generally don't depend heavily on debugging because it's often hard to do in situations where Python scripts are embedded in a larger product.
我发现 Winpdb 是一个不错的 python 调试器。
但正如 S.Lott 指出的那样,当您的项目嵌入到较大的项目中时,调试器可能对您没有多大用处。
I've found that Winpdb is a decent python debugger.
But as S.Lott points out, debuggers may not be very useful to you when your project is embedded within a larger one.
Trac 包含很好的 Python 代码示例,使用它作为指南将有助于避免错误。 只要确保测试你的代码,并且经常这样做,因为你是 Python 新手......你会发现你不需要调试器。
对于单元测试,请查看 PyUnit。
Trac contains good examples of Python code, using it as a guideline will help avoid bugs. Just be sure to test your code, and do it often since you are new to Python... You'll find you don't need a debugger.
For unit testing, check out PyUnit.
我发现在运行时添加那些奇特的 Trac 消息框作为调试帮助或跟踪是最有用的,就像这样:
有时它比事后阅读日志记录更舒服。 尽管它仅在您运行的函数具有该
req
参数时才有效。I found it most useful to add those fancy Trac messageboxes at runtime as debugging help or tracing, just like this:
Sometimes it's more comfortable than reading logging afterwards. Though it only works if the function you're running has that
req
arg.