Skip to content

Remove aqt dependency from media extraction in ankihub client #1246

Merged
RisingOrange merged 4 commits intomainfrom
claude/remove-aqt-import-v1YsX
Feb 13, 2026
Merged

Remove aqt dependency from media extraction in ankihub client #1246
RisingOrange merged 4 commits intomainfrom
claude/remove-aqt-import-v1YsX

Conversation

@RisingOrange
Copy link
Collaborator

@RisingOrange RisingOrange commented Feb 13, 2026

This PR refactors the media extraction functions to not import from aqt in the ankihub client code.

Proposed changes

  1. get_media_names_from_notes_data(): Now accepts a get_notetype_by_id callback function instead of directly accessing the Anki collection. This allows callers to provide their own notetype resolution logic.

  2. get_media_names_from_notetype(): Changed to accept a notetype dictionary object directly instead of a notetype ID. This eliminates the need for the function to import and access aqt.mw.col.models.

  3. Removed unused import: Removed NotetypeId from anki.models which is no longer needed.

These changes improve:

  • Testability: Functions can now be tested without requiring a live Anki collection
  • Separation of concerns: Media extraction logic is decoupled from Anki API access
  • Flexibility: Callers can provide custom notetype resolution strategies

All call sites have been updated to pass the required callback or notetype object:

  • deck_creation.py: Passes lambda to access aqt.mw.col.models.get()
  • decks_dialog.py: Passes notetype object directly
  • suggestions.py: Passes lambda to access aqt.mw.col.models.get()
  • media_sync.py: Retrieves notetype before calling the function
  • Test files: Updated to pass appropriate callbacks/objects

Refactor get_media_names_from_notetype to accept a note type dict
instead of an ID, removing the aqt dependency from the client layer.
Add a get_notetype_by_id callback parameter to get_media_names_from_notes_data
so callers in the GUI/business layer provide the lookup function.

https://claude.ai/code/session_01ENEZrvFPchRVdnATauZfo9
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @RisingOrange, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the core media extraction functions to significantly improve their testability and reduce coupling with the Anki collection API. By introducing callback functions for notetype resolution and passing notetype objects directly, the media extraction logic becomes more modular and flexible. This change allows for easier unit testing of these components and provides greater adaptability for future custom notetype resolution strategies, ultimately leading to a more robust and maintainable codebase.

Highlights

  • Refactored get_media_names_from_notes_data: The function now accepts a get_notetype_by_id callback, enhancing flexibility and decoupling it from direct Anki collection API access.
  • Refactored get_media_names_from_notetype: This function now directly accepts a notetype dictionary object instead of a notetype ID, eliminating its dependency on aqt.mw.col.models.
  • Removed unused import: The NotetypeId import from anki.models has been removed as it is no longer needed.
  • Improved Testability and Separation of Concerns: The refactoring makes media extraction logic more testable by allowing functions to be tested without requiring a live Anki collection and improves separation of concerns.
  • Updated Call Sites: All existing call sites in deck_creation.py, decks_dialog.py, suggestions.py, media_sync.py, and various test files have been updated to conform to the new function signatures.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • ankihub/ankihub_client/models.py
    • Removed NotetypeId import and added Callable import.
    • Updated get_media_names_from_notes_data to accept a get_notetype_by_id callback function.
    • Modified get_media_names_from_notetype to accept a notetype dictionary instead of an ID, and removed the aqt import.
  • ankihub/gui/decks_dialog.py
    • Adjusted calls to get_media_names_from_notetype to pass the full notetype object directly.
  • ankihub/gui/media_sync.py
    • Modified the call to get_media_names_from_notetype to first retrieve the notetype object before passing it.
  • ankihub/gui/operations/deck_creation.py
    • Updated the call to get_media_names_from_notes_data to provide a lambda function for notetype retrieval.
  • ankihub/main/suggestions.py
    • Updated the call to get_media_names_from_notes_data to provide a lambda function for notetype retrieval.
  • tests/addon/test_unit.py
    • Adjusted test assertions for get_media_names_from_notes_data_mock.
    • Updated calls to get_media_names_from_notes_data in various tests to pass a notetype retrieval lambda.
  • tests/client/test_client.py
    • Updated calls to get_media_names_from_notes_data in tests to pass a dummy notetype retrieval lambda.
Activity
  • No human activity has occurred on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

RisingOrange and others added 2 commits February 13, 2026 13:18
* Fix import sorting: add blank line between stdlib and third-party imports

Ruff I001 was failing because the typing import ran directly into
the mashumaro import without a blank line separator.

https://claude.ai/code/session_01K8GeVjG7MjJzhZMtrzRh48

* Remove fragile get_media_names_from_notetype mock in client tests

Replace `lambda mid: {}` (which would crash with KeyError if the mock
were removed) with a proper empty notetype dict `{"css": "", "tmpls": []}`.
This removes the implicit dependency on the get_media_names_from_notetype
mock and makes each call site self-sufficient.

https://claude.ai/code/session_01K8GeVjG7MjJzhZMtrzRh48

---------

Co-authored-by: Claude <noreply@anthropic.com>
@RisingOrange RisingOrange changed the title Refactor media extraction to accept notetype objects instead of IDs Remove aqt dependency from media extraction in ankihub client Feb 13, 2026
* Fix import sorting: add blank line between stdlib and third-party imports

Ruff I001 was failing because the typing import ran directly into
the mashumaro import without a blank line separator.

https://claude.ai/code/session_01K8GeVjG7MjJzhZMtrzRh48

* Remove fragile get_media_names_from_notetype mock in client tests

Replace `lambda mid: {}` (which would crash with KeyError if the mock
were removed) with a proper empty notetype dict `{"css": "", "tmpls": []}`.
This removes the implicit dependency on the get_media_names_from_notetype
mock and makes each call site self-sufficient.

https://claude.ai/code/session_01K8GeVjG7MjJzhZMtrzRh48

* Fix mypy errors: wrap mid with NotetypeId() for ModelManager.get() calls

https://claude.ai/code/session_01K8GeVjG7MjJzhZMtrzRh48

---------

Co-authored-by: Claude <noreply@anthropic.com>
@RisingOrange RisingOrange marked this pull request as ready for review February 13, 2026 12:47
@RisingOrange RisingOrange requested a review from abdnh February 13, 2026 12:47
@RisingOrange
Copy link
Collaborator Author

@abdnh This isn't so important, but I think it would be better for the ankihub client to not depend on anki/aqt code

@RisingOrange RisingOrange merged commit 9747480 into main Feb 13, 2026
8 checks passed
@RisingOrange RisingOrange deleted the claude/remove-aqt-import-v1YsX branch February 13, 2026 12:56
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