Skip to content

Commit 60af8b7

Browse files
authored
Merge branch 'main' into tracer-optimization
2 parents e2b1925 + 113f59d commit 60af8b7

File tree

3 files changed

+35
-12
lines changed

3 files changed

+35
-12
lines changed

codeflash/cli_cmds/cmd_init.py

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
f"{LF}"
4646
)
4747

48+
4849
@dataclass(frozen=True)
4950
class SetupInfo:
5051
module_root: str
@@ -70,7 +71,6 @@ def init_codeflash() -> None:
7071
did_add_new_key = prompt_api_key()
7172

7273
if should_modify_pyproject_toml():
73-
7474
setup_info: SetupInfo = collect_setup_info()
7575

7676
configure_pyproject_toml(setup_info)
@@ -83,7 +83,6 @@ def init_codeflash() -> None:
8383
if "setup_info" in locals():
8484
module_string = f" you selected ({setup_info.module_root})"
8585

86-
8786
click.echo(
8887
f"{LF}"
8988
f"⚡️ Codeflash is now set up! You can now run:{LF}"
@@ -125,11 +124,13 @@ def ask_run_end_to_end_test(args: Namespace) -> None:
125124
bubble_sort_path, bubble_sort_test_path = create_bubble_sort_file_and_test(args)
126125
run_end_to_end_test(args, bubble_sort_path, bubble_sort_test_path)
127126

127+
128128
def should_modify_pyproject_toml() -> bool:
129129
"""Check if the current directory contains a valid pyproject.toml file with codeflash config
130130
If it does, ask the user if they want to re-configure it.
131131
"""
132132
from rich.prompt import Confirm
133+
133134
pyproject_toml_path = Path.cwd() / "pyproject.toml"
134135
if not pyproject_toml_path.exists():
135136
return True
@@ -144,7 +145,9 @@ def should_modify_pyproject_toml() -> bool:
144145
return True
145146

146147
create_toml = Confirm.ask(
147-
"✅ A valid Codeflash config already exists in this project. Do you want to re-configure it?", default=False, show_default=True
148+
"✅ A valid Codeflash config already exists in this project. Do you want to re-configure it?",
149+
default=False,
150+
show_default=True,
148151
)
149152
return create_toml
150153

@@ -160,7 +163,18 @@ def collect_setup_info() -> SetupInfo:
160163
# Check for the existence of pyproject.toml or setup.py
161164
project_name = check_for_toml_or_setup_file()
162165

163-
ignore_subdirs = ["venv", "node_modules", "dist", "build", "build_temp", "build_scripts", "env", "logs", "tmp", "__pycache__"]
166+
ignore_subdirs = [
167+
"venv",
168+
"node_modules",
169+
"dist",
170+
"build",
171+
"build_temp",
172+
"build_scripts",
173+
"env",
174+
"logs",
175+
"tmp",
176+
"__pycache__",
177+
]
164178
valid_subdirs = [
165179
d for d in next(os.walk("."))[1] if not d.startswith(".") and not d.startswith("__") and d not in ignore_subdirs
166180
]
@@ -262,13 +276,13 @@ def collect_setup_info() -> SetupInfo:
262276
benchmarks_options.append(create_benchmarks_option)
263277
benchmarks_options.append(custom_dir_option)
264278

265-
266279
benchmarks_answer = inquirer_wrapper(
267280
inquirer.list_input,
268281
message="Where are your performance benchmarks located? (benchmarks must be a sub directory of your tests root directory)",
269282
choices=benchmarks_options,
270283
default=(
271-
default_benchmarks_subdir if default_benchmarks_subdir in benchmarks_options else benchmarks_options[0]),
284+
default_benchmarks_subdir if default_benchmarks_subdir in benchmarks_options else benchmarks_options[0]
285+
),
272286
)
273287

274288
if benchmarks_answer == create_benchmarks_option:
@@ -304,7 +318,6 @@ def collect_setup_info() -> SetupInfo:
304318
# carousel=True,
305319
# )
306320

