Skip to content

Commit

Permalink
Merge pull request #20 from ZeitOnline/adapter-discriminator
Browse files Browse the repository at this point in the history
Adjust discriminator for adapters so it matches the one used by zope.component
  • Loading branch information
wosc authored Jan 24, 2025
2 parents 2e4ab6a + a2b2886 commit 7384317
Show file tree
Hide file tree
Showing 18 changed files with 56 additions and 16 deletions.
5 changes: 4 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ Changes
4.2 (unreleased)
----------------

- Nothing changed yet.
- Adjust discriminator for adapters so it matches the one used by the
``zope.component`` ZCML directive (``<adapter factory=""/>``) and thus a
conflict error is raised if there are two registrations for the same
discriminator.


4.1 (2023-03-21)
Expand Down
5 changes: 3 additions & 2 deletions src/grokcore/component/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ class AdapterGrokker(martian.ClassGrokker):
martian.directive(grokcore.component.name)

def execute(self, factory, config, context, provides, name, **kw):
for_ = (context,)
config.action(
discriminator=('adapter', context, provides, name),
discriminator=('adapter', for_, provides, name),
callable=grokcore.component.provideAdapter,
args=(factory, (context,), provides, name),
args=(factory, for_, provides, name),
)
return True

Expand Down
1 change: 0 additions & 1 deletion src/grokcore/component/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
# make this directory a package
1 change: 0 additions & 1 deletion src/grokcore/component/tests/adapter/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
# this is a package
1 change: 0 additions & 1 deletion src/grokcore/component/tests/directive/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
# this is a package
1 change: 0 additions & 1 deletion src/grokcore/component/tests/event/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
# this is a package
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
# fixture package
1 change: 0 additions & 1 deletion src/grokcore/component/tests/inherit/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
#
1 change: 0 additions & 1 deletion src/grokcore/component/tests/order/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
#
1 change: 0 additions & 1 deletion src/grokcore/component/tests/subscriptions/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
# this is a package
1 change: 0 additions & 1 deletion src/grokcore/component/tests/utility/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
# this is a package
1 change: 0 additions & 1 deletion src/grokcore/component/tests/view/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
# this is a package
1 change: 0 additions & 1 deletion src/grokcore/component/tests/zcml/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
# this is a package
26 changes: 26 additions & 0 deletions src/grokcore/component/tests/zcml/conflict.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""
It raises ConflictError if ZCML and grok try to register an adapter from/to
the same classes.
>>> xmlconfig.string('''
... <configure
... xmlns="http://namespaces.zope.org/zope"
... xmlns:grok="http://namespaces.zope.org/grok">
... <include package="zope.component" file="meta.zcml"/>
... <include package="grokcore.component" file="meta.zcml"/>
... <adapter factory=".fixture.ZCMLHome" />
... <grok:grok package="." />
... </configure>''', context)
Traceback (most recent call last):
ConfigurationConflictError: ...
"""

from zope.configuration import xmlconfig

from grokcore.component.tests.zcml import conflictpkg


context = xmlconfig.ConfigurationMachine()
xmlconfig.registerCommonDirectives(context)
context.package = conflictpkg
Empty file.
23 changes: 23 additions & 0 deletions src/grokcore/component/tests/zcml/conflictpkg/fixture.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from zope import component
from zope import interface

import grokcore.component as grok


class Cave(grok.Context):
pass


class IHome(interface.Interface):
pass


@grok.implementer(IHome)
class GrokHome(grok.Adapter):
pass


@component.adapter(Cave)
@interface.implementer(IHome)
class ZCMLHome:
pass
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
# this is a package
1 change: 0 additions & 1 deletion src/grokcore/component/tests/zcml/excludepkg/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
# this is a package

0 comments on commit 7384317

Please sign in to comment.