Skip to content

Commit 3e3e709

Browse files
committed
fix: add explicit UTF-8 encoding for FFI doc generation
Add `encoding='utf-8'` to all file open operations in the FFI documentation generation scripts since the default Windows encoding doesnt seem to go well with it and lets the relevant `pre-commit` step fail for Windows in #253. Also improved error visibility in `verify_ffi.py` by capturing stderr when the subprocess fails.
1 parent 3884314 commit 3e3e709

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

contrib/verify_ffi.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ def generate_ffi_docs(crate_dir: Path) -> tuple[str, int, str]:
3535
capture_output=True,
3636
text=True
3737
)
38-
return crate_dir.name, result.returncode, result.stdout
38+
output = result.stdout
39+
if result.returncode != 0 and result.stderr:
40+
output = result.stderr
41+
return crate_dir.name, result.returncode, output
3942

4043

4144
def main():

dash-spv-ffi/scripts/generate_ffi_docs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def extract_ffi_functions(file_path: Path) -> List[FFIFunction]:
2929
"""
3030
functions: List[FFIFunction] = []
3131

32-
with open(file_path, 'r') as f:
32+
with open(file_path, 'r', encoding='utf-8') as f:
3333
content = f.read()
3434

3535
# Iterate over all #[no_mangle] attribute occurrences
@@ -370,7 +370,7 @@ def main():
370370

371371
# Write to file
372372
output_file = Path(__file__).parent.parent / "FFI_API.md"
373-
with open(output_file, 'w') as f:
373+
with open(output_file, 'w', encoding='utf-8') as f:
374374
f.write(markdown)
375375

376376
print(f"Generated FFI documentation with {len(all_functions)} functions")

key-wallet-ffi/scripts/generate_ffi_docs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def extract_ffi_functions(file_path: Path) -> List[FFIFunction]:
2828
"""
2929
functions: List[FFIFunction] = []
3030

31-
with open(file_path, 'r') as f:
31+
with open(file_path, 'r', encoding='utf-8') as f:
3232
content = f.read()
3333

3434
for m in re.finditer(r'(?m)^\s*#\[no_mangle\]\s*$', content):
@@ -309,7 +309,7 @@ def main():
309309

310310
# Write to file
311311
output_file = Path(__file__).parent.parent / "FFI_API.md"
312-
with open(output_file, 'w') as f:
312+
with open(output_file, 'w', encoding='utf-8') as f:
313313
f.write(markdown)
314314

315315
print(f"Generated FFI documentation with {len(all_functions)} functions")

0 commit comments

Comments
 (0)