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

refactor:upstream classes #6

Merged
merged 11 commits into from
Oct 14, 2024
Merged

refactor:upstream classes #6

merged 11 commits into from
Oct 14, 2024

Conversation

JarbasAl
Copy link
Member

@JarbasAl JarbasAl commented Oct 14, 2024

Copy link

coderabbitai bot commented Oct 14, 2024

Walkthrough

The changes primarily involve the Intent and IntentBuilder classes located in ovos_adapt/intent.py. A new metaclass _IntentMeta is introduced for the Intent class, which overrides the __instancecheck__ method for backward compatibility. The constructors of both classes are updated to include type hints and default to empty lists for specific attributes. The methods for managing entity types in IntentBuilder are retained but modified to append to their respective lists. Additionally, the requirements.txt file is updated to reflect a stable version of a dependency and includes a new package.

Changes

File Path Change Summary
ovos_adapt/intent.py - Introduced _IntentMeta for Intent class with __instancecheck__ override.
- Updated Intent constructor with type hints and default empty lists for requires, at_least_one, and optional.
- Introduced _IntentBuilderMeta for IntentBuilder class with similar instance check functionality.
- Updated IntentBuilder constructor with type hints and default empty lists for attributes.
- Retained methods one_of, require, exclude, and optionally in IntentBuilder, modified to append to lists.
requirements.txt - Updated ovos-plugin-manager version constraint to >=0.0.26,<1.0.0.
- Added new dependency ovos-workshop>=0.1.6,<1.0.0.

Possibly related PRs

  • feat/OPM Pipeline #2: The changes in the Intent and IntentBuilder classes in the main PR may relate to the intent parsing service in opm.py, as both involve managing intents and their configurations, potentially impacting how intents are recognized and processed across the system.

Suggested labels

enhancement

Poem

🐇 In the meadow where intents play,
A builder hops and finds the way.
With type hints bright and lists anew,
They craft their paths, both tried and true.
Oh, what joy in code's embrace,
A rabbit's dance in a digital space! 🌼


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 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.

@github-actions github-actions bot added fix and removed fix labels Oct 14, 2024
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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between c3c66d9 and 4874a0d.

📒 Files selected for processing (1)
  • ovos_adapt/intent.py (6 hunks)
🧰 Additional context used
🔇 Additional comments (6)
ovos_adapt/intent.py (6)

18-18: Necessary imports added for metaclasses and type annotations

The addition of abc, Optional, and List imports is appropriate to support the use of metaclasses and type annotations in the updated classes.

Also applies to: 20-20


121-130: Implementation of _IntentMeta ensures backward compatibility

The introduction of the _IntentMeta metaclass with the overridden __instancecheck__ method effectively maintains backward compatibility with the original Intent class from adapt.intent. This approach is sound and correctly implemented.


132-134: Updated Intent class with metaclass and type hints

Updating the Intent class to use _IntentMeta as its metaclass ensures consistent behavior with the newly introduced compatibility layer. The addition of type hints in the constructor enhances code readability and type safety.


144-146: Initialization avoids mutable default arguments

Assigning attributes with self.requires = requires or [] and similar statements prevents issues associated with mutable default arguments in function definitions. This is a best practice in Python and is properly applied here.


237-246: Implementation of _IntentBuilderMeta maintains backward compatibility

The addition of the _IntentBuilderMeta metaclass with the overridden __instancecheck__ method ensures backward compatibility with the original IntentBuilder class from adapt.intent. This is appropriately implemented.


248-248: Updated IntentBuilder class to use the new metaclass

By specifying metaclass=_IntentBuilderMeta, the IntentBuilder class aligns with the compatibility adjustments made for the Intent class, ensuring consistent behavior across both classes.

ovos_adapt/intent.py Outdated Show resolved Hide resolved
use the OVOS workshop Intent and IntentBuilder classes , as these will be shared with other keyword based engines
@JarbasAl JarbasAl changed the title fix:isinstance checks compat with upstream adapt refactor:upstream classes Oct 14, 2024
JarbasAl added a commit to OpenVoiceOS/OVOS-workshop that referenced this pull request Oct 14, 2024
JarbasAl added a commit to OpenVoiceOS/OVOS-workshop that referenced this pull request Oct 14, 2024
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: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 4874a0d and 813e1e3.

📒 Files selected for processing (2)
  • ovos_adapt/intent.py (4 hunks)
  • requirements.txt (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • requirements.txt
🧰 Additional context used
🪛 Ruff
ovos_adapt/intent.py

18-18: ovos_workshop.intent.IntentBuilder imported but unused

Remove unused import: ovos_workshop.intent.IntentBuilder

(F401)

ovos_adapt/intent.py Outdated Show resolved Hide resolved
JarbasAl added a commit to OpenVoiceOS/OVOS-workshop that referenced this pull request Oct 14, 2024
* fix:finish extracting intent classes from adapt package

ports usage of "excludes"

needed for OpenVoiceOS/ovos-core#527

companion to OpenVoiceOS/ovos-adapt-pipeline-plugin#6

* fix test

* simplify

* add a test
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: 3

🧹 Outside diff range and nitpick comments (1)
ovos_adapt/intent.py (1)

Line range hint 1-87: Overall refactoring improves centralization but introduces potential redundancy

The changes in this file primarily involve refactoring to delegate functionality to static methods of the Intent class. This centralization can improve maintainability and consistency of the codebase. However, it also introduces wrapper functions that might be unnecessary if all callers can directly use the Intent class methods.

Consider the following recommendations:

  1. Evaluate the necessity of the wrapper functions (find_first_tag and resolve_one_of). If they're not needed for backward compatibility or API simplicity, consider removing them to reduce code complexity.
  2. If you decide to keep the wrapper functions, document the reason for their existence to prevent future confusion.
  3. Ensure that the Intent class and its static methods are well-documented and easily discoverable for developers who might need to use them directly.

These changes appear to be part of a larger refactoring effort. Ensure that all related changes across the codebase are consistent with this new architecture.

🧰 Tools
🪛 Ruff

19-19: ovos_workshop.intents.IntentBuilder imported but unused

Remove unused import: ovos_workshop.intents.IntentBuilder

(F401)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 813e1e3 and 6fa2c0e.

📒 Files selected for processing (2)
  • ovos_adapt/intent.py (3 hunks)
  • requirements.txt (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • requirements.txt
🧰 Additional context used
🪛 Ruff
ovos_adapt/intent.py

19-19: ovos_workshop.intents.IntentBuilder imported but unused

Remove unused import: ovos_workshop.intents.IntentBuilder

(F401)

ovos_adapt/intent.py Show resolved Hide resolved
ovos_adapt/intent.py Show resolved Hide resolved
ovos_adapt/intent.py Show resolved Hide resolved
@JarbasAl JarbasAl merged commit 1add1d8 into dev Oct 14, 2024
6 checks passed
@JarbasAl JarbasAl deleted the fix/instancechecks branch October 14, 2024 05:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant