diff --git a/fusil/python/h5py/write_h5py_code.py b/fusil/python/h5py/write_h5py_code.py index 5413a64..25f1f89 100644 --- a/fusil/python/h5py/write_h5py_code.py +++ b/fusil/python/h5py/write_h5py_code.py @@ -1682,8 +1682,6 @@ def _write_h5py_file(self): locking_expr_list = self.parent.arg_generator.h5py_argument_generator.genH5PyLocking() locking_expr = "".join(locking_expr_list) if locking_expr_list else "None" - fs_kwargs_expr = "" - all_kwargs_parts = [] # Store parts like "driver='core'" if actual_driver: all_kwargs_parts.append(f"driver={driver_expr}") @@ -1710,7 +1708,6 @@ def _write_h5py_file(self): all_kwargs_parts.append(fs_kwargs_expr_temp[2:]) elif fs_kwargs_expr_temp: # If it's just "kw=val" all_kwargs_parts.append(fs_kwargs_expr_temp) - fs_kwargs_expr = fs_kwargs_expr_temp # For logging # Construct the final kwargs string for the File() call # Filter out any genuinely empty strings that might have resulted from non-chosen optional args diff --git a/fusil/python/write_python_code.py b/fusil/python/write_python_code.py index afba85a..5169910 100644 --- a/fusil/python/write_python_code.py +++ b/fusil/python/write_python_code.py @@ -403,15 +403,13 @@ def __eq__(self, other): def _write_helper_call_functions(self) -> None: """Writes helper functions for calling code, comparing results, etc.""" - self.write( - 0, "# Helper for correctness testing that handles NaN, lambdas, and complex numbers." - ) - self.write(0, "import math") - self.write(0, "import types") # Fixed-shape helper: emit it as one block rather than line-by-line self.write calls. self.write_block( 0, """ + # Helper for correctness testing that handles NaN, lambdas, and complex numbers. + import math + import types def compare_results(a, b): if isinstance(a, types.FunctionType) and a.__name__ == '' and \\ isinstance(b, types.FunctionType) and b.__name__ == '': diff --git a/fusil/write_code.py b/fusil/write_code.py index 10f6ba5..ce70bc7 100644 --- a/fusil/write_code.py +++ b/fusil/write_code.py @@ -1,48 +1,8 @@ -import re -import textwrap from contextlib import contextmanager from os import chmod from textwrap import dedent -class CodeTemplate: - def __init__(self, template_text: str): - # Dedent the template to handle templates defined in indented code - self.template = textwrap.dedent(template_text) - - def render(self_, **kwargs) -> str: - """ - Renders the template by substituting placeholders, handling both - multi-line indented blocks and single-line inline values. - """ - output = self_.template - - # For each key-value pair, perform both block and inline substitutions. - for key, value in kwargs.items(): - placeholder = f"{{{key}}}" - - # 1. BLOCK SUBSTITUTION: - # First, find and replace all occurrences of the placeholder that are - # at the beginning of a line (i.e., need indentation). - block_pattern = re.compile(f"^(?P\\s*){re.escape(placeholder)}", re.MULTILINE) - - def replacer(match): - """A replacer function for re.sub that indents the value.""" - indent_str = match.group("indent") - # Dedent the value to normalize it, then re-indent it to match the placeholder. - return textwrap.indent(textwrap.dedent(str(value)).strip(), indent_str) - - # Perform the substitution for all block-style placeholders. - output = block_pattern.sub(replacer, output) - - # 2. INLINE SUBSTITUTION: - # After handling the blocks, any remaining placeholders must be inline. - # Perform a simple, global string replacement for them. - output = output.replace(placeholder, str(value)) - - return output - - class WriteCode: def __init__(self): self.indent = " " * 4