Skip to content

Commit

Permalink
Avoid runtime dependency on plone.app.upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
davisagli committed Jun 17, 2024
1 parent db36cad commit 3c2cabc
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions news/142.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove runtime dependency on plone.app.upgrade. @davisagli
27 changes: 27 additions & 0 deletions src/plone/volto/bbb.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# flake8: noqa
from types import ModuleType

import sys


try:
from plone.base.interfaces import IPloneSiteRoot
Expand All @@ -9,3 +13,26 @@
from plone.base.utils import get_installer
except ImportError:
from Products.CMFPlone.utils import get_installer


# This was copied from plone.app.upgrade
# to avoid a hard dependency on it.
def alias_module(name, target):
parts = name.split(".")
i = 0
module = None
while i < len(parts) - 1:
i += 1
module_name = ".".join(parts[:i])
try:
__import__(module_name)
except ImportError:
new_module = ModuleType(module_name)
sys.modules[module_name] = new_module
if module is not None:
setattr(module, parts[i - 1], new_module)
module = sys.modules[module_name]

setattr(module, parts[-1], target)
# also make sure sys.modules is updated
sys.modules[module_name + "." + parts[-1]] = target
2 changes: 1 addition & 1 deletion src/plone/volto/patches.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from plone.app.upgrade.utils import alias_module
from plone.registry.interfaces import IRegistry
from plone.rest.interfaces import IAPIRequest
from plone.volto import content
from plone.volto import interfaces
from plone.volto import logger
from plone.volto.bbb import alias_module
from plone.volto.interfaces import IVoltoSettings
from Products.SiteErrorLog.SiteErrorLog import _rate_restrict_burst
from Products.SiteErrorLog.SiteErrorLog import _rate_restrict_period
Expand Down

0 comments on commit 3c2cabc

Please sign in to comment.