PICurv 0.1.0
A Parallel Particle-In-Cell Solver for Curvilinear LES
Loading...
Searching...
No Matches
Functions | Variables
audit_user_facing_reporting Namespace Reference

Functions

str strip_c_comments (str text)
 Replace C comments while preserving source line positions.
 
list[str] audit_direct_c_output ()
 Return raw C console emissions outside their approved rendering modules.
 
list[str] require_fragments (Path path, tuple[str,...] fragments, str surface)
 Return missing reporting-contract fragments for one user-facing surface.
 
list[str] audit_cli_contract (dict contract)
 Verify that every declared CLI command has a parser, dispatch handler, and contextual message.
 
int main ()
 Audit C banner, CLI summaries, and direct-output routing.
 

Variables

 REPO_ROOT = Path(__file__).resolve().parents[2]
 
str SRC_DIR = REPO_ROOT / "src"
 
dict ALLOWED_DIRECT_C_OUTPUT
 
tuple BANNER_REQUIRED
 
str CONTRACT_PATH = REPO_ROOT / "tests" / "tooling" / "user_facing_reporting_contract.json"
 
tuple CLI_REQUIRED
 

Detailed Description

Validate the repository's option-aware user-facing reporting contract.

Function Documentation

◆ strip_c_comments()

str audit_user_facing_reporting.strip_c_comments ( str  text)

Replace C comments while preserving source line positions.

Parameters
[in]textC source text to normalize.
Returns
Source text with comments replaced by whitespace/newlines.

Definition at line 38 of file audit_user_facing_reporting.py.

38def strip_c_comments(text: str) -> str:
39 """!
40 @brief Replace C comments while preserving source line positions.
41 @param[in] text C source text to normalize.
42 @return Source text with comments replaced by whitespace/newlines.
43 """
44
45 text = re.sub(r"/\*.*?\*/", lambda match: "\n" * match.group(0).count("\n"), text, flags=re.DOTALL)
46 return re.sub(r"//[^\n]*", "", text)
47
48
Here is the caller graph for this function:

◆ audit_direct_c_output()

list[str] audit_user_facing_reporting.audit_direct_c_output ( )

Return raw C console emissions outside their approved rendering modules.

Returns
Human-readable findings for every disallowed emission.

Definition at line 49 of file audit_user_facing_reporting.py.

49def audit_direct_c_output() -> list[str]:
50 """!
51 @brief Return raw C console emissions outside their approved rendering modules.
52 @return Human-readable findings for every disallowed emission.
53 """
54
55 findings: list[str] = []
56 pattern = re.compile(r"\b(?:PetscPrintf|PetscSynchronizedPrintf|printf)\s*\‍(")
57 for path in sorted(SRC_DIR.glob("*.c")):
58 if path.name in ALLOWED_DIRECT_C_OUTPUT:
59 continue
60 stripped = strip_c_comments(path.read_text(encoding="utf-8", errors="ignore"))
61 for match in pattern.finditer(stripped):
62 line = stripped.count("\n", 0, match.start()) + 1
63 findings.append(
64 f"{path.relative_to(REPO_ROOT)}:{line}: raw console output must use the logging policy "
65 "or be moved to an approved reporting surface."
66 )
67 return findings
68
69
Here is the call graph for this function:
Here is the caller graph for this function:

◆ require_fragments()

list[str] audit_user_facing_reporting.require_fragments ( Path  path,
tuple[str, ...]  fragments,
str  surface 
)

Return missing reporting-contract fragments for one user-facing surface.

Parameters
[in]pathSource file containing the surface.
[in]fragmentsRequired literal contract fragments.
[in]surfaceHuman-readable surface name for failures.
Returns
Findings for missing fragments.

Definition at line 70 of file audit_user_facing_reporting.py.

70def require_fragments(path: Path, fragments: tuple[str, ...], surface: str) -> list[str]:
71 """!
72 @brief Return missing reporting-contract fragments for one user-facing surface.
73 @param[in] path Source file containing the surface.
74 @param[in] fragments Required literal contract fragments.
75 @param[in] surface Human-readable surface name for failures.
76 @return Findings for missing fragments.
77 """
78
79 text = path.read_text(encoding="utf-8")
80 return [f"{surface}: missing required option-aware reporting fragment {fragment!r}."
81 for fragment in fragments if fragment not in text]
82
83
Here is the caller graph for this function:

◆ audit_cli_contract()

list[str] audit_user_facing_reporting.audit_cli_contract ( dict  contract)

Verify that every declared CLI command has a parser, dispatch handler, and contextual message.

