add python support to write rules
some work already done in the python branch
Comments (15)
-
-
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?
-
I'm very interested in this feature. We used to write all the project scripts in Phyton. Vera++ rules is the only exception.
-
The same situation for a project that I am working on!
-
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!
-
Hi Mr ehmann,
I have some problems with the change.
-
The CMake script is not able to find the python library. I have to add -lpython2.7 by hand.
-
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.
-
-
reporter -
I've fixed a small bug in a9ac87c — that may help. Could you clean your build dir and retry?
-
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.
-
-
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).
-
reporter Thanks alcaro,
Hopefully 89b3202 should fix the problem.
-
reporter still have to write the documentation
-
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
-
reporter You can set VERA_PYTHON to ON in cmake and then just put your new rule with the .py extension with the other rules. There are two tests at https://bitbucket.org/verateam/vera/src/34415c6659d4e5d61315a51e8eab3c0b733834c8/tests/python/scripts/rules/?at=master that you can use as example.
-
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]$
-
reporter great, thanks for your feedback :-)
-
reporter - changed status to resolved
this is fully supported now!
- Log in to comment
hello,
is there any update for this issue?