For package installations, handle version mismatches with higher version winning, and store installed packages to handle downgrades #78
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.
As mentioned in #70 the original implementation of installing packages from
requirements.txt
had some limitations, primarily around version mismatches. The previous code didn't do anything to address the case where different pyscriptrequirements.txt
's had different version requirements for the same package, it would simply tell HA to install them in the order they were found, resulting in the last version found being installed.This change does several things:
pyscript
- This is necessary to handle scenarios where users want to downgrade a package they installed throughpyscript
. We want to let them downgrade throughpyscript
but not if it was installed via another source.requirements.txt
. Pinned versions will always take precedence over unpinned versionspyscript
(and this handles if it was originally installed bypyscript
but another actor came in after the fact and changed the version) - this would allow users to downgrade packages as needed but would protect Home Assistant in case it takes over package management for a package installation thatpyscript
used to manageThere is complexity introduced by this change, but I tried to be comprehensive in my tests to account for that. I also moved the package logic into a separate module to keep
__init__.py
clean and to make it easier to write tests, so the number of lines changed looks bigger than it actually is.As a note, you must either leave a package unpinned or pin it using the
==
specifier. This reduces the already quite complex complexity of the package version resolution logic.