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

fix: importlib-metadata as a dependency on Python>=3.10 #839

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

hr1shu
Copy link

@hr1shu hr1shu commented Nov 21, 2024

Issue Summary

The zulip_bots package attempts to import importlib_metadata regardless of the Python version, even though importlib-metadata is not listed as a dependency in the package. This leads to an ImportError on Python versions >= 3.10, where importlib.metadata is included in the standard library, but the fallback to importlib_metadata is still attempted.

Root Cause

The error occurs because the code in zulip_bots does not correctly handle the conditional import for importlib-metadata vs. the standard library's importlib.metadata. The setup.py configuration ensures the dependency is installed only for Python < 3.10, but the runtime code doesn't account for the difference in module naming.

Solution

To fix the issue, I modified the code in zulip_bots/finder.py to conditionally import the appropriate module based on the Python version.

Testing

Verified behavior on Python 3.9 and Python 3.10+ environments:
Python >= 3.10: Uses importlib.metadata.
Python < 3.10: Falls back to importlib_metadata.
Added unit tests to validate both paths with mock objects.

Impact

This fix ensures that:

The package correctly resolves metadata imports regardless of Python version.
Dependencies are installed appropriately based on the Python version.

@zulipbot zulipbot added size: S and removed size: M labels Nov 21, 2024
@hr1shu
Copy link
Author

hr1shu commented Nov 21, 2024

Hi @timabbott, although the fix is done and it's working fine locally, can anyone help me understand why checks are failing?

@timabbott
Copy link
Member

Can you clean up your PR? Check out our GitHub guide and commit guidelines for more details, as well as the contributing guide.

Test failures seem related to your changes, try testing locally with those Python versions.

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.

3 participants