Skip to content
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

Drop deadline warning in dev.deprecated #735

Merged

Conversation

DanielYang59
Copy link
Contributor

@DanielYang59 DanielYang59 commented Jan 3, 2025

Summary

  • Drop deadline warning in dev.deprecated, link to Remove is_rare_earth_metal materialsproject/pymatgen#4243.
  • Noticed a major issue: downstream function calls (if downstream uses upstream's deprecated function, a warning would still be emitted in downstream's CI, but downstream cannot resolve it)

I hope I didn't misunderstand anything, comment appreciated :)

Copy link

coderabbitai bot commented Jan 3, 2025

Walkthrough

The pull request introduces modifications to the deprecated decorator in the src/monty/dev.py module. The changes streamline the deprecation warning mechanism by removing complex CI-specific logic and simplifying the warning emission process. The method signature is updated to accommodate datetime | None for deadline specifications. Additionally, the test suite is reorganized to reflect these changes, including renaming tests for clarity, integrating new tests for deadline scenarios, and restructuring existing tests for better organization.

Changes

File Change Summary
src/monty/dev.py - Updated deprecated decorator method signature to use `datetime
tests/test_dev.py - Renamed TestDecorator class to TestDeprecated.
- Renamed multiple test methods for clarity, including replacing test_deprecated with test_basic_usage.
- Removed test_deprecated_deadline and integrated its functionality into test_deadline with parameterization.
- Added test_deadline_no_warn method.
- Simplified test_requires and test_install_except_hook methods to top-level functions.
src/monty/logging.py - Removed global logger variable logger, now using a local _logger within the wrap function.

Possibly related PRs

Poem

🐰 A Rabbit's Ode to Deprecation

Warnings whisper, time ticks by,
Deprecated code takes a sigh,
Datetime dances, warnings clear,
Simplicity now draws us near!

🕰️ Hop along, old function's way! 🚀


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

codecov bot commented Jan 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.40%. Comparing base (26acf0b) to head (740933b).
Report is 30 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #735      +/-   ##
==========================================
+ Coverage   84.19%   84.40%   +0.20%     
==========================================
  Files          27       27              
  Lines        1670     1654      -16     
  Branches      314      313       -1     
==========================================
- Hits         1406     1396      -10     
+ Misses        202      198       -4     
+ Partials       62       60       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@DanielYang59 DanielYang59 marked this pull request as ready for review January 3, 2025 12:26
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (4)
tests/test_dev.py (2)

172-175: Ensure consistency in the test message.
The phrase "This function should have been removed" in the match argument is correct for deprecated functions, but consider using language inclusive of classes if the decorator is used on class objects as well. This will help future-proof your tests if you later expand coverage.


185-187: Use a more descriptive filter message.
You're filtering specifically for the phrase "function should have been removed," but this might be confusing if the decorator is applied to classes or other entities in the future. Consider adjusting the match string for broader coverage, such as "should have been removed" without the word "function."

src/monty/dev.py (2)

36-37: Minor docstring refinement.
Consider highlighting that the deadline tuple is (year, month, day). It may be worth clarifying whether zero-padded or leading formats matter.


112-113: Deadline conversion validation.
It might be beneficial to handle potential ValueError thrown if users pass invalid date tuples (e.g., (2025, 13, 1)). Currently, a ValueError from datetime(*deadline) would bubble up in an unclear manner.

 if deadline is not None:
     try:
         _deadline: datetime = datetime(*deadline)
     except ValueError as e:
+        raise ValueError(f"Invalid deadline: {deadline}") from e
 else:
     _deadline = None
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 26acf0b and 1a82e0b.

📒 Files selected for processing (2)
  • src/monty/dev.py (3 hunks)
  • tests/test_dev.py (1 hunks)
🔇 Additional comments (4)
tests/test_dev.py (3)

177-179: Confirm behavior for post-deadline usage.
Decorating func_old with a past date ensures the DeprecationWarning is raised. Looks good for verifying deadline-based deprecation. Ensure that the replacement or additional documentation provides guidance on alternatives.


181-182: Good practice to clarify test purpose.
The docstring is clear that no warning should be raised before the deadline. Tests confirm the new approach of ignoring the repository check.


189-190: No-warn scenario verification.
This test correctly validates that no deprecation warning is raised before the far-future deadline. Smoothly confirms that the logic gracefully skips warnings in borderline scenarios.

src/monty/dev.py (1)

46-46: Docstring alignment looks good.
The line succinctly states what the decorator returns and is consistent with the updated behavior (now issuing direct warnings).

src/monty/dev.py Outdated Show resolved Hide resolved
@DanielYang59 DanielYang59 marked this pull request as draft January 3, 2025 12:29
@DanielYang59 DanielYang59 changed the title Drop repo check in dev.deprecated and warn instead of raise Fix repo check in dev.deprecated and warn instead of raise Jan 3, 2025
@DanielYang59 DanielYang59 force-pushed the fix-deprecated-repo-check branch from 296466b to 19ed737 Compare January 3, 2025 13:03
@DanielYang59 DanielYang59 force-pushed the fix-deprecated-repo-check branch 3 times, most recently from 9b31428 to 86568d6 Compare January 3, 2025 13:29
@DanielYang59 DanielYang59 marked this pull request as ready for review January 3, 2025 13:31
@DanielYang59 DanielYang59 force-pushed the fix-deprecated-repo-check branch from 86568d6 to 279b265 Compare January 3, 2025 13:33
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Caution

Inline review comments failed to post. This is likely due to GitHub's limits when posting large numbers of comments.

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/monty/dev.py (2)

38-39: Docstring accurately reflects the warning behavior change

The docstring updates correctly reflect the switch from raising exceptions to emitting warnings. However, consider making the docstring more inclusive by mentioning both functions and classes explicitly, as this decorator can be applied to both.

-            of the old function/class, in format (yyyy, MM, dd). DeprecationWarning
+            of the deprecated entity, in format (yyyy, MM, dd). DeprecationWarning

Also applies to: 48-48


54-57: Enhance docstring clarity for repository check requirements

The docstring could be more explicit about the requirements for the repository check to work correctly.

-            """Check if is running in code owner's repo.
-            Only generate reliable check when `git` is installed and remote name
-            is "upstream".
-            """
+            """Check if the code is running in the original repository (not a fork).
+            
+            Requirements:
+            - Git must be installed
+            - Repository must have a remote named 'upstream' pointing to the original repository
+            - GITHUB_REPOSITORY environment variable must be set (typically in CI)
+            """
🛑 Comments failed to post (1)
src/monty/dev.py (1)

158-159: ⚠️ Potential issue

Review warning emission timing

The emit_deadline_warning() is called during decorator application rather than when the deprecated entity is used. This means the warning will be emitted when the module is imported, which might not be the intended behavior.

Consider moving the warning emission into the wrapped function/class:

-    # Emit CI warning after removal deadline
-    emit_deadline_warning()

     def decorator(target: Callable) -> Callable:
         if inspect.isfunction(target):
+            emit_deadline_warning()  # Move inside the wrapped function
             return deprecated_function_decorator(target)
         elif inspect.isclass(target):
+            emit_deadline_warning()  # Move inside the class initialization
             return deprecated_class_decorator(target)

Committable suggestion skipped: line range outside the PR's diff.

@DanielYang59 DanielYang59 marked this pull request as draft January 3, 2025 13:37
@DanielYang59 DanielYang59 changed the title Fix repo check in dev.deprecated and warn instead of raise Drop deadline warning in dev.deprecated Jan 3, 2025
@DanielYang59 DanielYang59 force-pushed the fix-deprecated-repo-check branch from ab30ec7 to 740933b Compare January 3, 2025 14:31
@DanielYang59 DanielYang59 marked this pull request as ready for review January 3, 2025 14:49
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/monty/dev.py (2)

33-33: Enhance docstring clarity for better developer experience.

The docstring could be more explicit about:

  1. The deadline format - specify that it expects a tuple of integers (yyyy, MM, dd)
  2. The return value behavior - clarify that the warning is shown on each invocation
-            of the old function/class, in format (yyyy, MM, dd).
+            of the old function/class. Expected format: tuple of integers (yyyy, MM, dd),
+            e.g., (2024, 12, 31).
-        Original function/class, but with a warning to use the replacement.
+        Original function/class wrapped with a warning that will be shown on each
+        invocation, directing users to the replacement if specified.

Also applies to: 42-42


Line range hint 1-174: Approval: Simplified warning mechanism improves downstream usage.

The removal of CI-specific warning logic is a good architectural decision that addresses the issue with downstream function calls. This change makes the deprecation mechanism more straightforward and easier to manage for downstream dependencies.

Consider documenting this architectural change in the module's docstring to explain the simplified warning behavior for future maintainers.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 279b265 and 740933b.

📒 Files selected for processing (3)
  • src/monty/dev.py (3 hunks)
  • src/monty/logging.py (0 hunks)
  • tests/test_dev.py (6 hunks)
💤 Files with no reviewable changes (1)
  • src/monty/logging.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/test_dev.py
🔇 Additional comments (1)
src/monty/dev.py (1)

Line range hint 52-71: Use generic terminology in warning messages.

As noted in previous reviews, the @deprecated decorator is used on both functions and classes. The warning message should use generic terminology like "entity" or "item" instead of specifically mentioning "function/class".

-        msg = f"{old.__name__} is deprecated"
+        msg = f"This entity ({old.__name__}) is deprecated"

src/monty/dev.py Show resolved Hide resolved
@DanielYang59
Copy link
Contributor Author

@shyuep Sorry for the first major issue of 2025, looks like it's broadly impacting pymatgen and related package, can I ask an urgent release of this patch?

cc @ml-evs @naik-aakash

@ml-evs
Copy link

ml-evs commented Jan 3, 2025

  • Noticed a major issue: downstream function calls (if downstream uses upstream's deprecated function, a warning would still be emitted in downstream's CI, but downstream cannot resolve it)

Just to clarify, it would be fine if it emitted a warning via warnings.warn in my CI as I will just ignore it, but as it literally raises the warning as an exception, it is impossible to deal with

@shyuep shyuep merged commit 8c13b0f into materialsvirtuallab:master Jan 3, 2025
8 checks passed
@DanielYang59 DanielYang59 deleted the fix-deprecated-repo-check branch January 4, 2025 02:05
@DanielYang59
Copy link
Contributor Author

Thanks @shyuep for the quick release :)

Just to clarify, it would be fine if it emitted a warning via warnings.warn in my CI as I will just ignore it

This point is well taken, but it's still broadcasting that warning to undesired audience (downstream package), so I might only add such a warning if I could somehow confine it only to the desire target (which I don't have a good idea now)

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

Successfully merging this pull request may close these issues.

3 participants