Eclipse 可以从命令行运行PyDev代码分析吗?

Eclipse 可以从命令行运行PyDev代码分析吗?,eclipse,pydev,code-analysis,Eclipse,Pydev,Code Analysis,我试图运行一个无头eclipse构建,但我被卡住了。我的上下文是,我希望使用PyDev代码分析,而不必启动eclipsegui。我知道还有其他命令行工具可以进行代码分析(pyflakes、pylint等) 到目前为止,我的命令是: java -jar /path/to/eclipse/plugins/org.eclipse.equinox.launcher_1.2.0.v20110502.jar -noSplash -data "/path/to/workspace" -application

我试图运行一个无头eclipse构建,但我被卡住了。我的上下文是,我希望使用PyDev代码分析,而不必启动eclipsegui。我知道还有其他命令行工具可以进行代码分析(pyflakes、pylint等)

到目前为止,我的命令是:

java -jar /path/to/eclipse/plugins/org.eclipse.equinox.launcher_1.2.0.v20110502.jar -noSplash -data "/path/to/workspace" -application org.eclipse.jdt.apt.core.aptBuild
我的java版本是1.6.031,我的eclipse版本是3.7.2,我的pydev版本是2.5.0

当我运行该命令时,看起来它正在工作,但它从未捕获任何错误或警告

...
PyDev: Analyzing 29 of 33 (forms.py)
PyDev: Analyzing 29 of 33 (forms.py)
PyDev: Analyzing 29 of 33 (forms.py)
PyDev: Analyzing 29 of 33 (forms.py)
...
如果我
tail-f/path/to/workspace/.metadata/.log
,我会得到一个巨大的堆栈跟踪:

!ENTRY org.eclipse.equinox.preferences 4 2 2012-07-30 17:48:39.612
!MESSAGE Problems occurred when invoking code from plug-in: "org.eclipse.equinox.preferences".
!STACK 0
java.lang.ExceptionInInitializerError
    at org.eclipse.debug.internal.ui.DebugUIPreferenceInitializer.setDefault(DebugUIPreferenceInitializer.java:186)
    at org.eclipse.debug.internal.ui.DebugUIPreferenceInitializer.setThemeBasedPreferences(DebugUIPreferenceInitializer.java:204)
    at org.eclipse.debug.internal.ui.DebugUIPreferenceInitializer.initializeDefaultPreferences(DebugUIPreferenceInitializer.java:79)
    at org.eclipse.core.internal.preferences.PreferenceServiceRegistryHelper$1.run(PreferenceServiceRegistryHelper.java:281)
..... TRUNCATED ......

!ENTRY org.eclipse.osgi 4 0 2012-07-30 17:48:39.622
!MESSAGE An error occurred while automatically activating bundle org.eclipse.debug.ui (42).
!STACK 0
org.osgi.framework.BundleException: Exception in org.eclipse.debug.internal.ui.DebugUIPlugin.start() of bundle org.eclipse.debug.ui.
    at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:734)
    at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:683)
    at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:381)
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:299)
..... TRUNCATED .......

java.lang.IllegalStateException: Workbench has not been created yet.
    at org.eclipse.ui.PlatformUI.getWorkbench(PlatformUI.java:92)
    at org.eclipse.debug.internal.ui.contextlaunching.LaunchingResourceManager.startup(LaunchingResourceManager.java:546)
    at org.eclipse.debug.internal.ui.DebugUIPlugin.getLaunchingResourceManager(DebugUIPlugin.java:315)
    at org.eclipse.debug.internal.ui.DebugUIPlugin.start(DebugUIPlugin.java:516)
..... TRUNCATED ......

!ENTRY org.eclipse.osgi 4 0 2012-07-30 17:48:39.624
!MESSAGE An error occurred while automatically activating bundle org.eclipse.debug.core (41).
!STACK 0
org.osgi.framework.BundleException: Exception in org.eclipse.debug.core.DebugPlugin.start() of bundle org.eclipse.debug.core.
    at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:734)
    at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:683)
    at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:381)
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:299)
..... TRUNCATED ......

我的怀疑是PyDev需要gui来呈现错误/警告。

PyDev需要gui来呈现错误/警告,一般来说,在命令行中没有使用gui。。。话虽如此,它确实有单元测试,可以在不需要gui(甚至不需要加载eclipse)的情况下运行代码分析,但是您必须在内存中配置解释器/项目才能使其工作

...
PyDev: Analyzing 29 of 33 (forms.py)
PyDev: Analyzing 29 of 33 (forms.py)
PyDev: Analyzing 29 of 33 (forms.py)
PyDev: Analyzing 29 of 33 (forms.py)
...
见:

对于在不需要加载eclipse工作台的情况下进行代码分析的测试(即:甚至不需要无头运行eclipse——它可以作为一个简单的java程序运行,但您仍然需要执行java main([])在类路径中使用PyDev并使用其API正确设置PyDev中使用的解释器以及projects/pythonpath)

您可以查看测试的设置(即:不要忘了查看超类,例如CodeCompletionTestsBase/AnalysisTestsBase)

注意:如果您确实创建了这样一个main([]),请为PyDev提供一个补丁,因为它可能会被其他人使用

作为一个实现说明,这样一个main可能会从正在启动的shell中收集所有当前的PYTHONPATH条目,并配置解释器中的所有条目。。。此外,它可能会接收一个目录作为参数,以便分析树中的所有文件(启动可能会占用您大部分的时间来配置东西,因此,理想情况下,您可以从一次运行中分析尽可能多的文件,因为PyDev代码分析是为了在启动时缓存很多东西,然后使用RAM中的信息——或者创建一个始终处于活动状态的服务器进程?)