307-
308321
formatter = inquirer_wrapper(
309322
inquirer.list_input,
310323
message="Which code formatter do you use?",
@@ -340,7 +353,7 @@ def collect_setup_info() -> SetupInfo:
340353
return SetupInfo(
341354
module_root=str(module_root),
342355
tests_root=str(tests_root),
343-
benchmarks_root = str(benchmarks_root) if benchmarks_root else None,
356+
benchmarks_root=str(benchmarks_root) if benchmarks_root else None,
344357
test_framework=cast(str, test_framework),
345358
ignore_paths=ignore_paths,
346359
formatter=cast(str, formatter),
@@ -499,19 +512,22 @@ def install_github_actions(override_formatter_check: bool = False) -> None:
499512
return
500513
workflows_path.mkdir(parents=True, exist_ok=True)
501514
from importlib.resources import files
515+
502516
benchmark_mode = False
503517
if "benchmarks_root" in config:
504518
benchmark_mode = inquirer_wrapper(
505519
inquirer.confirm,
506520
message="⚡️It looks like you've configured a benchmarks_root in your config. Would you like to run the Github action in benchmark mode? "
507-
" This will show the impact of Codeflash's suggested optimizations on your benchmarks",
521+
" This will show the impact of Codeflash's suggested optimizations on your benchmarks",
508522
default=True,
509523
)
510524

511525
optimize_yml_content = (
512526
files("codeflash").joinpath("cli_cmds", "workflows", "codeflash-optimize.yaml").read_text(encoding="utf-8")
513527
)
514-
materialized_optimize_yml_content = customize_codeflash_yaml_content(optimize_yml_content, config, git_root, benchmark_mode)
528+
materialized_optimize_yml_content = customize_codeflash_yaml_content(
529+
optimize_yml_content, config, git_root, benchmark_mode
530+
)
515531
with optimize_yaml_path.open("w", encoding="utf8") as optimize_yml_file:
516532
optimize_yml_file.write(materialized_optimize_yml_content)
517533
click.echo(f"{LF}✅ Created GitHub action workflow at {optimize_yaml_path}{LF}")
@@ -607,7 +623,7 @@ def get_dependency_manager_installation_string(dep_manager: DependencyManager) -
607623
python_version_string = f"'{py_version.major}.{py_version.minor}'"
608624
if dep_manager == DependencyManager.UV:
609625
return """name: 🐍 Setup UV
610-
uses: astral-sh/setup-uv@v4
626+
uses: astral-sh/setup-uv@v6
611627
with:
612628
enable-cache: true"""
613629
return f"""name: 🐍 Set up Python

codeflash/discovery/functions_to_optimize.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
path_belongs_to_site_packages,
2323
)
2424
from codeflash.code_utils.git_utils import get_git_diff
25+
from codeflash.code_utils.time_utils import humanize_runtime
2526
from codeflash.discovery.discover_unit_tests import discover_unit_tests
2627
from codeflash.models.models import FunctionParent
2728
from codeflash.telemetry.posthog_cf import ph
@@ -203,6 +204,12 @@ def get_functions_to_optimize(
203204
functions, test_cfg.tests_root, ignore_paths, project_root, module_root, previous_checkpoint_functions
204205
)
205206
logger.info(f"Found {functions_count} function{'s' if functions_count > 1 else ''} to optimize")
207+
if optimize_all:
208+
three_min_in_ns = int(1.8e11)
209+
logger.info(
210+
f"It might take about {humanize_runtime(functions_count*three_min_in_ns)} to fully optimize this project. Codeflash "
211+
f"will keep opening pull requests as it finds optimizations."
212+
)
206213
return filtered_modified_functions, functions_count
207214

208215

docs/docs/getting-started/codeflash-github-actions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ This assumes that you install poetry with pip and have Codeflash dependency in t
106106
2. uv
107107

108108
```yaml
109-
- uses: astral-sh/setup-uv@v4
109+
- uses: astral-sh/setup-uv@v6
110110
with:
111111
enable-cache: true
112112
- run: uv sync --group=dev

0 commit comments

Comments
 (0)