Skip to content

Commit 36229bb

Browse files
committed
format: Format
1 parent 9db390a commit 36229bb

3 files changed

Lines changed: 73 additions & 32 deletions

File tree

build_tools/sharpy_dogfood/config.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,10 @@ def sharpy_cli_project(self) -> Path:
142142

143143
@property
144144
def snippets_dir(self) -> Path:
145-
return self.project_root / "src/Sharpy.Compiler.Tests/Integration/TestFixtures/basics"
145+
return (
146+
self.project_root
147+
/ "src/Sharpy.Compiler.Tests/Integration/TestFixtures/basics"
148+
)
146149

147150
@property
148151
def test_fixtures_dir(self) -> Path:

build_tools/sharpy_dogfood/orchestrator.py

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,20 @@ def _is_valid_code_response(text: str) -> tuple[bool, str]:
6868
Returns (is_valid, reason) where reason explains why validation failed.
6969
"""
7070
if len(text) < _MIN_CODE_LENGTH:
71-
return False, f"Response too short ({len(text)} chars, minimum {_MIN_CODE_LENGTH})"
71+
return (
72+
False,
73+
f"Response too short ({len(text)} chars, minimum {_MIN_CODE_LENGTH})",
74+
)
7275

7376
for pattern in _NON_CODE_ERROR_PATTERNS:
7477
if pattern.match(text.strip()):
7578
return False, f"Response looks like an error message: {text[:80]!r}"
7679

7780
if not any(indicator in text for indicator in _CODE_INDICATORS):
78-
return False, "Response contains no code indicators (def, class, print, =, import)"
81+
return (
82+
False,
83+
"Response contains no code indicators (def, class, print, =, import)",
84+
)
7985

8086
return True, ""
8187

@@ -99,11 +105,13 @@ def _errors_are_equivalent(err1: Optional[str], err2: Optional[str]) -> bool:
99105
"""
100106
if not err1 or not err2:
101107
return False
108+
102109
# Normalize: strip whitespace, collapse spaces, remove file:line:col refs
103110
def normalize(s: str) -> str:
104-
s = re.sub(r'-->\s*\S+:\d+:\d+', '', s) # Remove file:line:col
105-
s = re.sub(r'\s+', ' ', s).strip()
111+
s = re.sub(r"-->\s*\S+:\d+:\d+", "", s) # Remove file:line:col
112+
s = re.sub(r"\s+", " ", s).strip()
106113
return s
114+
107115
return normalize(err1) == normalize(err2)
108116

109117

