Skip to content

Commit b7dc7bd

Browse files
authored
Merge branch 'main' into improve-addopts
2 parents 7d9ee86 + ffd8c90 commit b7dc7bd

File tree

5 files changed

+362
-7
lines changed

5 files changed

+362
-7
lines changed

.github/workflows/e2e-init-optimization.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
COLUMNS: 110
2020
MAX_RETRIES: 3
2121
RETRY_DELAY: 5
22-
EXPECTED_IMPROVEMENT_PCT: 30
22+
EXPECTED_IMPROVEMENT_PCT: 10
2323
CODEFLASH_END_TO_END: 1
2424
steps:
2525
- name: 🛎️ Checkout

codeflash/code_utils/code_extractor.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,16 +528,29 @@ def add_needed_imports_from_module(
528528

529529
try:
530530
for mod in gatherer.module_imports:
531+
# Skip __future__ imports as they cannot be imported directly
532+
# __future__ imports should only be imported with specific objects i.e from __future__ import annotations
533+
if mod == "__future__":
534+
continue
531535
if mod not in dotted_import_collector.imports:
532536
AddImportsVisitor.add_needed_import(dst_context, mod)
533537
RemoveImportsVisitor.remove_unused_import(dst_context, mod)
538+
aliased_objects = set()
539+
for mod, alias_pairs in gatherer.alias_mapping.items():
540+
for alias_pair in alias_pairs:
541+
if alias_pair[0] and alias_pair[1]: # Both name and alias exist
542+
aliased_objects.add(f"{mod}.{alias_pair[0]}")
543+
534544
for mod, obj_seq in gatherer.object_mapping.items():
535545
for obj in obj_seq:
536546
if (
537547
f"{mod}.{obj}" in helper_functions_fqn or dst_context.full_module_name == mod # avoid circular deps
538548
):
539549
continue # Skip adding imports for helper functions already in the context
540550

551+
if f"{mod}.{obj}" in aliased_objects:
552+
continue
553+
541554
# Handle star imports by resolving them to actual symbol names
542555
if obj == "*":
543556
resolved_symbols = resolve_star_import(mod, project_root)
@@ -559,6 +572,8 @@ def add_needed_imports_from_module(
559572
return dst_module_code
560573

561574
for mod, asname in gatherer.module_aliases.items():
575+
if not asname:
576+
continue
562577
if f"{mod}.{asname}" not in dotted_import_collector.imports:
563578
AddImportsVisitor.add_needed_import(dst_context, mod, asname=asname)
564579
RemoveImportsVisitor.remove_unused_import(dst_context, mod, asname=asname)
@@ -568,12 +583,16 @@ def add_needed_imports_from_module(
568583
if f"{mod}.{alias_pair[0]}" in helper_functions_fqn:
569584
continue
570585

586+
if not alias_pair[0] or not alias_pair[1]:
587+
continue
588+
571589
if f"{mod}.{alias_pair[1]}" not in dotted_import_collector.imports:
572590
AddImportsVisitor.add_needed_import(dst_context, mod, alias_pair[0], asname=alias_pair[1])
573591
RemoveImportsVisitor.remove_unused_import(dst_context, mod, alias_pair[0], asname=alias_pair[1])
574592

575593
try:
576-
transformed_module = AddImportsVisitor(dst_context).transform_module(parsed_dst_module)
594+
add_imports_visitor = AddImportsVisitor(dst_context)
595+
transformed_module = add_imports_visitor.transform_module(parsed_dst_module)
577596
transformed_module = RemoveImportsVisitor(dst_context).transform_module(transformed_module)
578597
return transformed_module.code.lstrip("\n")
579598
except Exception as e:

codeflash/verification/parse_test_output.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def calculate_function_throughput_from_test_results(test_results: TestResults, f
6767
def parse_test_return_values_bin(file_location: Path, test_files: TestFiles, test_config: TestConfig) -> TestResults:
6868
test_results = TestResults()
6969
if not file_location.exists():
70-
logger.warning(f"No test results for {file_location} found.")
70+
logger.debug(f"No test results for {file_location} found.")
7171
console.rule()
7272
return test_results
7373

@@ -237,6 +237,11 @@ def parse_test_xml(
237237

238238
test_class_path = testcase.classname
239239
try:
240+
if testcase.name is None:
241+
logger.debug(
242+
f"testcase.name is None for testcase {testcase!r} in file {test_xml_file_path}, skipping"
243+
)
244+
continue
240245
test_function = testcase.name.split("[", 1)[0] if "[" in testcase.name else testcase.name
241246
except (AttributeError, TypeError) as e:
242247
msg = (
@@ -273,16 +278,16 @@ def parse_test_xml(
273278

274279
timed_out = False
275280
if test_config.test_framework == "pytest":
276-
loop_index = int(testcase.name.split("[ ")[-1][:-2]) if "[" in testcase.name else 1
281+
loop_index = int(testcase.name.split("[ ")[-1][:-2]) if testcase.name and "[" in testcase.name else 1
277282
if len(testcase.result) > 1:
278-
logger.warning(f"!!!!!Multiple results for {testcase.name} in {test_xml_file_path}!!!")
283+
logger.debug(f"!!!!!Multiple results for {testcase.name or '<None>'} in {test_xml_file_path}!!!")
279284
if len(testcase.result) == 1:
280285
message = testcase.result[0].message.lower()
281286
if "failed: timeout >" in message:
282287
timed_out = True
283288
else:
284289
if len(testcase.result) > 1:
285-
logger.warning(f"!!!!!Multiple results for {testcase.name} in {test_xml_file_path}!!!")
290+
logger.debug(f"!!!!!Multiple results for {testcase.name or '<None>'} in {test_xml_file_path}!!!")
286291
if len(testcase.result) == 1:
287292
message = testcase.result[0].message.lower()
288293
if "timed out" in message:

tests/scripts/end_to_end_test_init_optimization.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def run_test(expected_improvement_pct: int) -> bool:
99
file_path="remove_control_chars.py",
1010
function_name="CharacterRemover.remove_control_characters",
1111
test_framework="pytest",
12-
min_improvement_x=0.3,
12+
min_improvement_x=0.1,
1313
coverage_expectations=[
1414
CoverageExpectation(
1515
function_name="CharacterRemover.remove_control_characters", expected_coverage=100.0, expected_lines=[14]

0 commit comments

Comments
 (0)