Skip to content

Commit abe3017

Browse files
Merge branch 'main' into chore/handle-json-and-string-errors-from-cfapi
2 parents 3952776 + 62a4575 commit abe3017

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+5156
-277
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ https://github.com/user-attachments/assets/38f44f4e-be1c-4f84-8db9-63d5ee3e61e5
6565

6666
Join our community for support and discussions. If you have any questions, feel free to reach out to us using one of the following methods:
6767

68+
- [Free live Installation Support](https://calendly.com/codeflash-saurabh/codeflash-setup)
6869
- [Join our Discord](https://www.codeflash.ai/discord)
6970
- [Follow us on Twitter](https://x.com/codeflashAI)
7071
- [Follow us on Linkedin](https://www.linkedin.com/in/saurabh-misra/)
71-
- [Email founders](mailto:[email protected])
7272

7373
## License
7474

codeflash/LICENSE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Business Source License 1.1
33
Parameters
44

55
Licensor: CodeFlash Inc.
6-
Licensed Work: Codeflash Client version 0.13.x
6+
Licensed Work: Codeflash Client version 0.14.x
77
The Licensed Work is (c) 2024 CodeFlash Inc.
88

99
Additional Use Grant: None. Production use of the Licensed Work is only permitted
@@ -13,7 +13,7 @@ Additional Use Grant: None. Production use of the Licensed Work is only permitte
1313
Platform. Please visit codeflash.ai for further
1414
information.
1515

16-
Change Date: 2029-06-03
16+
Change Date: 2029-06-09
1717

1818
Change License: MIT
1919

codeflash/api/aiservice.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def optimize_python_code( # noqa: D417
118118

119119
if response.status_code == 200:
120120
optimizations_json = response.json()["optimizations"]
121-
logger.info(f"Generated {len(optimizations_json)} candidates.")
121+
logger.info(f"Generated {len(optimizations_json)} candidate optimizations.")
122122
console.rule()
123123
end_time = time.perf_counter()
124124
logger.debug(f"Generating optimizations took {end_time - start_time:.2f} seconds.")
@@ -189,7 +189,7 @@ def optimize_python_code_line_profiler( # noqa: D417
189189

190190
if response.status_code == 200:
191191
optimizations_json = response.json()["optimizations"]
192-
logger.info(f"Generated {len(optimizations_json)} candidates.")
192+
logger.info(f"Generated {len(optimizations_json)} candidate optimizations.")
193193
console.rule()
194194
return [
195195
OptimizedCandidate(

codeflash/api/cfapi.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from pathlib import Path
88
from typing import TYPE_CHECKING, Any, Optional
99

10+
import git
1011
import requests
1112
import sentry_sdk
1213
from pydantic.json import pydantic_encoder
@@ -206,3 +207,35 @@ def get_blocklisted_functions() -> dict[str, set[str]] | dict[str, Any]:
206207
return {}
207208

208209
return {Path(k).name: {v.replace("()", "") for v in values} for k, values in content.items()}
210+
211+
212+
def is_function_being_optimized_again(
213+
owner: str, repo: str, pr_number: int, code_contexts: list[dict[str, str]]
214+
) -> Any: # noqa: ANN401
215+
"""Check if the function being optimized is being optimized again."""
216+
response = make_cfapi_request(
217+
"/is-already-optimized",
218+
"POST",
219+
{"owner": owner, "repo": repo, "pr_number": pr_number, "code_contexts": code_contexts},
220+
)
221+
response.raise_for_status()
222+
return response.json()
223+
224+
225+
def add_code_context_hash(code_context_hash: str) -> None:
226+
"""Add code context to the DB cache."""
227+
pr_number = get_pr_number()
228+
if pr_number is None:
229+
return
230+
try:
231+
owner, repo = get_repo_owner_and_name()
232+
pr_number = get_pr_number()
233+
except git.exc.InvalidGitRepositoryError:
234+
return
235+
236+
if owner and repo and pr_number is not None:
237+
make_cfapi_request(
238+
"/add-code-hash",
239+
"POST",
240+
{"owner": owner, "repo": repo, "pr_number": pr_number, "code_hash": code_context_hash},
241+
)

codeflash/benchmarking/codeflash_trace.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def setup(self, trace_path: str) -> None:
2525
"""Set up the database connection for direct writing.
2626
2727
Args:
28+
----
2829
trace_path: Path to the trace database file
2930
3031
"""
@@ -52,6 +53,7 @@ def write_function_timings(self) -> None:
5253
"""Write function call data directly to the database.
5354
5455
Args:
56+
----
5557
data: List of function call data tuples to write
5658
5759
"""
@@ -94,9 +96,11 @@ def __call__(self, func: Callable) -> Callable:
9496
"""Use as a decorator to trace function execution.
9597
9698
Args:
99+
----
97100
func: The function to be decorated
98101
99102
Returns:
103+
-------
100104
The wrapped function
101105
102106
"""

codeflash/benchmarking/instrument_codeflash_trace.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,12 @@ def add_codeflash_decorator_to_code(code: str, functions_to_optimize: list[Funct
7676
"""Add codeflash_trace to a function.
7777
7878
Args:
79+
----
7980
code: The source code as a string
8081
functions_to_optimize: List of FunctionToOptimize instances containing function details
8182
8283
Returns:
84+
-------
8385
The modified source code as a string
8486
8587
"""

codeflash/benchmarking/plugin/plugin.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,11 @@ def get_function_benchmark_timings(trace_path: Path) -> dict[str, dict[Benchmark
7474
"""Process the trace file and extract timing data for all functions.
7575
7676
Args:
77+
----
7778
trace_path: Path to the trace file
7879
7980
Returns:
81+
-------
8082
A nested dictionary where:
8183
- Outer keys are module_name.qualified_name (module.class.function)
8284
- Inner keys are of type BenchmarkKey
@@ -132,9 +134,11 @@ def get_benchmark_timings(trace_path: Path) -> dict[BenchmarkKey, int]:
132134
"""Extract total benchmark timings from trace files.
133135
134136
Args:
137+
----
135138
trace_path: Path to the trace file
136139
137140
Returns:
141+
-------
138142
A dictionary mapping where:
139143
- Keys are of type BenchmarkKey
140144
- Values are total benchmark timing in milliseconds (with overhead subtracted)

codeflash/benchmarking/replay_test.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,14 @@ def create_trace_replay_test_code(
5555
"""Create a replay test for functions based on trace data.
5656
5757
Args:
58+
----
5859
trace_file: Path to the SQLite database file
5960
functions_data: List of dictionaries with function info extracted from DB
6061
test_framework: 'pytest' or 'unittest'
6162
max_run_count: Maximum number of runs to include in the test
6263
6364
Returns:
65+
-------
6466
A string containing the test code
6567
6668
"""
@@ -218,12 +220,14 @@ def generate_replay_test(
218220
"""Generate multiple replay tests from the traced function calls, grouped by benchmark.
219221
220222
Args:
223+
----
221224
trace_file_path: Path to the SQLite database file
222225
output_dir: Directory to write the generated tests (if None, only returns the code)
223226
test_framework: 'pytest' or 'unittest'
224227
max_run_count: Maximum number of runs to include per function
225228
226229
Returns:
230+
-------
227231
Dictionary mapping benchmark names to generated test code
228232
229233
"""

codeflash/benchmarking/utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,13 @@ def process_benchmark_data(
8383
"""Process benchmark data and generate detailed benchmark information.
8484
8585
Args:
86+
----
8687
replay_performance_gain: The performance gain from replay
8788
fto_benchmark_timings: Function to optimize benchmark timings
8889
total_benchmark_timings: Total benchmark timings
8990
9091
Returns:
92+
-------
9193
ProcessedBenchmarkInfo containing processed benchmark details
9294
9395
"""

codeflash/cli_cmds/cli.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ def process_pyproject_config(args: Namespace) -> Namespace:
123123
"disable_telemetry",
124124
"disable_imports_sorting",
125125
"git_remote",
126+
"override_fixtures",
126127
]
127128
for key in supported_keys:
128129
if key in pyproject_config and (

0 commit comments

Comments
 (0)