From 6391a6d64cf93e9ac5dd63e66df2c46065b44a24 Mon Sep 17 00:00:00 2001 From: ckunki Date: Fri, 4 Apr 2025 16:51:08 +0200 Subject: [PATCH 1/8] #397: Fixed handling empty coverage --- doc/changes/unreleased.md | 4 ++++ exasol/toolbox/metrics.py | 20 ++++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/doc/changes/unreleased.md b/doc/changes/unreleased.md index 79e701b844..92059e1e86 100644 --- a/doc/changes/unreleased.md +++ b/doc/changes/unreleased.md @@ -1 +1,5 @@ # Unreleased + +## Bugfixes + +* #397: Fix handling empty coverage diff --git a/exasol/toolbox/metrics.py b/exasol/toolbox/metrics.py index b5f57874ed..48a700f331 100644 --- a/exasol/toolbox/metrics.py +++ b/exasol/toolbox/metrics.py @@ -1,6 +1,7 @@ import datetime import json import re +import sys from collections import defaultdict from dataclasses import ( asdict, @@ -13,7 +14,7 @@ from functools import singledispatch from inspect import cleandoc from pathlib import Path -from subprocess import run +import subprocess from tempfile import TemporaryDirectory from typing import ( Any, @@ -99,16 +100,27 @@ class Report: security: Rating technical_debt: Rating - def total_coverage(file: Union[str, Path]) -> float: with TemporaryDirectory() as tmpdir: tmp_dir = Path(tmpdir) report = tmp_dir / "coverage.json" - run( + p = subprocess.run( ["coverage", "json", f"--data-file={file}", "-o", f"{report}"], capture_output=True, - check=True, + check=False, + encoding="utf-8", ) + stdout = p.stdout.strip() + if (p.returncode == 1) and (stdout == "No data to report."): + print( + f'The following command' + f' returned non-zero exit status {p.returncode}:\n' + f' {" ".join(p.args)}\n' + f'{stdout}\n' + 'Returning total coverage 100 %.', + file=sys.stderr, + ) + return 100.0 with open(report, encoding="utf-8") as r: data = json.load(r) total: float = data["totals"]["percent_covered"] From 8c36e63ace47cfe227fb5abc37f93988aac46940 Mon Sep 17 00:00:00 2001 From: ckunki Date: Fri, 4 Apr 2025 16:53:01 +0200 Subject: [PATCH 2/8] project:fix --- exasol/toolbox/metrics.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/exasol/toolbox/metrics.py b/exasol/toolbox/metrics.py index 48a700f331..11872692f0 100644 --- a/exasol/toolbox/metrics.py +++ b/exasol/toolbox/metrics.py @@ -1,6 +1,7 @@ import datetime import json import re +import subprocess import sys from collections import defaultdict from dataclasses import ( @@ -14,7 +15,6 @@ from functools import singledispatch from inspect import cleandoc from pathlib import Path -import subprocess from tempfile import TemporaryDirectory from typing import ( Any, @@ -100,6 +100,7 @@ class Report: security: Rating technical_debt: Rating + def total_coverage(file: Union[str, Path]) -> float: with TemporaryDirectory() as tmpdir: tmp_dir = Path(tmpdir) @@ -113,11 +114,11 @@ def total_coverage(file: Union[str, Path]) -> float: stdout = p.stdout.strip() if (p.returncode == 1) and (stdout == "No data to report."): print( - f'The following command' - f' returned non-zero exit status {p.returncode}:\n' + f"The following command" + f" returned non-zero exit status {p.returncode}:\n" f' {" ".join(p.args)}\n' - f'{stdout}\n' - 'Returning total coverage 100 %.', + f"{stdout}\n" + "Returning total coverage 100 %.", file=sys.stderr, ) return 100.0 From 15a806b85f1a2de0a7115f4d31b65b30113d39e0 Mon Sep 17 00:00:00 2001 From: ckunki Date: Fri, 4 Apr 2025 17:26:12 +0200 Subject: [PATCH 3/8] Disabled lint report --- .github/workflows/report.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/report.yml b/.github/workflows/report.yml index eb176da08d..f861894f02 100644 --- a/.github/workflows/report.yml +++ b/.github/workflows/report.yml @@ -52,6 +52,6 @@ jobs: poetry run -- nox -s project:report -- --format markdown >> $GITHUB_STEP_SUMMARY poetry run -- nox -s dependency:licenses >> $GITHUB_STEP_SUMMARY echo -e "\n\n# Coverage\n" >> $GITHUB_STEP_SUMMARY - poetry run coverage report -- --format markdown >> $GITHUB_STEP_SUMMARY - poetry run -- tbx lint pretty-print >> $GITHUB_STEP_SUMMARY + poetry run coverage report -- --format markdown >> $GITHUB_STEP_SUMMARY || true + # poetry run -- tbx lint pretty-print >> $GITHUB_STEP_SUMMARY poetry run -- tbx security pretty-print .security.json >> $GITHUB_STEP_SUMMARY From 0ba804c54bf471f9db2e85732c2df60a2fa6bf8f Mon Sep 17 00:00:00 2001 From: ckunki Date: Fri, 4 Apr 2025 17:26:27 +0200 Subject: [PATCH 4/8] re-enabled lint report --- .github/workflows/report.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/report.yml b/.github/workflows/report.yml index f861894f02..da8e6049f4 100644 --- a/.github/workflows/report.yml +++ b/.github/workflows/report.yml @@ -53,5 +53,5 @@ jobs: poetry run -- nox -s dependency:licenses >> $GITHUB_STEP_SUMMARY echo -e "\n\n# Coverage\n" >> $GITHUB_STEP_SUMMARY poetry run coverage report -- --format markdown >> $GITHUB_STEP_SUMMARY || true - # poetry run -- tbx lint pretty-print >> $GITHUB_STEP_SUMMARY + poetry run -- tbx lint pretty-print >> $GITHUB_STEP_SUMMARY poetry run -- tbx security pretty-print .security.json >> $GITHUB_STEP_SUMMARY From f830cc08d7407b9e18a8b7473a5fe3f971de9c3e Mon Sep 17 00:00:00 2001 From: ckunki Date: Fri, 4 Apr 2025 18:45:19 +0200 Subject: [PATCH 5/8] Ignored failure when reporting empty coverage --- exasol/toolbox/templates/github/workflows/report.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exasol/toolbox/templates/github/workflows/report.yml b/exasol/toolbox/templates/github/workflows/report.yml index 12b67cc399..7ba5ed1caa 100644 --- a/exasol/toolbox/templates/github/workflows/report.yml +++ b/exasol/toolbox/templates/github/workflows/report.yml @@ -31,7 +31,7 @@ jobs: # Errors during copying are ignored because they are checked in the next step cp .coverage ../ || true cp lint-python3.9/.lint.txt ../ || true - cp lint-python3.9/.lint.txt ../ || true + cp lint-python3.9/.lint.json ../ || true cp security-python3.9/.security.json ../ || true - name: Validate Artifacts @@ -52,6 +52,6 @@ jobs: poetry run -- nox -s project:report -- --format markdown >> $GITHUB_STEP_SUMMARY poetry run -- nox -s dependency:licenses >> $GITHUB_STEP_SUMMARY echo -e "\n\n# Coverage\n" >> $GITHUB_STEP_SUMMARY - poetry run coverage report -- --format markdown >> $GITHUB_STEP_SUMMARY + poetry run coverage report -- --format markdown >> $GITHUB_STEP_SUMMARY || true poetry run -- tbx lint pretty-print >> $GITHUB_STEP_SUMMARY poetry run -- tbx security pretty-print .security.json >> $GITHUB_STEP_SUMMARY From 96a293ae61f6ffbb9080f113677a02c4ab639232 Mon Sep 17 00:00:00 2001 From: ckunki Date: Fri, 4 Apr 2025 18:46:25 +0200 Subject: [PATCH 6/8] moved double dash to front --- exasol/toolbox/templates/github/workflows/report.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exasol/toolbox/templates/github/workflows/report.yml b/exasol/toolbox/templates/github/workflows/report.yml index 7ba5ed1caa..b7a513232e 100644 --- a/exasol/toolbox/templates/github/workflows/report.yml +++ b/exasol/toolbox/templates/github/workflows/report.yml @@ -52,6 +52,6 @@ jobs: poetry run -- nox -s project:report -- --format markdown >> $GITHUB_STEP_SUMMARY poetry run -- nox -s dependency:licenses >> $GITHUB_STEP_SUMMARY echo -e "\n\n# Coverage\n" >> $GITHUB_STEP_SUMMARY - poetry run coverage report -- --format markdown >> $GITHUB_STEP_SUMMARY || true + poetry run -- coverage report --format markdown >> $GITHUB_STEP_SUMMARY || true poetry run -- tbx lint pretty-print >> $GITHUB_STEP_SUMMARY poetry run -- tbx security pretty-print .security.json >> $GITHUB_STEP_SUMMARY From 3ec4be7bf2f38baf589426168a67cf93220da5b5 Mon Sep 17 00:00:00 2001 From: Christoph Kuhnke Date: Mon, 7 Apr 2025 10:58:28 +0200 Subject: [PATCH 7/8] Apply suggestions from code review Co-authored-by: Ariel Schulz <43442541+ArBridgeman@users.noreply.github.com> --- .github/workflows/report.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/report.yml b/.github/workflows/report.yml index da8e6049f4..b1670ed7cb 100644 --- a/.github/workflows/report.yml +++ b/.github/workflows/report.yml @@ -52,6 +52,6 @@ jobs: poetry run -- nox -s project:report -- --format markdown >> $GITHUB_STEP_SUMMARY poetry run -- nox -s dependency:licenses >> $GITHUB_STEP_SUMMARY echo -e "\n\n# Coverage\n" >> $GITHUB_STEP_SUMMARY - poetry run coverage report -- --format markdown >> $GITHUB_STEP_SUMMARY || true + poetry run -- coverage report --format markdown >> $GITHUB_STEP_SUMMARY || true poetry run -- tbx lint pretty-print >> $GITHUB_STEP_SUMMARY poetry run -- tbx security pretty-print .security.json >> $GITHUB_STEP_SUMMARY From bdccf11f5cc5996c445cb9659fd8735b72dccde0 Mon Sep 17 00:00:00 2001 From: ckunki Date: Sat, 5 Apr 2025 08:25:18 +0200 Subject: [PATCH 8/8] Updated template for file .gitignore --- project-template/{{cookiecutter.repo_name}}/.gitignore | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/project-template/{{cookiecutter.repo_name}}/.gitignore b/project-template/{{cookiecutter.repo_name}}/.gitignore index fdfb6de9f1..ca472841cb 100644 --- a/project-template/{{cookiecutter.repo_name}}/.gitignore +++ b/project-template/{{cookiecutter.repo_name}}/.gitignore @@ -142,4 +142,10 @@ doc/api itde/ # Emacs -TAGS +/TAGS + +# PTB +/.lint.json +/.lint.txt +/.security.json +