-
Notifications
You must be signed in to change notification settings - Fork 15
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
Conversation
… sections of the file... This is to test the new formatting changes
To test that the new formatting logic correctly handles indentation
…anch We are going to take a gentler, CST-based approach to targeted formatting.
Also updated CODEFLASH_DISABLE_TELEMETRY behavior
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
…ing purposes This is done on a per-path basis.
... and started adding tests for that function.
new_code = format_code(self.args.formatter_cmds, path) | ||
if should_sort_imports: | ||
new_code = sort_imports(new_code) | ||
if len(code_ranges_formatted) != len(code_ranges_unformatted): |
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).
@@ -299,7 +299,6 @@ def optimize_function(self) -> Result[BestOptimization, str]: | |||
|
|||
self.log_successful_optimization(explanation, generated_tests, exp_type) | |||
|
|||
# xylophone |
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.
xylophone? 😂
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.
Easy to grep, should be gone. :)
approach looks good. Can you write tests for |
with --unsafe-fixes
... AGAIN
No longer have permission to push to the official repo, will open this PR from my fork. |
PR Type
Enhancement, Tests
Description
Implement CST-based targeted formatting for functions
Track function code ranges with OptimFunctionCollector
Enable disabling telemetry via env var
Add bubble sort samples for formatting tests
Changes walkthrough 📝
bubble_sort_method_preserve_bad_formatting_for_nonoptimized_code.py
Add bubble sort class with bad formatting
code_to_optimize/bubble_sort_method_preserve_bad_formatting_for_nonoptimized_code.py
lol
functionBubbleSorter
class with bad formattingsorter
bubble sort with printsbubble_sort_preserve_bad_formatting_for_nonoptimized_code.py
Add bubble sort function sample
code_to_optimize/bubble_sort_preserve_bad_formatting_for_nonoptimized_code.py
lol
functionsorter
bubble sort functioncode_replacer.py
Record function code ranges in CST collector
codeflash/code_utils/code_replacer.py
PositionProvider
in metadata dependenciesmodification_code_range_lines
listformatter.py
Add function to get modification code ranges
codeflash/code_utils/formatter.py
libcst
,OptimFunctionCollector
, and modelsget_modification_code_ranges
functionfunction_optimizer.py
Implement targeted code splicing in optimizer
codeflash/optimization/function_optimizer.py
get_modification_code_ranges
andcast
reformat_code_and_helpers
for targeted formattingmain.py
Support disabling telemetry via env var
codeflash/main.py
os
and readCODEFLASH_DISABLE_TELEMETRY