Skip to content

Conversation

@mart-r
Copy link
Collaborator

@mart-r mart-r commented Dec 20, 2025

When a partial set of extra dependencies are installed, the current process allows the import to continue. This could happen (for instance) if the user manually installs some of the deps, or if they've installed them as part of another optional extra.

This PR will fix that by fixing that logic.

The first commit will fail due to having added the test. The subsequent commit will succeed since the logic is fixed.

EDIT:
Turned out I also had to do a remap of scikit-learn to sklearn for the checks.

@tomolopolis
Copy link
Member

req = get_required_extra_deps(package_name, extra_name)
if not req:
raise IncorrectExtraComponent(package_name, extra_name)
if len(installed) != len(req):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this will miss if you happen to have exactly the same count of deps, just not the same

Could you instead always get missing? Something like this?

Suggested change
if len(installed) != len(req):
missing = [requirement for requirement in req
if requirement not in installed]
if missing:
raise MissingDependenciesError(package_name, extra_name, missing)

Else generally doing however set difference should work in python anyway...

Copy link
Collaborator Author

@mart-r mart-r Jan 5, 2026

Choose a reason for hiding this comment

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

The current implementation guarantees that if the lengths are the same, then the installed dependencies are correct. That's because the get_installed_extra_dependencies method uses get_required_extra_deps insternally and only returns a sub-list that contains the deps that are actually installed.

With that said, changing these to sets and doing a set comparison may be a more robust option overall.

self,
mock_get_required_extra_deps,
mock_get_installed_extra_dependencies):
mock_get_installed_extra_dependencies.return_value = ["A", "B", "C"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would like an extra test for ["A,B"] vs ["B", "C"] just to assert that it isnt just length of deps

Copy link
Collaborator

@alhendrickson alhendrickson left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

@mart-r mart-r merged commit 6291baa into main Jan 5, 2026
21 checks passed
@mart-r mart-r deleted the bug/medcat/CU-869bj3d4g-fix-issue-with-missing-deps branch January 5, 2026 11:22
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.

4 participants