Thursday, June 9, 2011

KDevelop python language support plugin pre-release

Hey there!

For the last couple of months, I have been working on Python language support for KDevelop, the well-known C++ IDE from the KDE project. Now I can finally release a first preview of my work to the public:
In this post I'll tell you about what the plugin is capable of and how to install it.
First of all, this is the list of supported features:
  • Semantic syntax highlighting, as seen in the above screenshot.
  • Code navigation telling you about declarations of stuff, types (if known) and arguments:
  • If possible, intelligent auto-completion:
  • If possible, autocompletion for function arguments:
  • QuickOpen / Outline support (just type in part of a function-name, classname, filename, or anything and press enter):
  • "Go to error" output widget (just click the line with the error or use F4 / Shift+F4 to jump to the next/previous error):
    You can configure what script to launch with which python version in the Run » Confiure Launches dialog. Be sure to select "Script Application" in the list on the left side!

How to install

First of all, this should not be considered an official release meant for production use or packagers. It's merely a preview.

The plugin is currently not very stable yet, but in my opinion it's usable already. I recommend installing the plugin into a local directory (like ~/install) so you can safely and easily get rid of it in case you encounter major problems (the build system is not very reliable yet, sorry for that).

So, first, you need to compile and install KDevelop and KDevPlatform. There's instructions on how to do this here: http://techbase.kde.org/KDevelop4/HowToCompile
It is very important that you use git to checkout the current master branch of both kdevelop and kdevplatform. If you download the tarballs, the plugin is NOT going to work, as it needs some recent changes in kdevplatform. You also cannot use it with any packages provided by your distribution currently. There will hopefully be packages in the future, but not until the plugins and all its dependencies have seen a stable release, which will at least take a few months.

If you've succeeded in installing KDevelop and KDevPlatform, you can now install the plugin in pretty much the same way:
"cd" to the directory you want to download the sources to, then get the plugin source code:
git clone git://anongit.kde.org/kdev-python
You can now checkout the alpha1.1 release by typing: "git checkout alpha1.1". However, I do not recommend doing so, as I'll continue doing bugfixes in the master branch and you probably want to have them.
Then do the following:
mkdir build
cd build
cmake ..
make parser
make install
You should of course specify a correct install path (-DCMAKE_INSTALL_PREFIX=/...) like for KDevelop and KDevPlatform. Especially you must not forget about the "make parser" step; it will compile a modified and stripped-down version of python (don't worry, it will not (should not? :) touch your system's python installation) which is needed by the plugin code.

Then just run "kbuildsycoca4" and start up kdevelop. You should now have fancy syntax highlighting and stuff in any .py file. Have fun!

If you encounter any problems while installing or if the plugin crashes, please tell me! I'm very interested in fixing those problems as soon as possible.

Good luck!

