-
Notifications
You must be signed in to change notification settings - Fork 22
Format only code that was optimized (and helpers) #211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 23 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
3cbd6b7
feat(optimizer): Implement targeted formatting (CF-637)
zomglings a10600c
Fixed changes to the FunctionOptimizer
zomglings bcba527
CODEFLASH_DISABLE_TELEMETRY environment variable can be set to disabl…
zomglings 36da640
Added bubble sort implementation with bad formatting in non-optimized…
zomglings 85fd3c0
Added a file containing a bubble sort method in a class
zomglings ce33708
Merge branch 'main' into targeted-formatting
zomglings 2c40018
Added "scratch/" directory to .gitignore
zomglings 82b9d41
Cleaned up the import sorting code in FunctionOptimizer
zomglings ce87832
Added test for sort_imports_in_place
zomglings 0373bfa
Reverted changes to optimizer and formatter on targeted-formatting br…
zomglings 81dbb33
Merge branch 'main' into targeted-formatting-cst-based
zomglings 9345d80
Started work on targeted formatting using the CST
zomglings bfc8423
TODO
zomglings 91fe6a7
Updated implementation of FunctionOptimizer.reformat_code_and_helpers
zomglings b89622c
Fixed a few bugs in reformat_code_and_helpers
zomglings 5a9265c
More codeposition bugs
zomglings b903d1a
Issue with splicing
zomglings 16ca27e
Fixing more bugs, testing live...
zomglings 59e3667
Got it functional
zomglings c3b8063
Do not recalculate code_context when reformatting
zomglings 6dd72cf
Correct calculation of all preexisting "function" symbols for formatt…
zomglings eae756a
Clarified docstring for get_modification_code_ranges
zomglings 05817f9
removed xylophone
zomglings 9efdc21
Added test for get_modification_code_ranges.
zomglings b6baf05
Merge branch 'main' into targeted-formatting-cst-based
zomglings 9face63
"ruff check --fix"
zomglings 0615f55
Fixed some more ruff check issues
zomglings af4df4a
"ruff format"
zomglings cf4a665
more fixes for "ruff check"...
zomglings d43862e
ruff format...
zomglings 6ec5ef0
That should be hte last of the ruff stuff
zomglings a468ba7
Added a test for FunctionOptimizer.reformat_code_and_helpers
zomglings File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -254,3 +254,5 @@ fabric.properties | |
|
|
||
| # Mac | ||
| .DS_Store | ||
|
|
||
| scratch/ | ||
38 changes: 38 additions & 0 deletions
38
code_to_optimize/bubble_sort_method_preserve_bad_formatting_for_nonoptimized_code.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import sys | ||
|
|
||
|
|
||
| def lol(): | ||
| print( "lol" ) | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| class BubbleSorter: | ||
| def __init__(self, x=0): | ||
| self.x = x | ||
|
|
||
| def lol(self): | ||
| print( "lol" ) | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| def sorter(self, arr): | ||
| print("codeflash stdout : BubbleSorter.sorter() called") | ||
| for i in range(len(arr)): | ||
| for j in range(len(arr) - 1): | ||
| if arr[j] > arr[j + 1]: | ||
| temp = arr[j] | ||
| arr[j] = arr[j + 1] | ||
| arr[j + 1] = temp | ||
| print("stderr test", file=sys.stderr) | ||
| return arr |
19 changes: 19 additions & 0 deletions
19
code_to_optimize/bubble_sort_preserve_bad_formatting_for_nonoptimized_code.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| def lol(): | ||
| print( "lol" ) | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| def sorter(arr): | ||
| print("codeflash stdout: Sorting list") | ||
| for i in range(len(arr)): | ||
| for j in range(len(arr) - 1): | ||
| if arr[j] > arr[j + 1]: | ||
| temp = arr[j] | ||
| arr[j] = arr[j + 1] | ||
| arr[j + 1] = temp | ||
| print(f"result: {arr}") | ||
| return arr |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
| solved problem, please reach out to us at [email protected]. We're hiring! | ||
| """ | ||
|
|
||
| import os | ||
| from pathlib import Path | ||
|
|
||
| from codeflash.cli_cmds.cli import parse_args, process_pyproject_config | ||
|
|
@@ -20,25 +21,29 @@ def main() -> None: | |
| CODEFLASH_LOGO, panel_args={"title": "https://codeflash.ai", "expand": False}, text_args={"style": "bold gold3"} | ||
| ) | ||
| args = parse_args() | ||
|
|
||
| disable_telemetry_env = os.environ.get("CODEFLASH_DISABLE_TELEMETRY", "").lower() in {"true", "t", "1", "yes", "y"} | ||
|
|
||
| if args.command: | ||
| if args.config_file and Path.exists(args.config_file): | ||
| disable_telemetry = disable_telemetry_env | ||
| if (not disable_telemetry) and args.config_file and Path.exists(args.config_file): | ||
| pyproject_config, _ = parse_config_file(args.config_file) | ||
| disable_telemetry = pyproject_config.get("disable_telemetry", False) | ||
| else: | ||
| disable_telemetry = False | ||
| init_sentry(not disable_telemetry, exclude_errors=True) | ||
| posthog_cf.initialize_posthog(not disable_telemetry) | ||
| args.func() | ||
| elif args.verify_setup: | ||
| args = process_pyproject_config(args) | ||
| init_sentry(not args.disable_telemetry, exclude_errors=True) | ||
| posthog_cf.initialize_posthog(not args.disable_telemetry) | ||
| disable_telemetry = args.disable_telemetry or disable_telemetry_env | ||
| init_sentry(not disable_telemetry, exclude_errors=True) | ||
| posthog_cf.initialize_posthog(not disable_telemetry) | ||
| ask_run_end_to_end_test(args) | ||
| else: | ||
| args = process_pyproject_config(args) | ||
| args.previous_checkpoint_functions = ask_should_use_checkpoint_get_functions(args) | ||
| init_sentry(not args.disable_telemetry, exclude_errors=True) | ||
| posthog_cf.initialize_posthog(not args.disable_telemetry) | ||
| disable_telemetry = args.disable_telemetry or disable_telemetry_env | ||
| init_sentry(not disable_telemetry, exclude_errors=True) | ||
| posthog_cf.initialize_posthog(not disable_telemetry) | ||
| optimizer.run_with_args(args) | ||
|
|
||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: Can you help me understand the case on Why these have to be equal always?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a defensive measure. The function to optimize and helpers are non-overlapping blocks of code, and should not become overlapping due to formatting. If this has happened, something has gone wrong in the formatting step or in the extraction step (which identifies function to optimize and helpers).