|
6 | 6 | import json |
7 | 7 | import linecache |
8 | 8 | import os |
9 | | -from typing import TYPE_CHECKING, Optional |
| 9 | +from pathlib import Path |
| 10 | +from typing import Optional |
10 | 11 |
|
11 | 12 | import dill as pickle |
12 | 13 |
|
13 | 14 | from codeflash.code_utils.tabulate import tabulate |
14 | 15 | from codeflash.languages import is_python |
15 | 16 |
|
16 | | -if TYPE_CHECKING: |
17 | | - from pathlib import Path |
18 | | - |
19 | 17 |
|
20 | 18 | def show_func( |
21 | 19 | filename: str, start_lineno: int, func_name: str, timings: list[tuple[int, int, float]], unit: float |
@@ -98,13 +96,13 @@ def show_text_non_python(stats: dict, line_contents: dict[tuple[str, int], str]) |
98 | 96 | table_rows = [] |
99 | 97 | for lineno, nhits, time in timings: |
100 | 98 | percent = "" if total_time == 0 else "%5.1f" % (100 * time / total_time) |
101 | | - time_disp = "%5.1f" % time |
| 99 | + time_disp = f"{time:5.1f}" |
102 | 100 | if len(time_disp) > default_column_sizes["time"]: |
103 | | - time_disp = "%5.1g" % time |
| 101 | + time_disp = f"{time:5.1g}" |
104 | 102 | perhit = (float(time) / nhits) if nhits > 0 else 0.0 |
105 | | - perhit_disp = "%5.1f" % perhit |
| 103 | + perhit_disp = f"{perhit:5.1f}" |
106 | 104 | if len(perhit_disp) > default_column_sizes["perhit"]: |
107 | | - perhit_disp = "%5.1g" % perhit |
| 105 | + perhit_disp = f"{perhit:5.1g}" |
108 | 106 | nhits_disp = "%d" % nhits # noqa: UP031 |
109 | 107 | if len(nhits_disp) > default_column_sizes["hits"]: |
110 | 108 | nhits_disp = f"{nhits:g}" |
@@ -161,7 +159,7 @@ def parse_line_profile_results(line_profiler_output_file: Optional[Path]) -> dic |
161 | 159 | if not sorted_line_stats: |
162 | 160 | continue |
163 | 161 | start_lineno = sorted_line_stats[0][0] |
164 | | - grouped_timings[(file_path, start_lineno, os.path.basename(file_path))] = sorted_line_stats |
| 162 | + grouped_timings[(file_path, start_lineno, Path(file_path).name)] = sorted_line_stats |
165 | 163 |
|
166 | 164 | stats_dict["timings"] = grouped_timings |
167 | 165 | stats_dict["unit"] = 1e-9 |
|
0 commit comments