add python support to write rules

Issue #27 resolved
Gaëtan Lehmann created an issue

some work already done in the python branch

Comments (15)

  1. Gaëtan Lehmann reporter

    I have a few changes locally to allow to select a python rule over a tcl rule, but nothing ready to be committed yet. The feature may come to the master branch soon, but the next vera++ won't happen before several weeks (maybe months). Do you need that feature soon?

  2. Alejandro Claro Mosqueda

    I'm very interested in this feature. We used to write all the project scripts in Phyton. Vera++ rules is the only exception.

  3. Gaëtan Lehmann reporter

    I've just made the python script usable and added a few tests in 00aba85. The python feature seems good enough to me for more testing, so I've merged the python branch in the master branch. The feature is still experimental, so it is disabled by default.

    Note that I'd like to not reimplement the existing tcl rules in python in order to avoid maintaining both the python and the tcl versions. New rules written in python would be welcome though :-)

    Your feedbacks would be very useful!

  4. Alejandro Claro Mosqueda

    Hi Mr ehmann,

    I have some problems with the change.

    1. The CMake script is not able to find the python library. I have to add -lpython2.7 by hand.

    2. The python interpreter try to load the module name "vera" as a shared library in interpreter.cpp:

    main_namespace["vera"] = py::import("vera");

    If it is no present it produces a segmentation fault. May be there is a way to tell python switch file to load.

  5. Gaëtan Lehmann reporter
    1. I've fixed a small bug in a9ac87c — that may help. Could you clean your build dir and retry?

    2. This line is there only to avoid the need to import vera in the python rules. The module should be already loaded, so this line only make the module available in the script.

  6. Alejandro Claro Mosqueda

    Thanks Gaëtan,

    I will check it out. I fix it adding 'find_package(PythonLibs 2.7 REQUIRED)' to the cmake script. It look like a problem in systems with multiples python version (2.7 and 3.2 in my case).

  7. skaluzka

    hi,

    currently we can see below infor on changenote wiki page:

    "experimental Python and Lua support - they are not turned on by default and their API may change without keeping the backward compatibility in the future."

    I have one related question: how to turn that python support on? I guess some extra configuration is needed during build process. are you able to share more details? thanks in advance

  8. skaluzka

    thanks a lot. it works very well, here are some additional details. according to your suggestion I made below change in src/CMakeLists.txt file:

    -option(VERA_PYTHON "Build Python rules support" OFF)
    +option(VERA_PYTHON "Build Python rules support" ON)
    

    and I built vera. next I prepared simple rule called sk0001.py (inside rules/ dir):

    # detecting tabs
    for f in vera.getSourceFileNames():
        for lineNumber, line in enumerate(vera.getAllLines(f)):
            if '\t' in line:
                vera.report(f, lineNumber+1, "found tab character")
    

    and test file with some tabs inside. after run vera reports perfectly what I want:

    [skaluzka@arch vera]$ vera++ -sSR sk0001 test.cpp 
    test.cpp:2: sk0001: found tab character
    test.cpp:3: sk0001: found tab character
    test.cpp:4: sk0001: found tab character
    1 reports in 1 files.
    [skaluzka@arch vera]$ 
    
  9. Log in to comment