Move the definition of the run_tmp_dir away from server side and into client side.

This commit is contained in:
Saurabh Misra 2024-01-11 20:36:05 -08:00
parent 3ef0e7999c
commit 0226561190
4 changed files with 15 additions and 4 deletions

8
README.md Normal file
View file

@ -0,0 +1,8 @@
# CodeFlash MonoRepo
Here's the projects that are part of the CodeFlash MonoRepo:
- CodeFlash Client - /cli/
- CodeFlash Python Django ai service - /django/aiservice
- CodeFlash NodeJS CF API - /js/cf-api
- CodeFlash Webapp - /js/cf-webapp

View file

@ -4,6 +4,7 @@ from typing import Tuple, Optional
from codeflash.api.aiservice import generate_regression_tests
from codeflash.code_utils.ast_unparser import ast_unparse
from codeflash.code_utils.code_utils import get_run_tmp_file
from codeflash.code_utils.code_utils import module_name_from_file_path
from codeflash.discovery.functions_to_optimize import FunctionToOptimize
from codeflash.verification.verification_utils import (
@ -49,6 +50,9 @@ def generate_tests(
)
if response and isinstance(response, tuple) and len(response) == 2:
generated_test_source, instrumented_test_source = response
instrumented_test_source = instrumented_test_source.replace(
"{codeflash_run_tmp_dir_client_side}", get_run_tmp_file("")
)
else:
logging.error(
f"Failed to generate and instrument tests for {function_to_optimize.function_name}"

View file

@ -237,13 +237,13 @@ class InjectPerfAndLogging(ast.NodeTransformer):
return node
def inject_logging_code(test_code: str, tmp_dir: str = "/tmp") -> str:
def inject_logging_code(test_code: str) -> str:
# TODO : Port this to Sqlite3 - makes it standard and easier to use
logging_code = f"""import pickle
import os
def _log__test__values(values, duration, test_name):
iteration = os.environ["CODEFLASH_TEST_ITERATION"]
with open(os.path.join('{tmp_dir}', f'test_return_values_{{iteration}}.bin'), 'ab') as f:
with open(os.path.join('{{codeflash_run_tmp_dir_client_side}}', f'test_return_values_{{iteration}}.bin'), 'ab') as f:
return_bytes = pickle.dumps(values)
_test_name = f"{{test_name}}".encode("ascii")
f.write(len(_test_name).to_bytes(4, byteorder='big'))

View file

@ -2,7 +2,6 @@ import ast
from injectperf.ast_unparser import ast_unparse
from injectperf.instrument_new_tests import InjectPerfAndLogging, inject_logging_code
from injectperf.run_tmp_file import get_run_tmp_file
from models.functions_to_optimize import FunctionToOptimize
@ -39,5 +38,5 @@ def instrument_test_source(
new_imports += [ast.Import(names=[ast.alias(name="timeout_decorator")])]
new_module_node.body = new_imports + new_module_node.body
new_tests = ast_unparse(new_module_node)
modified_new_tests = inject_logging_code(new_tests, tmp_dir=get_run_tmp_file(""))
modified_new_tests = inject_logging_code(new_tests)
return modified_new_tests