Skip to content

Update launch_utils.py - fixes repetead package reinstalls#14192

Merged
AUTOMATIC1111 merged 2 commits intoAUTOMATIC1111:devfrom
illtellyoulater:patch-1
Dec 4, 2023
Merged

Update launch_utils.py - fixes repetead package reinstalls#14192
AUTOMATIC1111 merged 2 commits intoAUTOMATIC1111:devfrom
illtellyoulater:patch-1

Conversation

@illtellyoulater
Copy link
Contributor

@illtellyoulater illtellyoulater commented Dec 4, 2023

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:

launch_utils.run_pip("install ffmpeg-python", "required package");

[ Installing required package: "ffmpeg-python" ... ] [ Installed ]

launch_utils.is_installed("ffmpeg-python");

False

...which would actually return true with:

launch_utils.is_installed("ffmpeg");

True

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:

pkg_metadata = importlib.metadata.distribution(mod_name);

<importlib.metadata.PathDistribution object at 0x7fe14698a290>

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:

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 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:

> launch_utils.run_pip("install ffmpeg-python", "required package")
[ Installing required package: "ffmpeg-python" ... ]
[ Installed ]

> launch_utils.is_installed("ffmpeg-python")
False

... which would actually return true with:

> launch_utils.is_installed("ffmpeg")
True
@AUTOMATIC1111 AUTOMATIC1111 merged commit 208760f into AUTOMATIC1111:dev Dec 4, 2023
@w-e-w w-e-w mentioned this pull request Dec 4, 2023
@illtellyoulater illtellyoulater deleted the patch-1 branch December 4, 2023 08:00
@illtellyoulater illtellyoulater restored the patch-1 branch December 4, 2023 08:03
@w-e-w w-e-w mentioned this pull request Dec 16, 2023
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