Parameters
[in]contractParsed user-facing reporting contract mapping.
Returns
Findings for missing CLI command-reporting contract elements.

Definition at line 84 of file audit_user_facing_reporting.py.

84def audit_cli_contract(contract: dict) -> list[str]:
85 """!
86 @brief Verify that every declared CLI command has a parser, dispatch handler, and contextual message.
87 @param[in] contract Parsed user-facing reporting contract mapping.
88 @return Findings for missing CLI command-reporting contract elements.
89 """
90
91 cli_text = (REPO_ROOT / "picurv_cli" / "cli.py").read_text(encoding="utf-8")
92 core_text = (REPO_ROOT / "picurv_cli" / "core.py").read_text(encoding="utf-8")
93 findings: list[str] = []
94 for command, entry in contract["cli_commands"].items():
95 for field, text, surface in (
96 ("parser", cli_text, "CLI parser"),
97 ("handler", core_text, "CLI handler"),
98 ("context", cli_text + core_text, "CLI context"),
99 ):
100 if entry[field] not in text:
101 findings.append(f"{surface} for '{command}': missing contract fragment {entry[field]!r}.")
102 return findings
103
104
Here is the caller graph for this function:

◆ main()

int audit_user_facing_reporting.main ( )

Audit C banner, CLI summaries, and direct-output routing.

Returns
Process status code.

Definition at line 105 of file audit_user_facing_reporting.py.

105def main() -> int:
106 """!
107 @brief Audit C banner, CLI summaries, and direct-output routing.
108 @return Process status code.
109 """
110
111 findings = audit_direct_c_output()
112 contract = json.loads(CONTRACT_PATH.read_text(encoding="utf-8"))
113 findings.extend(require_fragments(
114 REPO_ROOT / contract["banner"]["source"], tuple(contract["banner"]["required_fragments"]), "C startup banner"
115 ))
116 findings.extend(require_fragments(REPO_ROOT / "picurv_cli" / "core.py", CLI_REQUIRED, "Python CLI/summarize"))
117 findings.extend(audit_cli_contract(contract))
118 if findings:
119 print("\n".join(findings), file=sys.stderr)
120 return 1
121 print("User-facing reporting audit passed.")
122 return 0
123
124
int main(int argc, char **argv)
Entry point for the postprocessor executable.
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ REPO_ROOT

audit_user_facing_reporting.REPO_ROOT = Path(__file__).resolve().parents[2]

Definition at line 12 of file audit_user_facing_reporting.py.

◆ SRC_DIR

str audit_user_facing_reporting.SRC_DIR = REPO_ROOT / "src"

Definition at line 13 of file audit_user_facing_reporting.py.

◆ ALLOWED_DIRECT_C_OUTPUT

dict audit_user_facing_reporting.ALLOWED_DIRECT_C_OUTPUT
Initial value:
1= {
2 "io.c", # Rank-zero effective-configuration banner.
3 "logging.c", # Logging and diagnostic rendering sinks.
4 "setup.c", # Bootstrap warnings before logging is configured.
5 "runloop.c", # Progress-bar line control.
6 "postprocessor.c", # Progress-bar line control.
7 "momentumsolvers.c", # Unconditional convergence warnings.
8}

Definition at line 14 of file audit_user_facing_reporting.py.

◆ BANNER_REQUIRED

tuple audit_user_facing_reporting.BANNER_REQUIRED
Initial value:
1= (
2 "Momentum Equation Solver",
3 "Initial Pseudo-CFL (Courant)",
4 "Newton-Krylov PETSc Controls",
5 "Pseudo-Time Controller : NOT APPLICABLE",
6 "Console Log Level",
7 "Profiling Timestep Output",
8 "Runtime Memory Log",
9 "Solution Convergence Mode",
10)

Definition at line 22 of file audit_user_facing_reporting.py.

◆ CONTRACT_PATH

str audit_user_facing_reporting.CONTRACT_PATH = REPO_ROOT / "tests" / "tooling" / "user_facing_reporting_contract.json"

Definition at line 32 of file audit_user_facing_reporting.py.

◆ CLI_REQUIRED

tuple audit_user_facing_reporting.CLI_REQUIRED
Initial value:
1= ("Momentum Solver: Dual Time Picard Jameson RK", "Momentum Solver: Newton Krylov",
2 "Momentum Solver: Explicit RK (no pseudo-time controller)",
3 "Dual-Time Pseudo-Time Controls", "Newton--Krylov Controls")

Definition at line 33 of file audit_user_facing_reporting.py.