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

Avoid runtime dependency on plone.app.upgrade #150

Merged
merged 1 commit into from
Jun 17, 2024
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
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
Loading