42 comments:

  1. @Theo django support is on its way. :)
    Basic support should be there with the latest commit (although it's nothing django-specific, the plugin will find its way through some of the django sources).

    ReplyDelete
  2. I love you man ;D. Now just waiting for C# support in KDevelop and I'm content.

    Thank you for making Python support possible. Will make Python develop more easier and fun to work in now.

    ReplyDelete
  3. Can't wait to get the stable release, it really looks awesome :)

    And hearing that Django support is planned, it's even better :D

    ReplyDelete
  4. I tested it and runs!

    ReplyDelete
  5. I'm sorry, but when i do "make install", i have an error :

    Generating navigationwidget.moc
    [ 0%] Built target kdev4pythonduchain_automoc
    [ 0%] Built target kdev4pythonparser_automoc
    make[2]: *** Pas de règle pour fabriquer la cible « KDevPlatformImport__kdevplatformlanguage-NOTFOUND », nécessaire pour « lib/libkdev4pythonparser.so ». Arrêt.
    make[1]: *** [parser/CMakeFiles/kdev4pythonparser.dir/all] Erreur 2
    make: *** [all] Erreur 2

    Could you help me ? Thanks.

    ReplyDelete
  6. Hi,

    it seems that it doesn't find kdevplatform. Did you install kdevplatform from git, maybe best into the same directory (-DCMAKE_INSTALL_DIR) like the plugin?

    Cheers,
    Sven

    ReplyDelete
  7. Thanks for your answer.

    Yes, I have install kdevplatform from git, but I don't understand how to use "-DCMAKE_INSTALL_DIR"...

    Bruno

    ReplyDelete
  8. You should do something like this:
    $ cd kdevplatform
    $ cd build
    $ cmake .. -DCMAKE_INSTALL_PREFIX=~/install #or anything else
    $ make install
    $ cd ../../kdevelop
    $ cd build
    $ cmake .. -DCMAKE_INSTALL_PREFIX=~/install
    $ make install
    $ cd ../../kdev-python
    $ cd build
    $ cmake .. -DCMAKE_INSTALL_PREFIX=~/install
    $ make parser
    $ make install
    $ kbuildsycoca4 --noincremental

    Always look out for error messages, i.e. cmake should notice and tell you when libraries are missing.

    ReplyDelete
  9. I don't know what's wrong, but the result is :

    Scanning dependencies of target kdevpythonlanguagesupport_automoc
    [ 0%] Built target kdevpythonlanguagesupport_automoc
    Scanning dependencies of target kdev4pythonparser_automoc
    [ 0%] Built target kdev4pythonparser_automoc
    Scanning dependencies of target kdev4pythonparser
    [ 2%] Building CXX object parser/CMakeFiles/kdev4pythonparser.dir/kdev4pythonparser_automoc.cpp.o
    [ 5%] Building CXX object parser/CMakeFiles/kdev4pythonparser.dir/parsesession.cpp.o
    [ 8%] Building CXX object parser/CMakeFiles/kdev4pythonparser.dir/ast.cpp.o
    [ 11%] Building CXX object parser/CMakeFiles/kdev4pythonparser.dir/astdefaultvisitor.cpp.o
    [ 13%] Building CXX object parser/CMakeFiles/kdev4pythonparser.dir/astvisitor.cpp.o
    [ 16%] Building CXX object parser/CMakeFiles/kdev4pythonparser.dir/astbuilder.cpp.o
    [ 19%] Building CXX object parser/CMakeFiles/kdev4pythonparser.dir/pythondriver.cpp.o
    make[2]: *** Pas de règle pour fabriquer la cible « KDevPlatformImport__kdevplatformlanguage-NOTFOUND », nécessaire pour « lib/libkdev4pythonparser.so ». Arrêt.
    make[1]: *** [parser/CMakeFiles/kdev4pythonparser.dir/all] Erreur 2
    make: *** [all] Erreur 2

    ReplyDelete
  10. As this is probably not of huge public concern, could you please email me for further discussion? Thanks.
    Attaching the whole output of the cmake command might be helpful.

    ReplyDelete
  11. Your help will be much appreciated. Thanks

    Missing pyconfig.h???

    Building on Ubuntu 11.04.


    [ 2%] Building CXX object parser/CMakeFiles/kdev4pythonparser.dir/astbuilder.cpp.o
    In file included from /home/isaacs/localprojects/kdevelop4/kdev-python/parser/astbuilder.cpp:46:0:
    /home/isaacs/localprojects/kdevelop4/kdev-python/python-src/Include/pyport.h:4:48: fatal error: pyconfig.h: No such file or directory
    compilation terminated.
    make[2]: *** [parser/CMakeFiles/kdev4pythonparser.dir/astbuilder.cpp.o] Error 1
    make[1]: *** [parser/CMakeFiles/kdev4pythonparser.dir/all] Error 2
    make: *** [all] Error 2

    -----------------


    $ locate pyconfig.h
    /home/isaacs/localprojects/kdevelop4/kdev-python/python-src/pyconfig.h.in
    /usr/include/python2.6/pyconfig.h
    /usr/include/python2.7/pyconfig.h

    ReplyDelete
  12. Did you follow the instructions in the INSTALL file? It seems not. :)
    Also, please use the "alpha2" tag, current master is broken (sorry).

    Cheers,
    Sven

    ReplyDelete
  13. Ooops... my bad. Seems I missed the "parser" target and instead ran make with no target.

    Thanks

    Steve

    ReplyDelete
  14. Hi,

    I compiled and installed the code without any errors but I cannot see it in the plugins page in the settings and the autocomplete feature (or anything that would indicate the plugin is running) does not work. Am I missing something very trivial?

    Thanks again for your effort. It looks very promising (from the screenshots :) )

    Best,
    Cetin

    ReplyDelete
  15. Hi,

    Make sure you're running the vey latest version of kdevelop and kdevplatform (from git). Also verify that KDEDIRS is set correctly and that you ran kbuildsycoca after setting it.

    Greetings

    ReplyDelete
  16. I'm sorry, what KDevelop release I need to use this plugin? For now I'm using 4.2.3 version, but I'm not sure it is the very latest one.

    ReplyDelete
  17. Hi,

    for the newest version of the plugin, you need kdevplatform 1.3 beta, which is tagged "v1.2.80" or similar. This is only available in git.
    1.2.3 (or 4.2.3 for kdevelop) is the latest stable version, but is quite old and will be replaced by a new release in a few days.

    Greetings

    ReplyDelete
  18. Thank you, very much! By the way, I've discovered the plugin in openSUSE unstable KDE repository, looks like it is close to be pushed to upstream :)

    ReplyDelete
  19. That's nice to hear! Still, it's very brave to push something to upstream which has not seen a release yet... ;p

    ReplyDelete
  20. Oops, my mistake. It's not in unstable, but in playground, so not so brave ;)

    ReplyDelete
  21. Hi , I got two bug when trying to install,
    first he was asking for kdevPlatform 1.2.60 which do not exist, i fixed it in modifing cmake/FindKDevPlatform.cmake replacing in line 41 with the current version of it. But now during the make install, i got stuck with this:

    /home/lois/.local/share/Trash/files/kdev-python/kdev-python/duchain/declarationbuilder.cpp:246:13: instantiated from ‘T* Python::DeclarationBuilder::visitVariableDeclaration(Python::Identifier*, Python::Ast*, KDevelop::Declaration*) [with T = KDevelop::Declaration]’
    /home/lois/.local/share/Trash/files/kdev-python/kdev-python/duchain/declarationbuilder.cpp:570:74: instantiated from here
    /home/lois/.local/share/Trash/files/kdev-python/kdev-python/duchain/declarationbuilder.h:59:9: error: ‘class KDevelop::Declaration’ has no member named ‘setAlwaysForceDirect’
    make[2]: *** [duchain/CMakeFiles/kdev4pythonduchain.dir/declarationbuilder.cpp.o] Error 1
    make[1]: *** [duchain/CMakeFiles/kdev4pythonduchain.dir/all] Error 2
    make: *** [all] Error 2
    and there i do not now what to do?

    Thanks

    ReplyDelete
    Replies
    1. You're trying to build against kdevplatform 1.2. This does not work. You need kdevplatform 1.3, which you can either build yourself from git or wait for the release which should happen in a few days.

      Delete
    2. Lol, just reading the whole post -- you edited the cmake file to require an older version of kdevplatform, and now you noticed it doesn't work with that? ;p
      I didn't put the line which requires 1.2.60 there for fun (yes, 1.2.60 doesn't exist, but 1.2.80 does and that's what you need)... :)

      Delete
  22. I think I've install it now (yes in a better way :p ) but it don't appear in Kdevelop

    ReplyDelete
    Replies
    1. Do you have kdevplatform 1.3 (not 1.2, and not 1.4)?
      Do you have the plugin installation directory in your KDEDIRS?
      Did you run kbuildsycoca --noincremental after fulfilling the other two requirements?
      It should work, then...

      Delete
    2. I'm sure to have kdevplatfrom 1.2.3 but how do i check for KDEDIR?

      Delete
  23. You don't need kdevplatform 1.2.3. It's too old. You need kdevplatform 1.3. one point three.
    Greetings

    ReplyDelete
    Replies
    1. For now, when i check in the help section of kdevelop i get
      Kdevplatfrom 1.3.60
      Kdevelop 4.3.60

      I get an coloration for python (wich i assume come from kate)

      But i do not have any of the stuff you show up there

      I have install the python plugin so what am i missing

      Delete
    2. And when I try with PHP plugin, i have no problem

      Delete
    3. Hi,

      yes, that's what the newest post in this blog is about, I didn't yet port the plugin to 1.4 beta (and 1.3.60 is 1.4 beta). If you compiled from svn, get version 1.3 beta by issuing
      git checkout v1.2.82
      *or* adjust the x-kdevelop-version in the python .desktop file (increase it by one) to make it work with 1.4 (i.e. 1.3.60).

      The KDE policy of having a.b.(large number) be the beta version of a.b+1 is a bit confusing, that's true.

      Greetings

      Delete
  24. hi,
    I have installed kdevelop 4.3.1 and kdevplatform 1.3.1. Built the python plugin. There were no errors. BUt I am not able to see the plugin.
    My KDEDIRS is pointing to the installation path of kdevelop.
    Is there anything else I need to do ?

    - Sameer

    ReplyDelete
    Replies
    1. Hello,

      the current master branch of the plugin needs the current kdevelop / kdevplatform 4.4 beta in order to work. Sorry about that.

      Greetings

      Delete
  25. Thanks for your reply..

    Would you kindly advise then which version of the python plugin I must use to suit my kdevplatform/kdev combination ?

    Regards
    Sameer

    ReplyDelete
    Replies
    1. Hi there,

      there's a branch called "1.3" in kdev-python which you can use with kdevelop / kdevplatform 4.3. However, some grave bugs have been fixed since and there's a lot of new features which are not available in that branch. For trying the plugin out it should be sufficient, tough.
      The release of kdevelop 4.4 is not too far away, so you'll probably be able to use the master branch of the python plugin with your distribution's packages for kdevelop/kdevplatform soon.

      Greetings,
      Sven

      Delete
  26. Do you have to register or install the compiled plugin? I just used git and compiled kdevelop, kdevplatform, kdev-python and I don't believe the plugin is showing up in kdevelop. All went well with the compile, It is kdevelop 4.6, it runs fine, just no Python. I have another packaged version installed on a different computer and when I open a python file it has many colors. This one looks like regular text highlighting.

    ReplyDelete
    Replies
    1. Make sure you have the current master of kdev-python compiled (1.5 or 1.4 won't load in kdevelop 4.6).

      Also, you have to do this if your installation prefix is not your default (system) KDE prefix:
      export KDEDIRS=[install prefix of kdev-python, e.g. /usr/local]
      kbuildsycoca4
      Then try running kdevelop from the same terminal session.

      Greetings,
      Sven

      Delete
  27. This article gives the light in which we can observe the reality. This is very nice one and gives indepth information. Thanks for this nice article.
    Sprachföderung im Kindergarten

    ReplyDelete

Note: Only a member of this blog may post a comment.