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
2 changes: 1 addition & 1 deletion .github/workflows/e2e-init-optimization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
COLUMNS: 110
MAX_RETRIES: 3
RETRY_DELAY: 5
EXPECTED_IMPROVEMENT_PCT: 30
EXPECTED_IMPROVEMENT_PCT: 10
CODEFLASH_END_TO_END: 1
steps:
- name: 🛎️ Checkout
Expand Down
21 changes: 20 additions & 1 deletion codeflash/code_utils/code_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,16 +528,29 @@ def add_needed_imports_from_module(

try:
for mod in gatherer.module_imports:
# Skip __future__ imports as they cannot be imported directly
# __future__ imports should only be imported with specific objects i.e from __future__ import annotations
if mod == "__future__":
continue
if mod not in dotted_import_collector.imports:
AddImportsVisitor.add_needed_import(dst_context, mod)
RemoveImportsVisitor.remove_unused_import(dst_context, mod)
aliased_objects = set()
for mod, alias_pairs in gatherer.alias_mapping.items():
for alias_pair in alias_pairs:
if alias_pair[0] and alias_pair[1]: # Both name and alias exist
aliased_objects.add(f"{mod}.{alias_pair[0]}")

for mod, obj_seq in gatherer.object_mapping.items():
for obj in obj_seq:
if (
f"{mod}.{obj}" in helper_functions_fqn or dst_context.full_module_name == mod # avoid circular deps
):
continue # Skip adding imports for helper functions already in the context

if f"{mod}.{obj}" in aliased_objects:
continue

# Handle star imports by resolving them to actual symbol names
if obj == "*":
resolved_symbols = resolve_star_import(mod, project_root)
Expand All @@ -559,6 +572,8 @@ def add_needed_imports_from_module(
return dst_module_code

for mod, asname in gatherer.module_aliases.items():
if not asname:
continue
if f"{mod}.{asname}" not in dotted_import_collector.imports:
AddImportsVisitor.add_needed_import(dst_context, mod, asname=asname)
RemoveImportsVisitor.remove_unused_import(dst_context, mod, asname=asname)
Expand All @@ -568,12 +583,16 @@ def add_needed_imports_from_module(
if f"{mod}.{alias_pair[0]}" in helper_functions_fqn:
continue

if not alias_pair[0] or not alias_pair[1]:
continue

if f"{mod}.{alias_pair[1]}" not in dotted_import_collector.imports:
AddImportsVisitor.add_needed_import(dst_context, mod, alias_pair[0], asname=alias_pair[1])
RemoveImportsVisitor.remove_unused_import(dst_context, mod, alias_pair[0], asname=alias_pair[1])

try:
transformed_module = AddImportsVisitor(dst_context).transform_module(parsed_dst_module)
add_imports_visitor = AddImportsVisitor(dst_context)
transformed_module = add_imports_visitor.transform_module(parsed_dst_module)
transformed_module = RemoveImportsVisitor(dst_context).transform_module(transformed_module)
return transformed_module.code.lstrip("\n")
except Exception as e:
Expand Down
13 changes: 9 additions & 4 deletions codeflash/verification/parse_test_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def calculate_function_throughput_from_test_results(test_results: TestResults, f
def parse_test_return_values_bin(file_location: Path, test_files: TestFiles, test_config: TestConfig) -> TestResults:
test_results = TestResults()
if not file_location.exists():
logger.warning(f"No test results for {file_location} found.")
logger.debug(f"No test results for {file_location} found.")
console.rule()
return test_results

Expand Down Expand Up @@ -237,6 +237,11 @@ def parse_test_xml(

test_class_path = testcase.classname
try:
if testcase.name is None:
logger.debug(
f"testcase.name is None for testcase {testcase!r} in file {test_xml_file_path}, skipping"
)
continue
test_function = testcase.name.split("[", 1)[0] if "[" in testcase.name else testcase.name
except (AttributeError, TypeError) as e:
msg = (
Expand Down Expand Up @@ -273,16 +278,16 @@ def parse_test_xml(

timed_out = False
if test_config.test_framework == "pytest":
loop_index = int(testcase.name.split("[ ")[-1][:-2]) if "[" in testcase.name else 1
loop_index = int(testcase.name.split("[ ")[-1][:-2]) if testcase.name and "[" in testcase.name else 1
if len(testcase.result) > 1:
logger.warning(f"!!!!!Multiple results for {testcase.name} in {test_xml_file_path}!!!")
logger.debug(f"!!!!!Multiple results for {testcase.name or '<None>'} in {test_xml_file_path}!!!")
if len(testcase.result) == 1:
message = testcase.result[0].message.lower()
if "failed: timeout >" in message:
timed_out = True
else:
if len(testcase.result) > 1:
logger.warning(f"!!!!!Multiple results for {testcase.name} in {test_xml_file_path}!!!")
logger.debug(f"!!!!!Multiple results for {testcase.name or '<None>'} in {test_xml_file_path}!!!")
if len(testcase.result) == 1:
message = testcase.result[0].message.lower()
if "timed out" in message:
Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/end_to_end_test_init_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def run_test(expected_improvement_pct: int) -> bool:
file_path="remove_control_chars.py",
function_name="CharacterRemover.remove_control_characters",
test_framework="pytest",
min_improvement_x=0.3,
min_improvement_x=0.1,
coverage_expectations=[
CoverageExpectation(
function_name="CharacterRemover.remove_control_characters", expected_coverage=100.0, expected_lines=[14]
Expand Down
Loading
Loading