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
11 changes: 4 additions & 7 deletions codeflash/cli_cmds/cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import importlib.util
import logging
import sys
from argparse import SUPPRESS, ArgumentParser, Namespace
Expand Down Expand Up @@ -104,7 +103,7 @@ def parse_args() -> Namespace:
"--async",
default=False,
action="store_true",
help="Enable optimization of async functions. By default, async functions are excluded from optimization.",
help="(Deprecated) Async function optimization is now enabled by default. This flag is ignored.",
)

args, unknown_args = parser.parse_known_args()
Expand Down Expand Up @@ -155,13 +154,11 @@ def process_and_validate_cmd_args(args: Namespace) -> Namespace:
if env_utils.is_ci():
args.no_pr = True

if getattr(args, "async", False) and importlib.util.find_spec("pytest_asyncio") is None:
if getattr(args, "async", False):
logger.warning(
"Warning: The --async flag requires pytest-asyncio to be installed.\n"
"Please install it using:\n"
' pip install "codeflash[asyncio]"'
"The --async flag is deprecated and will be removed in a future version. "
"Async function optimization is now enabled by default."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make it actionable. "You can remove this flag"

)
raise SystemExit(1)

return args

Expand Down
22 changes: 1 addition & 21 deletions codeflash/discovery/functions_to_optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,6 @@ def get_functions_to_optimize(
project_root: Path,
module_root: Path,
previous_checkpoint_functions: dict[str, dict[str, str]] | None = None,
*,
enable_async: bool = False,
) -> tuple[dict[Path, list[FunctionToOptimize]], int, Path | None]:
assert sum([bool(optimize_all), bool(replay_test), bool(file)]) <= 1, (
"Only one of optimize_all, replay_test, or file should be provided"
Expand Down Expand Up @@ -242,13 +240,7 @@ def get_functions_to_optimize(
ph("cli-optimizing-git-diff")
functions = get_functions_within_git_diff(uncommitted_changes=False)
filtered_modified_functions, functions_count = filter_functions(
functions,
test_cfg.tests_root,
ignore_paths,
project_root,
module_root,
previous_checkpoint_functions,
enable_async=enable_async,
functions, test_cfg.tests_root, ignore_paths, project_root, module_root, previous_checkpoint_functions
)

logger.info(f"!lsp|Found {functions_count} function{'s' if functions_count > 1 else ''} to optimize")
Expand Down Expand Up @@ -658,7 +650,6 @@ def filter_functions(
previous_checkpoint_functions: dict[Path, dict[str, Any]] | None = None,
*,
disable_logs: bool = False,
enable_async: bool = False,
) -> tuple[dict[Path, list[FunctionToOptimize]], int]:
filtered_modified_functions: dict[str, list[FunctionToOptimize]] = {}
blocklist_funcs = get_blocklisted_functions()
Expand All @@ -678,7 +669,6 @@ def filter_functions(
submodule_ignored_paths_count: int = 0
blocklist_funcs_removed_count: int = 0
previous_checkpoint_functions_removed_count: int = 0
async_functions_removed_count: int = 0
tests_root_str = str(tests_root)
module_root_str = str(module_root)

Expand Down Expand Up @@ -734,15 +724,6 @@ def filter_functions(
functions_tmp.append(function)
_functions = functions_tmp

if not enable_async:
functions_tmp = []
for function in _functions:
if function.is_async:
async_functions_removed_count += 1
continue
functions_tmp.append(function)
_functions = functions_tmp

filtered_modified_functions[file_path] = _functions
functions_count += len(_functions)

Expand All @@ -756,7 +737,6 @@ def filter_functions(
"Files from ignored submodules": (submodule_ignored_paths_count, "bright_black"),
"Blocklisted functions removed": (blocklist_funcs_removed_count, "bright_red"),
"Functions skipped from checkpoint": (previous_checkpoint_functions_removed_count, "green"),
"Async functions removed": (async_functions_removed_count, "bright_magenta"),
}
tree = Tree(Text("Ignored functions and files", style="bold"))
for label, (count, color) in log_info.items():
Expand Down
1 change: 0 additions & 1 deletion codeflash/optimization/optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ def get_optimizable_functions(self) -> tuple[dict[Path, list[FunctionToOptimize]
project_root=self.args.project_root,
module_root=self.args.module_root,
previous_checkpoint_functions=self.args.previous_checkpoint_functions,
enable_async=getattr(self.args, "async", False),
)

def create_function_optimizer(
Expand Down
8 changes: 1 addition & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ dependencies = [
"pygls>=2.0.0,<3.0.0",
"codeflash-benchmark",
"filelock",
"pytest-asyncio>=1.2.0",
]

[project.urls]
Expand All @@ -53,13 +54,9 @@ Homepage = "https://codeflash.ai"
codeflash = "codeflash.main:main"

[project.optional-dependencies]
asyncio = [
"pytest-asyncio>=1.2.0",
]

[dependency-groups]
dev = [
{include-group = "asyncio"},
"ipython>=8.12.0",
"mypy>=1.13",
"ruff>=0.7.0",
Expand All @@ -82,9 +79,6 @@ dev = [
"uv>=0.6.2",
"pre-commit>=4.2.0,<5",
]
asyncio = [
"pytest-asyncio>=1.2.0",
]
tests = [
"black>=25.9.0",
"jax>=0.4.30",
Expand Down
1 change: 0 additions & 1 deletion tests/scripts/end_to_end_test_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ def run_test(expected_improvement_pct: int) -> bool:
config = TestConfig(
file_path="main.py",
min_improvement_x=0.1,
enable_async=True,
coverage_expectations=[
CoverageExpectation(
function_name="retry_with_backoff",
Expand Down
3 changes: 0 additions & 3 deletions tests/scripts/end_to_end_test_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class TestConfig:
trace_mode: bool = False
coverage_expectations: list[CoverageExpectation] = field(default_factory=list)
benchmarks_root: Optional[pathlib.Path] = None
enable_async: bool = False
use_worktree: bool = False


Expand Down Expand Up @@ -136,8 +135,6 @@ def build_command(
)
if benchmarks_root:
base_command.extend(["--benchmark", "--benchmarks-root", str(benchmarks_root)])
if config.enable_async:
base_command.append("--async")
if config.use_worktree:
base_command.append("--worktree")
return base_command
Expand Down
13 changes: 7 additions & 6 deletions tests/test_async_function_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ def sync_method(self):
ignore_paths=[],
project_root=file_path.parent,
module_root=file_path.parent,
enable_async=True,
)

assert functions_count == 4
Expand All @@ -259,7 +258,8 @@ def sync_method(self):


@pytest.mark.skipif(sys.platform == "win32", reason="pending support for asyncio on windows")
def test_no_async_functions_finding(temp_dir):
def test_async_functions_always_included(temp_dir):
"""Test that async functions are always included now (no longer filtered out)."""
mixed_code = """
async def async_func_one():
return await operation_one()
Expand Down Expand Up @@ -297,16 +297,17 @@ def sync_method(self):
ignore_paths=[],
project_root=file_path.parent,
module_root=file_path.parent,
enable_async=False,
)

assert functions_count == 2
# Now async functions are always included, so we expect 4 functions (not 2)
assert functions_count == 4

function_names = [fn.function_name for fn in functions[file_path]]
assert "sync_func_one" in function_names
assert "sync_method" in function_names
assert "async_func_one" not in function_names
assert "async_method" not in function_names
# Async functions are now included by default
assert "async_func_one" in function_names
assert "async_method" in function_names


@pytest.mark.skipif(sys.platform == "win32", reason="pending support for asyncio on windows")
Expand Down
21 changes: 4 additions & 17 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading