Skip to content

Commit

Permalink
Soft dependencies on p.a.{discussion,multilingual} (#31)
Browse files Browse the repository at this point in the history
* Soft dependencies on p.a.{discussion,multilingual}

* update dependency ignores

* lint

* changelog
  • Loading branch information
davisagli authored Sep 7, 2024
1 parent d9978bb commit 0513373
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .meta.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ commit-id = "ae379f1f"
[pyproject]
codespell_skip = "*.min.js"
codespell_ignores = "vew"
dependencies_ignores = "['plone.volto', 'plone.app.iterate', 'plone.app.upgrade', 'zestreleaser.towncrier', 'zest.releaser', 'pytest', 'pytest-cov', 'pytest-plone', 'plone.testing', 'plone.app.testing', 'plone.portlets', 'plone.app.portlets']"
dependencies_ignores = "['plone.volto', 'plone.app.discussion', 'plone.app.iterate', 'plone.app.multilingual', 'plone.app.upgrade', 'zestreleaser.towncrier', 'zest.releaser', 'pytest', 'pytest-cov', 'pytest-plone', 'plone.testing', 'plone.app.testing', 'plone.portlets', 'plone.app.portlets']"
dependencies_mappings = [
"Plone = ['Products.CMFPlone', 'Products.CMFCore', 'Products.GenericSetup']",
]
Expand Down
2 changes: 2 additions & 0 deletions news/18.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Use plone.app.discussion and plone.app.multilingual as optional dependencies.
@davisagli
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ Zope = [
'Products.CMFCore', 'Products.CMFDynamicViewFTI',
]
python-dateutil = ['dateutil']
ignore-packages = ['plone.volto', 'plone.app.iterate', 'plone.app.upgrade', 'zestreleaser.towncrier', 'zest.releaser', 'pytest', 'pytest-cov', 'pytest-plone', 'plone.testing', 'plone.app.testing', 'plone.portlets', 'plone.app.portlets']
ignore-packages = ['plone.volto', 'plone.app.discussion', 'plone.app.iterate', 'plone.app.multilingual', 'plone.app.upgrade', 'zestreleaser.towncrier', 'zest.releaser', 'pytest', 'pytest-cov', 'pytest-plone', 'plone.testing', 'plone.app.testing', 'plone.portlets', 'plone.app.portlets']
Plone = ['Products.CMFPlone', 'Products.CMFCore', 'Products.GenericSetup']

##
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@
"plone.api",
"plone.app.contenttypes",
"plone.app.dexterity",
"plone.app.discussion",
"plone.app.multilingual",
"plone.app.redirector",
"plone.app.textfield",
"plone.app.users",
Expand All @@ -76,7 +74,9 @@
"test": [
"zest.releaser[recommended]",
"zestreleaser.towncrier",
"plone.app.discussion",
"plone.app.iterate",
"plone.app.multilingual",
"plone.app.testing",
"plone.app.upgrade",
"plone.restapi[test]",
Expand Down
2 changes: 0 additions & 2 deletions src/plone/exportimport/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
<include package="Products.CMFPlone" />
<include package="plone.namedfile" />
<include package="plone.app.dexterity" />
<include package="plone.app.discussion" />
<include package="plone.app.multilingual" />
<include package="plone.restapi" />

<include package=".serializers" />
Expand Down
15 changes: 14 additions & 1 deletion src/plone/exportimport/exporters/discussions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,30 @@
from pathlib import Path
from plone.exportimport import interfaces
from plone.exportimport import logger
from plone.exportimport.utils import discussions as utils
from typing import List
from zope.interface import implementer


try:
import plone.app.discussion # noqa
except ImportError:
HAS_DISCUSSION = False
else:
HAS_DISCUSSION = True


@implementer(interfaces.INamedExporter)
class DiscussionsExporter(BaseExporter):
name: str = "discussions"

def dump(self) -> List[Path]:
"""Serialize object and dump it to disk."""
if not HAS_DISCUSSION:
logger.debug("- Discussions: Skipping (plone.app.discussion not installed)")
return

from plone.exportimport.utils import discussions as utils

discussions = utils.get_discussions()
filepath = self._dump(discussions, self.filepath)
logger.debug(
Expand Down
10 changes: 9 additions & 1 deletion src/plone/exportimport/importers/discussions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from .base import BaseImporter
from plone.exportimport import logger
from plone.exportimport.utils import discussions as utils


class DiscussionsImporter(BaseImporter):
Expand All @@ -11,6 +10,15 @@ def do_import(self) -> dict:
data = self._read()
if data is None:
return f"{self.__class__.__name__}: No data to import"

try:
from plone.exportimport.utils import discussions as utils
except ImportError:
logger.warning(
"- Discussions: Skipping (plone.app.discussion not installed)"
)
return

logger.debug(f"- Discussions: Read {len(data)} from {self.filepath}")
results = utils.set_discussions(data)
return f"{self.__class__.__name__}: Imported {len(results)} conversations"
15 changes: 10 additions & 5 deletions src/plone/exportimport/utils/cli.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from AccessControl.SecurityManagement import newSecurityManager
from AccessControl.users import system as user
from pathlib import Path
from plone.app.discussion.interfaces import IDiscussionLayer # Needed by plone.restapi
from plone.restapi.interfaces import IPloneRestapiLayer
from Products.CMFPlone.Portal import PloneSite
from Testing.makerequest import makerequest
Expand Down Expand Up @@ -40,10 +39,16 @@ def get_app(zopeconf: Path):
request = app.REQUEST
app.REQUEST["PARENTS"] = [app]
setRequest(app.REQUEST)
ifaces = [
IPloneRestapiLayer,
IDiscussionLayer,
] + list(directlyProvidedBy(request))
ifaces = [IPloneRestapiLayer]
try:
from plone.app.discussion.interfaces import (
IDiscussionLayer, # Needed by plone.restapi
)
except ImportError:
pass
else:
ifaces.append(IDiscussionLayer)
ifaces += list(directlyProvidedBy(request))

directlyProvides(request, *ifaces)
newSecurityManager(None, user)
Expand Down
10 changes: 8 additions & 2 deletions src/plone/exportimport/utils/content/export_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from Acquisition import aq_base
from Acquisition import aq_parent
from plone import api
from plone.app.discussion.interfaces import IConversation
from plone.base.interfaces.constrains import ENABLED
from plone.base.interfaces.constrains import ISelectableConstrainTypes
from plone.dexterity.content import DexterityContent
Expand All @@ -24,6 +23,12 @@
import json


try:
from plone.app.discussion.interfaces import IConversation
except ImportError:
IConversation = None


def get_serializer(obj, request) -> Callable:
return getMultiAdapter((obj, request), ISerializeToJson)

Expand Down Expand Up @@ -281,8 +286,9 @@ def enrichers() -> List[types.ExportImportHelper]:
add_constrains_info,
add_workflow_history,
add_revisions_history,
add_conversation,
]
if IConversation is not None:
funcs.append(add_conversation)
for func in funcs:
enrichers.append(
types.ExportImportHelper(
Expand Down
11 changes: 10 additions & 1 deletion src/plone/exportimport/utils/translations.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
from .content.core import get_obj_path
from .content.core import get_portal_languages
from plone import api
from plone.app.multilingual.interfaces import ITranslationManager
from plone.dexterity.content import DexterityContent
from plone.exportimport import logger
from Products.CMFPlone.CatalogTool import CatalogTool
from typing import List
from typing import Tuple


try:
from plone.app.multilingual.interfaces import ITranslationManager
except ImportError:
HAS_MULTILINGUAL = False
else:
HAS_MULTILINGUAL = True

TRANSLATION_INDEX = "TranslationGroup"


Expand Down Expand Up @@ -109,6 +115,9 @@ def link_translations(

def set_translations(data: List[dict]) -> List[dict]:
"""Process a list of translations and add them to the Plone site."""
if not HAS_MULTILINGUAL:
logger.warning("- Translation: Skipping (plone.app.multilingual not installed)")
return
results = []
for item in data:
translation_group = _parse_translation_group(item)
Expand Down

0 comments on commit 0513373

Please sign in to comment.