Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions fusil/python/h5py/write_h5py_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand All @@ -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
Expand Down
8 changes: 3 additions & 5 deletions fusil/python/write_python_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__ == '<lambda>' and \\
isinstance(b, types.FunctionType) and b.__name__ == '<lambda>':
Expand Down
40 changes: 0 additions & 40 deletions fusil/write_code.py
Original file line number Diff line number Diff line change
@@ -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<indent>\\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
Expand Down
Loading