@@ -279,14 +287,14 @@ async def _verify_expected_with_python(
279287
"str?",
280288
"float?",
281289
"bool?",
282-
"property ", # Sharpy properties (auto or function-style)
290+
"property ", # Sharpy properties (auto or function-style)
283291
"property get ",
284292
"property set ",
285293
"property init ",
286-
"with ", # Sharpy with statement uses IDisposable, not Python __enter__/__exit__
287-
"from System", # .NET interop imports
294+
"with ", # Sharpy with statement uses IDisposable, not Python __enter__/__exit__
295+
"from System", # .NET interop imports
288296
"from system",
289-
"type ", # Named tuple type aliases (type Point = tuple[x: ...])
297+
"type ", # Named tuple type aliases (type Point = tuple[x: ...])
290298
]
291299
if any(feature in code for feature in sharpy_only_features):
292300
return True, None, "Sharpy-specific features - skipping Python verification"
@@ -1209,7 +1217,9 @@ async def _generate_and_validate_code(
12091217
return GenerationResult(
12101218
success=False,
12111219
code=code,
1212-
expected_output=extract_expected_output_from_response(gen_result.output),
1220+
expected_output=extract_expected_output_from_response(
1221+
gen_result.output
1222+
),
12131223
skip_reason=f"Repeated identical error (likely compiler bug): {prevalidation_error}",
12141224
backend_used=backend_used,
12151225
generation_duration=total_duration,
@@ -1226,7 +1236,9 @@ async def _generate_and_validate_code(
12261236
return GenerationResult(
12271237
success=False,
12281238
code=code,
1229-
expected_output=extract_expected_output_from_response(gen_result.output),
1239+
expected_output=extract_expected_output_from_response(
1240+
gen_result.output
1241+
),
12301242
skip_reason=f"Pre-validation failed after {attempt} attempts: {prevalidation_error}",
12311243
backend_used=backend_used,
12321244
generation_duration=total_duration,
@@ -1245,7 +1257,9 @@ async def _generate_and_validate_code(
12451257
return GenerationResult(
12461258
success=False,
12471259
code=code,
1248-
expected_output=extract_expected_output_from_response(gen_result.output),
1260+
expected_output=extract_expected_output_from_response(
1261+
gen_result.output
1262+
),
12491263
skip_reason=f"Internal compiler error: {semantic_error}",
12501264
backend_used=backend_used,
12511265
generation_duration=total_duration,
@@ -1266,7 +1280,9 @@ async def _generate_and_validate_code(
12661280
return GenerationResult(
12671281
success=False,
12681282
code=code,
1269-
expected_output=extract_expected_output_from_response(gen_result.output),
1283+
expected_output=extract_expected_output_from_response(
1284+
gen_result.output
1285+
),
12701286
skip_reason=f"Repeated identical compiler error (likely compiler bug): {semantic_error}",
12711287
backend_used=backend_used,
12721288
generation_duration=total_duration,
@@ -1283,7 +1299,9 @@ async def _generate_and_validate_code(
12831299
return GenerationResult(
12841300
success=False,
12851301
code=code,
1286-
expected_output=extract_expected_output_from_response(gen_result.output),
1302+
expected_output=extract_expected_output_from_response(
1303+
gen_result.output
1304+
),
12871305
skip_reason=f"Sharpy compiler error after {attempt} attempts: {semantic_error}",
12881306
backend_used=backend_used,
12891307
generation_duration=total_duration,
@@ -1335,7 +1353,11 @@ async def _generate_and_validate_code(
13351353
return GenerationResult(
13361354
success=False,
13371355
code=last_code,
1338-
expected_output=extract_expected_output_from_response(last_raw_output) if last_raw_output else None,
1356+
expected_output=(
1357+
extract_expected_output_from_response(last_raw_output)
1358+
if last_raw_output
1359+
else None
1360+
),
13391361
skip_reason="Generation failed after all retry attempts",
13401362
backend_used=backend_used,
13411363
generation_duration=total_duration,
@@ -1469,9 +1491,7 @@ async def _generate_and_validate_multifile_code(
14691491
)
14701492

14711493
# Step 1.4: Validate that the response looks like actual code
1472-
is_valid_code, invalid_reason = _is_valid_code_response(
1473-
gen_result.output
1474-
)
1494+
is_valid_code, invalid_reason = _is_valid_code_response(gen_result.output)
14751495
if not is_valid_code:
14761496
print(
14771497
f" Non-code response detected: {invalid_reason}", file=sys.stderr

build_tools/sharpy_dogfood/prompts.py

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,38 @@
1313
# =============================================================================
1414

1515
RETRY_REMEDIATION: list[tuple[str, str]] = [
16-
(r"SPY0456", "When defining __hash__, you MUST also define __eq__(self, other: object). "
17-
"Note: the parameter type must be 'object', not the class type."),
18-
(r"SPY0018", "Remove ALL backtick characters (`) from your code. "
19-
"Backticks are only valid as identifier escape syntax in Sharpy, not as code fences."),
20-
(r"SPY0220.*list\[.*\?\]", "Cannot create list[T?] from mixed T and None literals. "
21-
"Use an empty list and .append() each value individually."),
22-
(r"SPY0301.*no exported symbol", "Check that the imported symbol name matches exactly "
23-
"(case-sensitive) and that the symbol is defined at the module's top level. "
24-
"If the symbol is an @abstract class, try simplifying: remove the @abstract decorator "
25-
"or move the class to the importing file. Abstract class cross-module imports can be unreliable."),
26-
(r"SPY0907", "An internal compiler error occurred. Try simplifying your code — "
27-
"avoid deeply nested generics or complex cross-module patterns."),
28-
(r"FormatException.*0x", "Hex literals are supported in Sharpy. If you see a FormatException, "
29-
"ensure hex values don't exceed the 64-bit signed integer range (max 0x7FFFFFFFFFFFFFFF)."),
16+
(
17+
r"SPY0456",
18+
"When defining __hash__, you MUST also define __eq__(self, other: object). "
19+
"Note: the parameter type must be 'object', not the class type.",
20+
),
21+
(
22+
r"SPY0018",
23+
"Remove ALL backtick characters (`) from your code. "
24+
"Backticks are only valid as identifier escape syntax in Sharpy, not as code fences.",
25+
),
26+
(
27+
r"SPY0220.*list\[.*\?\]",
28+
"Cannot create list[T?] from mixed T and None literals. "
29+
"Use an empty list and .append() each value individually.",
30+
),
31+
(
32+
r"SPY0301.*no exported symbol",
33+
"Check that the imported symbol name matches exactly "
34+
"(case-sensitive) and that the symbol is defined at the module's top level. "
35+
"If the symbol is an @abstract class, try simplifying: remove the @abstract decorator "
36+
"or move the class to the importing file. Abstract class cross-module imports can be unreliable.",
37+
),
38+
(
39+
r"SPY0907",
40+
"An internal compiler error occurred. Try simplifying your code — "
41+
"avoid deeply nested generics or complex cross-module patterns.",
42+
),
43+
(
44+
r"FormatException.*0x",
45+
"Hex literals are supported in Sharpy. If you see a FormatException, "
46+
"ensure hex values don't exceed the 64-bit signed integer range (max 0x7FFFFFFFFFFFFFFF).",
47+
),
3048
]
3149

3250

0 commit comments

Comments
 (0)