Skip to content
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

Mark add-on store code as public API #15777

Merged
merged 1 commit into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions source/addonHandler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
from NVDAState import WritePaths
from types import ModuleType

from _addonStore.models.status import AddonStateCategory, SupportsAddonState
from _addonStore.models.version import MajorMinorPatch, SupportsVersionCheck
from addonStore.models.status import AddonStateCategory, SupportsAddonState
from addonStore.models.version import MajorMinorPatch, SupportsVersionCheck
import extensionPoints
from utils.caseInsensitiveCollections import CaseInsensitiveSet

Expand All @@ -53,7 +53,7 @@
)

if TYPE_CHECKING:
from _addonStore.models.addon import ( # noqa: F401
from addonStore.models.addon import ( # noqa: F401
AddonManifestModel,
AddonHandlerModelGeneratorT,
InstalledAddonStoreModel,
Expand Down Expand Up @@ -203,7 +203,7 @@ def cleanupRemovedDisabledAddons(self) -> None:
self[AddonStateCategory.DISABLED].discard(disabledAddonName)

def _cleanupCompatibleAddonsFromDowngrade(self) -> None:
from _addonStore.dataManager import addonDataManager
from addonStore.dataManager import addonDataManager
installedAddons = addonDataManager._installedAddonsCache.installedAddons
for blockedAddon in CaseInsensitiveSet(
self[AddonStateCategory.BLOCKED].union(
Expand Down Expand Up @@ -450,13 +450,13 @@ def manifest(self) -> "AddonManifest":

@property
def _addonStoreData(self) -> Optional["InstalledAddonStoreModel"]:
from _addonStore.dataManager import addonDataManager
from addonStore.dataManager import addonDataManager
assert addonDataManager
return addonDataManager._getCachedInstalledAddonData(self.name)

@property
def _addonGuiModel(self) -> "AddonManifestModel":
from _addonStore.models.addon import _createGUIModelFromManifest
from addonStore.models.addon import _createGUIModelFromManifest
return _createGUIModelFromManifest(self)


Expand Down Expand Up @@ -593,7 +593,7 @@ def enable(self, shouldEnable: bool) -> None:
else:
if self.canOverrideCompatibility and not self.overrideIncompatibility:
from gui import mainFrame
from gui._addonStoreGui.controls.messageDialogs import _shouldInstallWhenAddonTooOldDialog
from gui.addonStoreGui.controls.messageDialogs import _shouldInstallWhenAddonTooOldDialog
if not _shouldInstallWhenAddonTooOldDialog(mainFrame, self._addonGuiModel):
import addonAPIVersion
raise AddonError("Add-on is not compatible and over ride was abandoned")
Expand Down
2 changes: 1 addition & 1 deletion source/addonHandler/addonVersionCheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import addonAPIVersion

if TYPE_CHECKING:
from _addonStore.models.version import SupportsVersionCheck # noqa: F401
from addonStore.models.version import SupportsVersionCheck # noqa: F401


def hasAddonGotRequiredSupport(
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
from addonHandler import Addon as AddonHandlerModel # noqa: F401
# AddonGUICollectionT must only be imported when TYPE_CHECKING
from .models.addon import AddonGUICollectionT, _AddonStoreModel # noqa: F401
from gui._addonStoreGui.viewModels.addonList import AddonListItemVM # noqa: F401
from gui.addonStoreGui.viewModels.addonList import AddonListItemVM # noqa: F401
from gui.message import DisplayableError # noqa: F401


Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ class SupportsVersionCheck(Protocol):
""" Examples implementing this protocol include:
- addonHandler.Addon
- addonHandler.AddonBundle
- _addonStore.models._AddonGUIModel
- _addonStore.models._AddonStoreModel
- _addonStore.models.AddonManifestModel
- _addonStore.models.AddonStoreModel
- _addonStore.models.InstalledAddonStoreModel
- addonStore.models._AddonGUIModel
- addonStore.models._AddonStoreModel
- addonStore.models.AddonManifestModel
- addonStore.models.AddonStoreModel
- addonStore.models.InstalledAddonStoreModel
"""
minimumNVDAVersion: addonAPIVersion.AddonApiVersionT
lastTestedNVDAVersion: addonAPIVersion.AddonApiVersionT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

if TYPE_CHECKING:
from gui.message import DisplayableError
from gui._addonStoreGui.viewModels.addonList import AddonListItemVM
from gui.addonStoreGui.viewModels.addonList import AddonListItemVM


_BASE_URL = "https://nvaccess.org/addonStore"
Expand Down
4 changes: 2 additions & 2 deletions source/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def resetConfiguration(factoryDefaults=False):
log.debug("setting language to %s"%lang)
languageHandler.setLanguage(lang)
# Addons
from _addonStore import dataManager
from addonStore import dataManager
dataManager.initialize()
addonHandler.initialize()
# Hardware background i/o
Expand Down Expand Up @@ -532,7 +532,7 @@ def main():
import socket
socket.setdefaulttimeout(10)
log.debug("Initializing add-ons system")
from _addonStore import dataManager
from addonStore import dataManager
dataManager.initialize()
addonHandler.initialize()
if globalVars.appArgs.disableAddons:
Expand Down
4 changes: 2 additions & 2 deletions source/gui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,8 @@ def onAddonsManagerCommand(self, evt: wx.MenuEvent):
blockAction.Context.RUNNING_LAUNCHER,
)
def onAddonStoreCommand(self, evt: wx.MenuEvent):
from ._addonStoreGui import AddonStoreDialog
from ._addonStoreGui.viewModels.store import AddonStoreVM
from .addonStoreGui import AddonStoreDialog
from .addonStoreGui.viewModels.store import AddonStoreVM
_storeVM = AddonStoreVM()
_storeVM.refresh()
self.popupSettingsDialog(AddonStoreDialog, _storeVM)
Expand Down
22 changes: 11 additions & 11 deletions source/gui/addonGui.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def onRemoveClick(self, evt: wx.EVT_BUTTON):
if index < 0:
return
addon = self.curAddons[index]
from gui._addonStoreGui.controls.messageDialogs import _shouldProceedToRemoveAddonDialog
from gui.addonStoreGui.controls.messageDialogs import _shouldProceedToRemoveAddonDialog
if not _shouldProceedToRemoveAddonDialog(addon):
return
addon.requestRemove()
Expand Down Expand Up @@ -342,7 +342,7 @@ def refreshAddonsList(self, activeIndex: int = 0) -> None:
self.addonsList.DeleteAllItems()
self.curAddons: List[Addon] = []
anyAddonIncompatible = False
from _addonStore.dataManager import addonDataManager
from addonStore.dataManager import addonDataManager
assert addonDataManager
installedAddons = addonDataManager._installedAddonsCache.installedAddons
for addon in sorted(installedAddons.values(), key=lambda a: strxfrm(a.manifest['summary'])):
Expand Down Expand Up @@ -410,7 +410,7 @@ def onAbout(self, evt: wx.EVT_BUTTON):
index: int = self.addonsList.GetFirstSelected()
if index<0: return
addon = self.curAddons[index]
from gui._addonStoreGui.controls.messageDialogs import _showAddonInfo
from gui.addonStoreGui.controls.messageDialogs import _showAddonInfo
_showAddonInfo(addon._addonGuiModel)

def onHelp(self, evt):
Expand All @@ -430,7 +430,7 @@ def onEnableDisable(self, evt: wx.EVT_BUTTON):
# Counterintuitive, but makes sense when context is taken into account.
addon.enable(not shouldDisable)
except addonHandler.AddonError:
from gui._addonStoreGui.viewModels.store import AddonStoreVM
from gui.addonStoreGui.viewModels.store import AddonStoreVM
log.error("Couldn't change state for %s add-on"%addon.name, exc_info=True)
if shouldDisable:
message = AddonStoreVM._disableErrorMessage.format(addon=addon.manifest['summary'])
Expand Down Expand Up @@ -467,7 +467,7 @@ def installAddon(parentWindow: wx.Window, addonPath: str) -> bool: # noqa: C901
Any error messages / warnings are presented to the user via a GUI message box.
If attempting to install an addon that is pending removal, it will no longer be pending removal.
@return True on success or False on failure.
@note See also L{_addonStore.install.installAddon}
@note See also L{addonStore.install.installAddon}
"""
try:
bundle = addonHandler.AddonBundle(addonPath)
Expand All @@ -486,7 +486,7 @@ def installAddon(parentWindow: wx.Window, addonPath: str) -> bool: # noqa: C901
_showAddonRequiresNVDAUpdateDialog(parentWindow, bundle)
return False # Exit early, addon does not have required support
elif bundle.canOverrideCompatibility:
from gui._addonStoreGui.controls.messageDialogs import _shouldInstallWhenAddonTooOldDialog
from gui.addonStoreGui.controls.messageDialogs import _shouldInstallWhenAddonTooOldDialog
if _shouldInstallWhenAddonTooOldDialog(parentWindow, bundle._addonGuiModel):
# Install incompatible version
if not bundle.overrideIncompatibility:
Expand All @@ -497,7 +497,7 @@ def installAddon(parentWindow: wx.Window, addonPath: str) -> bool: # noqa: C901
elif wx.YES != _showConfirmAddonInstallDialog(parentWindow, bundle):
return False # Exit early, User changed their mind about installation.

from _addonStore.install import _getPreviouslyInstalledAddonById
from addonStore.install import _getPreviouslyInstalledAddonById
prevAddon = _getPreviouslyInstalledAddonById(bundle)
if prevAddon:
summary=bundle.manifest["summary"]
Expand Down Expand Up @@ -558,7 +558,7 @@ def doneAndDestroy(window):
with doneAndDestroy(progressDialog):
gui.ExecAndPump(addonHandler.installAddonBundle, bundle)
if prevAddon:
from _addonStore.dataManager import addonDataManager
from addonStore.dataManager import addonDataManager
assert addonDataManager
# External install should remove cached add-on
addonDataManager._deleteCacheInstalledAddon(prevAddon.name)
Expand Down Expand Up @@ -607,7 +607,7 @@ def _showAddonRequiresNVDAUpdateDialog(
minimumNVDAVersion=addonAPIVersion.formatForGUI(bundle.minimumNVDAVersion),
NVDAVersion=addonAPIVersion.formatForGUI(addonAPIVersion.CURRENT)
)
from gui._addonStoreGui.controls.messageDialogs import _showAddonInfo
from gui.addonStoreGui.controls.messageDialogs import _showAddonInfo
displayDialogAsModal(ErrorAddonInstallDialog(
parent=parent,
# Translators: The title of a dialog presented when an error occurs.
Expand All @@ -628,7 +628,7 @@ def _showConfirmAddonInstallDialog(
"Addon: {summary} {version}"
).format(**bundle.manifest)

from gui._addonStoreGui.controls.messageDialogs import _showAddonInfo
from gui.addonStoreGui.controls.messageDialogs import _showAddonInfo
return displayDialogAsModal(ConfirmAddonInstallDialog(
parent=parent,
# Translators: Title for message asking if the user really wishes to install an Addon.
Expand Down Expand Up @@ -766,7 +766,7 @@ def onAbout(self, evt: wx.EVT_BUTTON):
index: int = self.addonsList.GetFirstSelected()
if index<0: return
addon = self.curAddons[index]
from gui._addonStoreGui.controls.messageDialogs import _showAddonInfo
from gui.addonStoreGui.controls.messageDialogs import _showAddonInfo
_showAddonInfo(addon._addonGuiModel)

def onClose(self, evt):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import wx

from _addonStore.models.status import _StatusFilterKey
from addonStore.models.status import _StatusFilterKey
from logHandler import log
import ui

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import wx

from _addonStore.models.addon import (
from addonStore.models.addon import (
_AddonStoreModel,
_AddonManifestModel,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import wx

import addonAPIVersion
from _addonStore.models.addon import (
from addonStore.models.addon import (
_AddonGUIModel,
_AddonStoreModel,
_AddonManifestModel,
Expand All @@ -28,7 +28,7 @@
import windowUtils

if TYPE_CHECKING:
from _addonStore.models.version import SupportsVersionCheck
from addonStore.models.version import SupportsVersionCheck


class ErrorAddonInstallDialogWithYesNoButtons(ErrorAddonInstallDialog):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
from addonHandler import (
BUNDLE_EXTENSION,
)
from _addonStore.dataManager import addonDataManager
from _addonStore.models.channel import Channel, _channelFilters
from _addonStore.models.status import (
from addonStore.dataManager import addonDataManager
from addonStore.models.channel import Channel, _channelFilters
from addonStore.models.status import (
EnabledStatus,
_statusFilters,
_StatusFilterKey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@

from requests.structures import CaseInsensitiveDict

from _addonStore.models.addon import (
from addonStore.models.addon import (
_AddonGUIModel,
_AddonStoreModel,
_AddonManifestModel,
)
from _addonStore.models.status import (
from addonStore.models.status import (
_StatusFilterKey,
AvailableAddonStatus,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,26 @@
import threading

import addonHandler
from _addonStore.dataManager import addonDataManager
from _addonStore.install import installAddon
from _addonStore.models.addon import (
from addonStore.dataManager import addonDataManager
from addonStore.install import installAddon
from addonStore.models.addon import (
_createAddonGUICollection,
_AddonGUIModel,
_AddonManifestModel,
_AddonStoreModel,
)
from _addonStore.models.channel import (
from addonStore.models.channel import (
Channel,
_channelFilters,
)
from _addonStore.models.status import (
from addonStore.models.status import (
EnabledStatus,
getStatus,
_statusFilters,
_StatusFilterKey,
AvailableAddonStatus,
)
from _addonStore.network import AddonFileDownloader
from addonStore.network import AddonFileDownloader
import core
import extensionPoints
from gui.message import DisplayableError
Expand Down
2 changes: 1 addition & 1 deletion source/gui/installerGui.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def __init__(self, parent, isUpdate):
super().__init__(parent, title=_("Install NVDA"))

import addonHandler
from _addonStore.models.version import (
from addonStore.models.version import (
getAddonCompatibilityConfirmationMessage,
getAddonCompatibilityMessage,
)
Expand Down
2 changes: 1 addition & 1 deletion source/updateCheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
from gui import guiHelper
from gui.message import displayDialogAsModal # noqa: E402
from addonHandler import getCodeAddon, AddonError, getIncompatibleAddons
from _addonStore.models.version import ( # noqa: E402
from addonStore.models.version import ( # noqa: E402
getAddonCompatibilityMessage,
getAddonCompatibilityConfirmationMessage,
)
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/test_addonHandler/test_addonsState.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

import unittest

import _addonStore.models.status
from _addonStore.models.version import MajorMinorPatch
import addonStore.models.status
from addonStore.models.version import MajorMinorPatch
import addonHandler
import utils.caseInsensitiveCollections

Expand All @@ -21,7 +21,7 @@ def test_expectedDefaultValsInState(self):
self.assertEqual(state.manualOverridesAPIVersion.major, 2023)
self.assertEqual(state.manualOverridesAPIVersion.minor, 1)
self.assertEqual(state.manualOverridesAPIVersion.patch, 0)
for stateKey in _addonStore.models.status.AddonStateCategory:
for stateKey in addonStore.models.status.AddonStateCategory:
stateVals = state.pop(stateKey)
self.assertEqual(stateVals, utils.caseInsensitiveCollections.CaseInsensitiveSet())
# Verify that only known categories are in the state.
Expand All @@ -37,7 +37,7 @@ def setUp(self) -> None:

def test_addonNamesCaseInsensitive(self):
self.state.fromPickledDict({"pendingRemovesSet": set(("foo", "FOO"))})
self.assertEqual(self.state[_addonStore.models.status.AddonStateCategory.PENDING_REMOVE], {"foo"})
self.assertEqual(self.state[addonStore.models.status.AddonStateCategory.PENDING_REMOVE], {"foo"})

def test_noBackCompatInStateBackCompatSetToDefault(self):
self.state.fromPickledDict({"pendingRemovesSet": set(("foo", "FOO"))})
Expand Down Expand Up @@ -83,9 +83,9 @@ def test_stateConvertedToBuiltInTypes(self):
# All keys in the state should be strings, all values should be plain sets.
for key in dataForPickling.keys():
# Compare by identity, to make sure keys are not enum members.
self.assertIs(key, _addonStore.models.status.AddonStateCategory(key).value)
self.assertIs(key, addonStore.models.status.AddonStateCategory(key).value)

for knownStateKey in _addonStore.models.status.AddonStateCategory:
for knownStateKey in addonStore.models.status.AddonStateCategory:
value = dataForPickling.pop(knownStateKey.value)
# Verify the values are converted to standard sets, by adding two strings which differ in case.
# Normal sets should preserve them both.
Expand Down