-
Notifications
You must be signed in to change notification settings - Fork 5.9k
[Refactor] Minor Improvement for import utils #11161
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
Conversation
@bot /style |
Style fixes have been applied. View the workflow run here. |
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
ccd99a1
to
6bb876f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the iteration. Looks like packages_distributions
was only added in 3.10
https://docs.python.org/3/library/importlib.metadata.html#importlib.metadata.packages_distributions
Can you look into alternatives?
Couldn't find alternatives, but pulled out some code from packages_distribution from
Let me know if this looks good to you ? I have tested works fine for python [3.8, 3.9, 3.10] |
LGTM, thanks! |
656a19f
to
68bb955
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors the _is_package_available function to handle the case where the package name used for import differs from the distribution name used for installation. It also consolidates the logic for determining package version and updates the optimum_quanto check accordingly.
- Updated _is_package_available signature to return a tuple (availability, version) and added an optional get_dist_name parameter.
- Integrated a fallback mechanism for package distribution lookup and refactored the optimum_quanto availability check.
- Added necessary imports and extended the collections import for defaultdict.
Comments suppressed due to low confidence (1)
src/diffusers/utils/import_utils.py:87
- [nitpick] Consider using a separate variable (e.g., 'dist_name') instead of overwriting 'pkg_name' when get_dist_name is True. This improves code clarity by distinguishing between the module name and the distribution name.
pkg_name = package_map[pkg_name][0]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks!
What does this PR do?
At times pkg_name (used for import) and dist_name (used for install) are different. The
_is_package_available
function doesnt work for that see here. This PR helps resolve this through_is_package_available
function.Who can review?
@DN6 @hlky