Update launch_utils.py - fixes repetead package reinstalls #14192
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Fixes failing dependency checks for extensions having a different package name and import name (for example ffmpeg-python / ffmpeg), which currently is causing the unneeded reinstall of packages at runtime.
In fact with the current code, the same string is used when installing a package and when checking for its presence, as you can see in the following example:
...which would actually return true with:
This PR modifies is_installed() from
launch_utils.py
so that it correctly confirms that a package is installed by returning a valid metadata object when passed the import name of an installed module, like this:I've been using this for a couple of months now, without noticing any issues at all (as documented by #13487)
In case the above method fails, the code tries validating for package existence using the previous method... which if IIRC was still useful in some specific conditions...
Checklist: