Fix #123710: Remote repo re-used when installing from file selector

Functionality from [0] to skip-saving remote repositories was only
applied when dropping extensions. Now this is done when installing
from the file selector too.

[0]: 9b7f2c9976
This commit is contained in:
Campbell Barton
2024-06-26 00:32:00 +10:00
parent 17951d12ed
commit fcba8b8099

View File

@@ -2105,6 +2105,25 @@ class EXTENSIONS_OT_package_install_files(Operator, _ExtCmdMixIn):
return True
def invoke(self, context, event):
# Regarding reusing the last repository.
# - If it's a "local" repository, use it.
# - If it's a "remote" repository, reset.
# This is done because installing a file into a remote repository is a corner-case supported so
# it's possible to download large extensions before installing or to down-grade to older versions.
# Installing into a remote repository should be intentional, not the default.
# This could be annoying to users if they want to install many files into a remote repository,
# in this case they would be better off using the file selector "Install from disk"
# which supports selecting multiple files, although support for dropping multiple files would
# also be good to support.
if not self.properties.is_property_set("repo"):
repos_valid = self._repos_valid_for_install(context)
repo_module = self.repo
if (repo_test := next((repo for repo in repos_valid if repo.module == repo_module), None)) is not None:
if repo_test.use_remote_url:
self.properties.property_unset("repo")
del repo_module, repo_test, repos_valid
if self.properties.is_property_set("url"):
return self._invoke_for_drop(context, event)
@@ -2167,8 +2186,7 @@ class EXTENSIONS_OT_package_install_files(Operator, _ExtCmdMixIn):
from .bl_extension_utils import pkg_manifest_dict_from_file_or_error
repos_valid = list(repo_iter_valid_only(context, exclude_remote=False, exclude_system=True))
if not repos_valid:
if not self._repos_valid_for_install():
self.report({'ERROR'}, "No user repositories")
return {'CANCELLED'}
@@ -2181,24 +2199,6 @@ class EXTENSIONS_OT_package_install_files(Operator, _ExtCmdMixIn):
del result
self._drop_variables = pkg_id, pkg_type
# Regarding reusing the last repository.
# - If it's a "local" repository, use it.
# - If it's a "remote" repository, reset.
# This is done because installing a file into a remote repository is a corner-case supported so
# it's possible to download large extensions before installing or to down-grade to older versions.
# Installing into a remote repository should be intentional, not the default.
# This could be annoying to users if they want to install many files into a remote repository,
# in this case they would be better off using the file selector "Install from disk"
# which supports selecting multiple files, although support for dropping multiple files would
# also be good to support.
if not self.properties.is_property_set("repo"):
repo_module = self.repo
if (repo_test := next((repo for repo in repos_valid if repo.module == repo_module), None)) is not None:
if repo_test.use_remote_url:
self.properties.property_unset("repo")
del repo_module, repo_test
else:
self._drop_variables = None
self._legacy_drop = True
@@ -2234,6 +2234,10 @@ class EXTENSIONS_OT_package_install_files(Operator, _ExtCmdMixIn):
layout.prop(self, "overwrite", text="Overwrite")
layout.prop(self, "enable_on_install")
@staticmethod
def _repos_valid_for_install(context):
return list(repo_iter_valid_only(context, exclude_remote=False, exclude_system=True))
class EXTENSIONS_OT_package_install(Operator, _ExtCmdMixIn):
"""Download and install the extension"""