Removing dependency between zope.location and zope.copy

Fabio Tranchitella <[email protected]>
Newsgroups gmane.comp.web.zope.devel
Message-ID <[email protected]>
Hello,

I'm wondering if it would be possible to drop the dependency between
zope.location and zope.copy. It makes sense to me because zope.location
depends on zope.copy only because it registers a LocationCopyHook, not
because it is really using anything from that package.

Attached to this message you can find my (proposed) patch to remove the
dependency making the adapter registration optional, and informing the
developer that zope.copy is needed is he is importing directly the
zope.location.pickling module.

Comments?

Thanks,
Fabio

_______________________________________________
Zope-Dev maillist  -  [email protected]
https://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 https://mail.zope.org/mailman/listinfo/zope-announce
 https://mail.zope.org/mailman/listinfo/zope )
zope.location-without-zope.copy.diff (text/x-diff, 2.7 KB)
Index: buildout.cfg
===================================================================
--- buildout.cfg	(revisione 106858)
+++ buildout.cfg	(copia locale)
@@ -4,11 +4,11 @@
 
 [test]
 recipe = zc.recipe.testrunner
-eggs = zope.location
+eggs = zope.location [test]
 
 [coverage-test]
 recipe = zc.recipe.testrunner
-eggs = zope.location
+eggs = zope.location [test]
 defaults = ['--coverage', '../../coverage']
 
 [coverage-report]
Index: src/zope/location/configure.zcml
===================================================================
--- src/zope/location/configure.zcml	(revisione 106858)
+++ src/zope/location/configure.zcml	(copia locale)
@@ -1,7 +1,9 @@
-<configure xmlns="http://namespaces.zope.org/zope">
+<configure xmlns="http://namespaces.zope.org/zope"
+           zcml:xmlns="http://namespaces.zope.org/zcml">
 
   <adapter factory=".location.LocationProxy" />
-  <adapter factory=".pickling.LocationCopyHook" />
+  <adapter zcml:condition="installed zope.copy"
+           factory=".pickling.LocationCopyHook" />
   <adapter factory=".traversing.LocationPhysicallyLocatable" />
   <adapter factory=".traversing.RootPhysicallyLocatable" />
 
Index: src/zope/location/pickling.py
===================================================================
--- src/zope/location/pickling.py	(revisione 106858)
+++ src/zope/location/pickling.py	(copia locale)
@@ -18,13 +18,17 @@
 __docformat__ = 'restructuredtext'
 
 from zope.component import adapts
-from zope.copy.interfaces import ICopyHook, ResumeCopy
 from zope.interface import implements
-
 from zope.location.interfaces import ILocation
 from zope.location.location import inside
 
+try:
+    from zope.copy.interfaces import ICopyHook, ResumeCopy
+except ImportError:
+    raise NotImplementedError("zope.location.pickling is not supported "
+        "because zope.copy is not available")
 
+
 class LocationCopyHook(object):
     """Copy hook to preserve copying referenced objects that are not
     located inside object that's being copied.
Index: setup.py
===================================================================
--- setup.py	(revisione 106858)
+++ setup.py	(copia locale)
@@ -56,13 +56,14 @@
       packages=find_packages('src'),
       package_dir = {'': 'src'},
       namespace_packages=['zope',],
+      tests_require=['zope.copy'],
       install_requires=['setuptools',
                         'zope.interface',
                         'zope.schema>=3.5.1dev',
                         'zope.component>=3.8.0',
                         'zope.proxy>3.3',
-                        'zope.copy',
                         ],
+      extras_require=dict(test=['zope.copy']),
       include_package_data = True,
       zip_safe = False,
       )
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.