Skip to content

Conversation

Saga4
Copy link
Contributor

@Saga4 Saga4 commented Sep 2, 2025

User description

Closes ##631

closes #https://linear.app/codeflash-ai/issue/CF-700/print-a-warning-if-the-current-codeflash-version-is-not-the-latest


PR Type

Enhancement, Tests


Description

  • Add utilities to fetch and cache latest PyPI version

  • Notify users of newer minor or major releases

  • Integrate version check on CLI startup

  • Add comprehensive unit tests for version checking


Diagram Walkthrough

flowchart LR
  main["main() startup"] -- "calls" --> check["check_for_newer_minor_version()"]
  check -- "fetch or cache" --> get["get_latest_version_from_pypi()"]
  get -- "requests to PyPI" --> pypi["PyPI API"]
  check -- "notify if newer" --> console["console.print()"]
Loading

File Walkthrough

Relevant files
Enhancement
version_check.py
Add version check utilities                                                           

codeflash/code_utils/version_check.py

  • New get_latest_version_from_pypi() with 1h cache
  • New check_for_newer_minor_version() logic
  • Handle HTTP, network, JSON errors gracefully
  • Use packaging.version for version comparison
+84/-0   
main.py
Integrate version check in main                                                   

codeflash/main.py

  • Import and call check_for_newer_minor_version() at startup
  • Simplify telemetry disable logic
  • Ensure version warning runs before CLI commands
+6/-2     
Tests
test_version_check.py
Add tests for version check                                                           

tests/test_version_check.py

  • Test successful and error responses from PyPI
  • Verify caching and cache expiry behavior
  • Validate notifications for minor and major updates
  • Cover invalid version and no-update scenarios
+208/-0 

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link

github-actions bot commented Sep 2, 2025

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Indentation Inconsistency

The newly added lines for version checking and disable_telemetry use incorrect indentation levels compared to the surrounding code, which will cause syntax errors or broken logic flow.

# Check for newer version for all commands
check_for_newer_minor_version()

if args.command:
    disable_telemetry = False
Notification Format Mismatch

The printed message uses Rich markup without the expected "ℹ️" icon, causing unit tests to fail and deviating from the intended user notification style.

console.print(
    f"[bold blue]A newer version of Codeflash is available![/bold blue]\n"
    f"Current version: {__version__} | Latest version: {latest_version}\n"
    f"Consider upgrading for better quality optimizations.",
    style="blue",
)
Broad Exception Catch

The code catches a generic Exception, which may suppress unexpected errors; consider narrowing exception handling to specific cases or logging/re-raising critical issues.

except Exception as e:
    logger.debug(f"Unexpected error fetching version from PyPI: {e}")
    return None

Copy link

github-actions bot commented Sep 2, 2025

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
General
Add emoji and remove markup tags

Update the warning message to match test expectations by removing Rich markup tags
and adding the ℹ️ emoji prefix. This ensures the printed string contains "ℹ️ A
newer version..." exactly as the tests assert. Keep the style argument for coloring.

codeflash/code_utils/version_check.py [75-80]

 console.print(
-    f"[bold blue]A newer version of Codeflash is available![/bold blue]\n"
+    f"ℹ️  A newer version of Codeflash is available!\n"
     f"Current version: {__version__} | Latest version: {latest_version}\n"
     f"Consider upgrading for better quality optimizations.",
     style="blue",
 )
Suggestion importance[1-10]: 8

__

Why: The suggestion updates the printed message to include the ℹ️ emoji prefix and removes Rich markup tags to match test expectations, ensuring tests pass.

Medium

@misrasaurabh1
Copy link
Contributor

@Saga4 , we can't accept these changes unless @mihikap01 signs the CLA above

Copy link
Contributor

@mohammedahmed18 mohammedahmed18 left a comment

Choose a reason for hiding this comment

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

just some small changes,
also I think it's a lot of test cases, maybe 1 or 2 would do, besides they are failing for some reason

Comment on lines +72 to +74
if latest_parsed.major > current_parsed.major or (
latest_parsed.major == current_parsed.major and latest_parsed.minor > current_parsed.minor
):
Copy link
Contributor

Choose a reason for hiding this comment

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

personally, I prefer checking if latest_version < __version__ (major or minor)
@Saga4 what do you think ?

Comment on lines +75 to +80
console.print(
f"[bold blue]A newer version of Codeflash is available![/bold blue]\n"
f"Current version: {__version__} | Latest version: {latest_version}\n"
f"Consider upgrading for better quality optimizations.",
style="blue",
)
Copy link
Contributor

Choose a reason for hiding this comment

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

that's a lot of info, maybe just a simple one line message would do.

also I'm not a big fan of for better quality optimizations,
the message should say something like "Things could behave unexpectedly"

also use the warning log level for that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants