Code report
The following analysing modules (analysers) are currently added to Universum:
Analysers are separate scripts, fully compatible with Universum. It is possible to use them as independent Python modules.
All analysers must have an argument for JSON file with analysis results. If you run code report independently, the name must conform to file name standards.
Running analysers from Universum config, you need to add code_report=True
and result file argument
mandatory must be set to "${CODE_REPORT_FILE}"
.
"${CODE_REPORT_FILE}"
is a pseudo-variable that will be replaced with the file name during execution.
Also, without code_report=True
and result file may be called any name, as it won’t be processed according
to the rules defined for analysers. Such step will be marked as Failed
if any analysis issues are found.
Do note that you can also directly submit results generated by static analyzers, which are not supported by the Universum. Provided data shall be parsed and found issues shall be processed and reported, given that file conforms to the following pylint-like json schema:
"issues": {
"type": "array",
"items": {
"type": "object",
"required": [ "path", "line", "message", "symbol" ],
"properties": {
"path": { "type": "string" },
"line": { "type": "number" },
"message": { "type": "string" },
"symbol": { "type": "string" }
}
}
}
Alternatively, report file can conform to SARIF schema: https://docs.oasis-open.org/sarif/sarif/v2.0/sarif-v2.0.html
To provide such report directly, you need to place/copy the pre-formatted file in "${CODE_REPORT_FILE}"
location.
from universum.configuration_support import Configuration, Step
configs = Configuration([Step(name="Direct report", code_report=True, report_artifacts='${CODE_REPORT_FILE}',
command=f"cp /my_path/my_report.json ${{CODE_REPORT_FILE}}")])
Note
When using Universum, if a file with analysis results is not added to artifacts, it will be deleted along with other build sources and results.
When using via Universum code_report=True
step, use --report-to-review
functionality to comment on any found issues to code review system.
Pylint
Pylint analyzer
usage: python3.8 -m universum.analyzers.pylint [-h] [--rcfile RCFILE]
[--python-version VERSION]
Named Arguments
- --rcfile
Specify a configuration file.
- --python-version
Version of the python interpreter, such as 2, 3 or 3.7. Pylint analyzer uses this parameter to select python binary for launching pylint. For example, if the version is 3.7, it uses the following command: ‘python3.7 -m pylint <…>’
Default: “3”
Config example for universum.analyzers.pylint
:
from universum.configuration_support import Configuration, Step
configs = Configuration([Step(name="pylint", code_report=True, command=[
"python3.8", "-m", "universum.analyzers.pylint", "--python-version", "2.7",
"--result-file", "${CODE_REPORT_FILE}", "--files", "*.py", "examples/"
])])
if __name__ == '__main__':
print(configs.dump())
This file will get us the following list of configurations:
$ ./.universum.py
[{'name': 'pylint', 'code_report': True, 'command': 'python3.8 -m universum.analyzers.pylint --python-version 2.7 --result-file ${CODE_REPORT_FILE} --files *.py examples/'}]
Mypy
Mypy analyzer
usage: python3.8 -m universum.analyzers.mypy [-h] [--config-file CONFIG_FILE]
[--python-version VERSION]
Named Arguments
- --config-file
Specify a configuration file.
- --python-version
Version of the python interpreter, such as 2, 3 or 3.7. Pylint analyzer uses this parameter to select python binary for launching pylint. For example, if the version is 3.7, it uses the following command: ‘python3.7 -m pylint <…>’
Default: “3”
Config example for universum.analyzers.mypy
:
from universum.configuration_support import Configuration, Step
configs = Configuration([Step(name="mypy", code_report=True, command=[
"python3.8", "-m", "universum.analyzers.mypy", "--python-version", "3",
"--result-file", "${CODE_REPORT_FILE}", "--files", "*.py", "examples/"
])])
if __name__ == '__main__':
print(configs.dump())
This file will get us the following list of configurations:
$ ./.universum.py
[{'name': 'mypy', 'code_report': True, 'command': 'python3.8 -m universum.analyzers.mypy --python-version 3 --result-file ${CODE_REPORT_FILE} --files *.py examples/'}]
Uncrustify
Uncrustify analyzer
usage: python3.8 -m universum.analyzers.uncrustify [-h]
[--output-directory OUTPUT_DIRECTORY]
[--report-html]
[--cfg-file CFG_FILE]
Named Arguments
- --output-directory, -od
Directory to store fixed files and HTML files with diff; the default value is ‘uncrustify’. Has to be distinct from source directory
- --report-html
(optional) Set to generate html reports for each modified file
- --cfg-file, -cf
Name of the configuration file of Uncrustify; can also be set via ‘UNCRUSTIFY_CONFIG’ env. variable
Config example for universum.analyzers.uncrustify
:
from universum.configuration_support import Configuration, Step
configs = Configuration([Step(name="uncrustify", code_report=True, command=[
"python3.8", "-m", "universum.analyzers.uncrustify", "--files", "/home/user/workspace/temp/*.c",
"--cfg-file", "file_name.cfg", "--result-file", "${CODE_REPORT_FILE}", "--output-directory", "uncrustify"
])])
if __name__ == '__main__':
print(configs.dump())
will produce this list of configurations:
$ ./.universum.py
[{'name': 'uncrustify', 'code_report': True, 'command': 'python3.8 -m universum.analyzers.uncrustify --files /home/user/workspace/temp/*.c --cfg-file file_name.cfg --result-file ${CODE_REPORT_FILE} --output-directory uncrustify'}]
Clang-format
Clang-format analyzer
usage: python3.8 -m universum.analyzers.clang_format [-h]
[--output-directory OUTPUT_DIRECTORY]
[--report-html]
[--executable EXECUTABLE]
[--style STYLE]
Named Arguments
- --output-directory, -od
Directory to store fixed files and HTML files with diff; the default value is ‘clang-format’. Has to be distinct from source directory
- --report-html
(optional) Set to generate html reports for each modified file
- --executable, -e
The name of the clang-format executable, default: clang-format
- --style
The ‘style’ parameter of the clang-format. Can be literal ‘file’ string or path to real file. See the clang-format documentation for details.
Config example for universum.analyzers.clang_format
:
from universum.configuration_support import Configuration, Step
configs = Configuration([Step(name="clang-format", code_report=True, command=[
"python3.8", "-m", "universum.analyzers.clang-format", "--files", "/home/user/workspace/temp/*.c",
"--result-file", "${CODE_REPORT_FILE}", "--output-directory", "clang-format", "-e", "clang-format-15",
])])
if __name__ == '__main__':
print(configs.dump())
will produce this list of configurations:
$ ./.universum.py
[{'name': 'clang-format', 'code_report': True, 'command': 'python3.8 -m universum.analyzers.clang-format --files /home/user/workspace/temp/*.c --result-file ${CODE_REPORT_FILE} --output-directory clang-format -e clang-format-15'}]