MCPcopy Index your code
hub / github.com/algorithmicsuperintelligence/openevolve / _prepare_program

Function _prepare_program

openevolve/api.py:202–234  ·  view source on GitHub ↗

Convert program input to a file path

(
    initial_program: Union[str, Path, List[str]], temp_dir: Optional[str], temp_files: List[str]
)

Source from the content-addressed store, hash-verified

200
201
202def _prepare_program(
203 initial_program: Union[str, Path, List[str]], temp_dir: Optional[str], temp_files: List[str]
204) -> str:
205 """Convert program input to a file path"""
206
207 # If already a file path, use it directly
208 if isinstance(initial_program, (str, Path)):
209 if os.path.exists(str(initial_program)):
210 return str(initial_program)
211
212 # Otherwise, treat as code and write to temp file
213 if isinstance(initial_program, list):
214 code = "\n".join(initial_program)
215 else:
216 code = str(initial_program)
217
218 # Ensure code has evolution markers if it doesn't already
219 if "EVOLVE-BLOCK-START" not in code:
220 # Wrap entire code in evolution block
221 code = f"""# EVOLVE-BLOCK-START
222{code}
223# EVOLVE-BLOCK-END"""
224
225 # Write to temp file
226 if temp_dir is None:
227 temp_dir = tempfile.gettempdir()
228
229 program_file = os.path.join(temp_dir, f"program_{uuid.uuid4().hex[:8]}.py")
230 with open(program_file, "w") as f:
231 f.write(code)
232 temp_files.append(program_file)
233
234 return program_file
235
236
237def _prepare_evaluator(

Calls

no outgoing calls