Skip to content

Commit 5a0df94

Browse files
resolve conversation
1 parent 481da6b commit 5a0df94

File tree

4 files changed

+179
-153
lines changed

4 files changed

+179
-153
lines changed

exasol/toolbox/nox/_artifacts.py

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import json
2+
import pathlib
3+
import sqlite3
4+
import sys
5+
from pathlib import Path
6+
7+
import nox
8+
from nox import Session
9+
10+
from noxconfig import PROJECT_CONFIG
11+
12+
13+
@nox.session(name="artifacts:validate", python=False)
14+
def check_artifacts(session: Session) -> None:
15+
"""Validate that all project artifacts are available and consistent"""
16+
if not_available := _missing_files(
17+
{".lint.json", ".lint.txt", ".security.json", ".coverage"}, PROJECT_CONFIG.root
18+
):
19+
print(f"not available: {not_available}")
20+
sys.exit(1)
21+
22+
error = False
23+
if msg := _validate_lint_json(Path(PROJECT_CONFIG.root, ".lint.json")):
24+
print(f"error in [.lint.json]: {msg}")
25+
error = True
26+
if msg := _validate_security_json(Path(PROJECT_CONFIG.root, ".security.json")):
27+
print(f"error in [.security.json]: {msg}")
28+
error = True
29+
if msg := _validate_coverage(Path(PROJECT_CONFIG.root, ".coverage")):
30+
print(f"error in [.coverage]: {msg}")
31+
error = True
32+
if error:
33+
sys.exit(1)
34+
35+
36+
def _missing_files(expected_files: set, directory: Path) -> set:
37+
files = {f.name for f in directory.iterdir() if f.is_file()}
38+
return expected_files - files
39+
40+
41+
def _validate_lint_json(file: Path) -> str:
42+
try:
43+
content = file.read_text()
44+
except FileNotFoundError as ex:
45+
return f"Could not find file {file}, details: {ex}"
46+
try:
47+
issues = json.loads(content)
48+
except json.JSONDecodeError as ex:
49+
return f"Invalid json file, details: {ex}"
50+
expected = {
51+
"type",
52+
"module",
53+
"obj",
54+
"line",
55+
"column",
56+
"endLine",
57+
"endColumn",
58+
"path",
59+
"symbol",
60+
"message",
61+
"message-id",
62+
}
63+
for number, issue in enumerate(issues):
64+
actual = set(issue.keys())
65+
missing = expected - actual
66+
if len(missing) > 0:
67+
return (
68+
f"Invalid format, issue {number} is missing the following attributes {missing}"
69+
)
70+
return ""
71+
72+
73+
def _validate_security_json(file: Path) -> str:
74+
try:
75+
content = file.read_text()
76+
except FileNotFoundError as ex:
77+
return f"Could not find file {file}, details: {ex}"
78+
try:
79+
actual = set(json.loads(content))
80+
except json.JSONDecodeError as ex:
81+
return f"Invalid json file, details: {ex}"
82+
expected = {"errors", "generated_at", "metrics", "results"}
83+
missing = expected - actual
84+
if len(missing) > 0:
85+
return (
86+
f"Invalid format, the file is missing the following attributes {missing}"
87+
)
88+
return ""
89+
90+
91+
def _validate_coverage(path: Path) -> str:
92+
try:
93+
conn = sqlite3.connect(path)
94+
except sqlite3.Error as ex:
95+
return f"database connection not possible, details: {ex}"
96+
cursor = conn.cursor()
97+
try:
98+
actual_tables = set(cursor.execute("select name from sqlite_schema where type == 'table'"))
99+
except sqlite3.Error as ex:
100+
return f"schema query not possible, details: {ex}"
101+
expected = {"coverage_schema", "meta", "file", "line_bits"}
102+
actual = {f[0] for f in actual_tables if (f[0] in expected)}
103+
missing = expected - actual
104+
if len(missing) > 0:
105+
return f"Invalid database, the database is missing the following tables {missing}"
106+
return ""
107+

exasol/toolbox/nox/_gh.py

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

exasol/toolbox/nox/tasks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ def check(session: Session) -> None:
6666
_version,
6767
python_files,
6868
)
69-
from exasol.toolbox.nox._gh import (
70-
check_lint_files
69+
from exasol.toolbox.nox._artifacts import (
70+
check_artifacts
7171
)
7272
# isort: on
7373
# fmt: on

0 commit comments

Comments
 (0)