Skip to content

Commit f562ff2

Browse files
authored
Make htmlreport installable single package (#6335)
For example, with `pipx` you can install `cppcheck-htmlreport` executable as follow: ```py pipx install "git+https://github.com/vpetrigo/cppcheck@feature/installable_htmlreport#subdirectory=htmlreport" ``` That also allows populating `Pygments` into user's environment automatically. No need to switch to the `htmlreport` and execute `pip install .` or something. After that the user is able to use `cppcheck-htmlreport` without installation of DEB/RPM packages. Moreover, on Windows it allows usage of this utility withot necessity to execute it like that, because shebans are not supported there: ```bash python <path/to/script>/cppcheck-htmlreport ```
1 parent a26b16d commit f562ff2

12 files changed

Lines changed: 78 additions & 48 deletions

File tree

.github/workflows/scriptcheck.yml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,23 @@ jobs:
143143
env:
144144
PYTHONPATH: ./addons
145145

146-
- name: test htmlreport
146+
- name: test htmlreport (standalone)
147147
run: |
148-
htmlreport/test_htmlreport.py
149-
cd htmlreport
148+
test/tools/htmlreport/test_htmlreport.py
149+
cd test/tools/htmlreport
150+
./check.sh
151+
# Python 3.5 and 3.6 are excluded as they are not supported by setuptools-scm package for getting
152+
# package version
153+
- name: test htmlreport (pip)
154+
if: matrix.python-version != '3.5' && matrix.python-version != '3.6'
155+
run: |
156+
python -m venv venv
157+
source venv/bin/activate
158+
python -m pip install -U pip
159+
pip install ./htmlreport/
160+
which cppcheck-htmlreport
161+
PIP_PACKAGE_TEST=1 test/tools/htmlreport/test_htmlreport.py
162+
cd test/tools/htmlreport
150163
./check.sh
151164
152165
- name: test reduce

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,11 @@ compile_commands.json
134134
/oss-fuzz/corpus
135135
/oss-fuzz/corpus_
136136
/oss-fuzz/samples
137+
138+
# Python
139+
/.venv/
140+
/venv/
141+
**/*.egg-info/
142+
143+
# cppcheck-htmlreport auto files
144+
/htmlreport/cppcheck_htmlreport/run.py

htmlreport/cppcheck-htmlreport

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ class CppCheckHandler(XmlContentHandler):
616616
'info': attributes.get('info')
617617
})
618618

619-
if __name__ == '__main__':
619+
def main() -> None:
620620
# Configure all the options this little utility is using.
621621
parser = optparse.OptionParser()
622622
parser.add_option('--title', dest='title',
@@ -984,3 +984,7 @@ if __name__ == '__main__':
984984
stats_file.write(HTML_FOOTER % contentHandler.versionCppcheck)
985985

986986
print("\nOpen '" + options.report_dir + "/index.html' to see the results.")
987+
988+
989+
if __name__ == "__main__":
990+
main()

htmlreport/cppcheck_htmlreport/__init__.py

Whitespace-only changes.

htmlreport/setup.py

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,31 @@
11
#!/usr/bin/env python3
2+
import shutil
3+
from setuptools import find_packages, setup
24

3-
from setuptools import setup
4-
5-
with open('README.txt') as f:
5+
with open("README.txt") as f:
66
readme = f.read()
77

8+
shutil.copy("cppcheck-htmlreport", "cppcheck_htmlreport/run.py")
9+
810
setup(
9-
name="cppcheck",
10-
description='Python script to parse the XML (version 2) output of ' +
11-
'cppcheck and generate an HTML report using Pygments for syntax ' +
12-
'highlighting.',
11+
name="cppcheck-htmlreport",
12+
description=(
13+
"Python script to parse the XML (version 2) output of "
14+
"cppcheck and generate an HTML report using Pygments for syntax "
15+
"highlighting."
16+
),
1317
long_description=readme,
14-
author='Henrik Nilsson',
15-
url='https://github.com/danmar/cppcheck',
16-
license='GPL',
17-
scripts=[
18-
"cppcheck-htmlreport",
19-
],
20-
install_requires=['Pygments']
18+
author="Cppcheck Team",
19+
url="https://github.com/danmar/cppcheck",
20+
license="GPL",
21+
packages=find_packages(exclude=("tests", "docs")),
22+
use_scm_version={"root": ".."},
23+
entry_points={
24+
"console_scripts": [
25+
"cppcheck-htmlreport = cppcheck_htmlreport:run.main",
26+
]
27+
},
28+
install_requires=["Pygments"],
29+
# Required by setuptools-scm 7.0 for Python 3.7+
30+
setup_requires=["setuptools>=60", "setuptools-scm>=7.0"],
2131
)

htmlreport/test_suppressions.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

htmlreport/tox.ini

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,49 +26,52 @@ if [ -z "$PYTHON" ]; then
2626
PYTHON=python
2727
fi
2828

29+
SCRIPT_DIR="$(dirname ${BASH_SOURCE[0]})"
30+
ABSOLUTE_SCRIPT_DIR="$(cd -- ${SCRIPT_DIR} ; pwd -P)"
31+
PROJECT_ROOT_DIR="$(cd -- ${SCRIPT_DIR}/../../../ ; pwd -P)"
2932
REPORT_DIR=$(mktemp -d -t htmlreport-XXXXXXXXXX)
3033
INDEX_HTML="$REPORT_DIR/index.html"
3134
STATS_HTML="$REPORT_DIR/stats.html"
3235
GUI_TEST_XML="$REPORT_DIR/gui_test.xml"
3336
ERRORLIST_XML="$REPORT_DIR/errorlist.xml"
3437
UNMATCHEDSUPPR_XML="$REPORT_DIR/unmatchedSuppr.xml"
3538

36-
$PYTHON cppcheck-htmlreport --file ../gui/test/data/xmlfiles/xmlreport_v2.xml --title "xml2 test" --report-dir "$REPORT_DIR" --source-dir ../test/
39+
$PYTHON ${PROJECT_ROOT_DIR}/htmlreport/cppcheck-htmlreport --file ${PROJECT_ROOT_DIR}/gui/test/data/xmlfiles/xmlreport_v2.xml --title "xml2 test" --report-dir "$REPORT_DIR" --source-dir ${PROJECT_ROOT_DIR}/test/
3740
echo -e "\n"
3841
# Check HTML syntax
3942
validate_html "$INDEX_HTML"
4043
validate_html "$STATS_HTML"
4144

4245

43-
../cppcheck ../samples --enable=all --inconclusive --xml-version=2 2> "$GUI_TEST_XML"
46+
${PROJECT_ROOT_DIR}/cppcheck ${PROJECT_ROOT_DIR}/samples --enable=all --inconclusive --xml-version=2 2> "$GUI_TEST_XML"
4447
xmllint --noout "$GUI_TEST_XML"
45-
$PYTHON cppcheck-htmlreport --file "$GUI_TEST_XML" --title "xml2 + inconclusive test" --report-dir "$REPORT_DIR"
48+
$PYTHON ${PROJECT_ROOT_DIR}/htmlreport/cppcheck-htmlreport --file "$GUI_TEST_XML" --title "xml2 + inconclusive test" --report-dir "$REPORT_DIR"
4649
echo ""
4750
# Check HTML syntax
4851
validate_html "$INDEX_HTML"
4952
validate_html "$STATS_HTML"
5053

5154

52-
../cppcheck ../samples --enable=all --inconclusive --verbose --xml-version=2 2> "$GUI_TEST_XML"
55+
${PROJECT_ROOT_DIR}/cppcheck ${PROJECT_ROOT_DIR}/samples --enable=all --inconclusive --verbose --xml-version=2 2> "$GUI_TEST_XML"
5356
xmllint --noout "$GUI_TEST_XML"
54-
$PYTHON cppcheck-htmlreport --file "$GUI_TEST_XML" --title "xml2 + inconclusive + verbose test" --report-dir "$REPORT_DIR"
57+
$PYTHON ${PROJECT_ROOT_DIR}/htmlreport/cppcheck-htmlreport --file "$GUI_TEST_XML" --title "xml2 + inconclusive + verbose test" --report-dir "$REPORT_DIR"
5558
echo -e "\n"
5659
# Check HTML syntax
5760
validate_html "$INDEX_HTML"
5861
validate_html "$STATS_HTML"
5962

6063

61-
../cppcheck --errorlist --inconclusive --xml-version=2 > "$ERRORLIST_XML"
64+
${PROJECT_ROOT_DIR}/cppcheck --errorlist --inconclusive --xml-version=2 > "$ERRORLIST_XML"
6265
xmllint --noout "$ERRORLIST_XML"
63-
$PYTHON cppcheck-htmlreport --file "$ERRORLIST_XML" --title "errorlist" --report-dir "$REPORT_DIR"
66+
$PYTHON ${PROJECT_ROOT_DIR}/htmlreport/cppcheck-htmlreport --file "$ERRORLIST_XML" --title "errorlist" --report-dir "$REPORT_DIR"
6467
# Check HTML syntax
6568
validate_html "$INDEX_HTML"
6669
validate_html "$STATS_HTML"
6770

6871

69-
../cppcheck ../samples/memleak/good.c ../samples/resourceLeak/good.c --xml-version=2 --enable=information --suppressions-list=test_suppressions.txt --xml 2> "$UNMATCHEDSUPPR_XML"
72+
${PROJECT_ROOT_DIR}/cppcheck ${PROJECT_ROOT_DIR}/samples/memleak/good.c ${PROJECT_ROOT_DIR}/samples/resourceLeak/good.c --xml-version=2 --enable=information --suppressions-list="${ABSOLUTE_SCRIPT_DIR}/test_suppressions.txt" --xml 2> "$UNMATCHEDSUPPR_XML"
7073
xmllint --noout "$UNMATCHEDSUPPR_XML"
71-
$PYTHON cppcheck-htmlreport --file "$UNMATCHEDSUPPR_XML" --title "unmatched Suppressions" --report-dir="$REPORT_DIR"
74+
$PYTHON ${PROJECT_ROOT_DIR}/htmlreport/cppcheck-htmlreport --file "$UNMATCHEDSUPPR_XML" --title "unmatched Suppressions" --report-dir="$REPORT_DIR"
7275
grep "unmatchedSuppression<.*>information<.*>Unmatched suppression: variableScope*<" "$INDEX_HTML"
7376
grep ">unmatchedSuppression</.*>information<.*>Unmatched suppression: uninitstring<" "$INDEX_HTML"
7477
grep "notexisting" "$INDEX_HTML"

0 commit comments

Comments
 (0)