How to develop a plugin that depends on Python plugin?

I have a lot of *.spec files. In fact, those files are python script with my own extentions(like you don't need to import anything there are a lot of out of stock global functions you can use in the script)
I want to write a plugin to help the editing of *.spec files.
What I did is:
1. Create a plugin project, add python.jar to the dependencies of my project. And add "<depends>Pythonid</depends>" in "plugin.xml"
2. Create "SpecFileTypeFactory" like this:

public class SpecFileTypeFactory extends FileTypeFactory {
  @Override
  public void createFileTypes(@NotNull FileTypeConsumer consumer) {
    consumer.consume(PythonFileType.INSTANCE, new ExtensionFileNameMatcher("spec"));
  }
}

3. Register this factory in "plugin.xml"

<fileTypeFactory implementation="leojay.devtools.intellij.buildplugin.filetype.SpecFileTypeFactory"/>

4. Execute the plugin, install Python plugin, and restart the sandboxed intellij idea.

But I saw some errors:

[   4101]  ERROR -    #com.intellij.lang.Language - Language with ID 'Python' is already registered: class com.jetbrains.python.PythonLanguage
java.lang.Throwable
     at com.intellij.openapi.diagnostic.Logger.error(Logger.java:54)
     at com.intellij.lang.Language.<init>(Language.java:82)
     at com.intellij.lang.Language.<init>(Language.java:67)
     at com.intellij.lang.Language.<init>(Language.java:63)
     at com.jetbrains.python.PythonLanguage.<init>(PythonLanguage.java:19)
     at com.jetbrains.python.PythonFileType.<init>(PythonFileType.java:31)
     at com.jetbrains.python.PythonFileType.<clinit>(PythonFileType.java:28)
     at leojay.devtools.intellij.buildplugin.filetype.SpecFileTypeFactory.createFileTypes(SpecFileTypeFactory.java:13)
     at com.intellij.openapi.fileTypes.impl.FileTypeManagerImpl.a(FileTypeManagerImpl.java:152)

...


[  39350]  ERROR - e.fileTemplates.impl.FTManager - Assertion failed: Duplicate bundled template Flask Main.py
java.lang.Throwable
     at com.intellij.openapi.diagnostic.Logger.assertTrue(Logger.java:98)
     at com.intellij.ide.fileTemplates.impl.FTManager.a(FTManager.java:190)
     at com.intellij.ide.fileTemplates.impl.FTManager.addDefaultTemplate(FTManager.java:181)
     at com.intellij.ide.fileTemplates.impl.FileTemplatesLoader.a(FileTemplatesLoader.java:168)
     at com.intellij.ide.fileTemplates.impl.FileTemplatesLoader.a(FileTemplatesLoader.java:135)
     at com.intellij.ide.fileTemplates.impl.FileTemplatesLoader.<init>(FileTemplatesLoader.java:85)
     at com.intellij.ide.fileTemplates.impl.ExportableFileTemplateSettings.<init>(ExportableFileTemplateSettings.java:54)
     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
     at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
     at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
     at org.picocontainer.defaults.InstantiatingComponentAdapter.newInstance(InstantiatingComponentAdapter.java:193)
     at org.picocontainer.defaults.ConstructorInjectionComponentAdapter$1.run(ConstructorInjectionComponentAdapter.java:220)
     at org.picocontainer.defaults.ThreadLocalCyclicDependencyGuard.observe(ThreadLocalCyclicDependencyGuard.java:53)

...

[  39353]  ERROR - e.fileTemplates.impl.FTManager - Assertion failed: Duplicate bundled template Python Script.py
java.lang.Throwable
     at com.intellij.openapi.diagnostic.Logger.assertTrue(Logger.java:98)
     at com.intellij.ide.fileTemplates.impl.FTManager.a(FTManager.java:190)
     at com.intellij.ide.fileTemplates.impl.FTManager.addDefaultTemplate(FTManager.java:181)
     at com.intellij.ide.fileTemplates.impl.FileTemplatesLoader.a(FileTemplatesLoader.java:168)
     at com.intellij.ide.fileTemplates.impl.FileTemplatesLoader.a(FileTemplatesLoader.java:135)
     at com.intellij.ide.fileTemplates.impl.FileTemplatesLoader.<init>(FileTemplatesLoader.java:85)
     at com.intellij.ide.fileTemplates.impl.ExportableFileTemplateSettings.<init>(ExportableFileTemplateSettings.java:54)
     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
     at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
     at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
     at org.picocontainer.defaults.InstantiatingComponentAdapter.newInstance(InstantiatingComponentAdapter.java:193)
     at org.picocontainer.defaults.ConstructorInjectionComponentAdapter$1.run(ConstructorInjectionComponentAdapter.java:220)
     at org.picocontainer.defaults.ThreadLocalCyclicDependencyGuard.observe(ThreadLocalCyclicDependencyGuard.java:53)
     at org.picocontainer.defaults.ConstructorInjectionComponentAdapter.getComponentInstance(ConstructorInjectionComponentAdapter.java:248)
     at org.picocontainer.defaults.DecoratingComponentAdapter.getComponentInstance(DecoratingComponentAdapter.java:60)
     at com.intellij.openapi.components.impl.CachingComponentAdapter.getComponentInstance(CachingComponentAdapter.java:54)
     at com.intellij.openapi.components.impl.ServiceManagerImpl$MyComponentAdapter.initializeInstance(ServiceManagerImpl.java:159)
     at com.intellij.openapi.components.impl.ServiceManagerImpl$MyComponentAdapter$1.compute(ServiceManagerImpl.java:147)
     at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:950)


Why those errors?

Thanks.

Leo Jay

6 comments

Oh, another question: How can I add global python functions for those spec files? I need auto completion and parameter info.

Thanks.

0

Please make sure that you've added the jars of the Python plugin to the classpath of the IntelliJ IDEA SDK and not as a separate library.

0

I don't think the currently released version of the Python plugin has any APIs for that.

0

Hi, I have the same question, I want to develop custom documentation provider that extends existing PythonDocumentationProvider,
but my plugin code seems to be not executed at all.

Here is my plugin.xml:

<idea-plugin version="2">
  ...
  <!-- please see http://confluence.jetbrains.net/display/IDEADEV/Build+Number+Ranges for description -->
  <idea-version since-build="107.105"/>

  <!-- please see http://confluence.jetbrains.net/display/IDEADEV/Plugin+Compatibility+with+IntelliJ+Platform+Products
       on how to target different products -->
  <depends>com.intellij.modules.lang</depends>

  <application-components>
    <!-- Add your application components here -->
  </application-components>

  <project-components>
    <!-- Add your project components here -->
  </project-components>

  <actions>
    <!-- Add your actions here -->
  </actions>

  <extensions defaultExtensionNs="com.intellij">
    <!-- Add your extensions here -->
      <lang.documentationProvider language="Python" implementationClass="com.xxx.MyDocumentationProvider"/>
  </extensions>
</idea-plugin>
 

 
0

add order="first" to your documentation provider definition and make sure to return null for cases which yours does not handle

0

Please sign in to leave a comment.