[Checkins] SVN: zope.security/trunk/ Made ``pytz`` a soft dependency.

Tres Seaver tseaver at palladion.com
Wed May 13 18:49:51 EDT 2009


Log message for revision 99938:
  Made ``pytz`` a soft dependency.
  
  The checker for ``pytz.UTC`` is created / tested only if the package
  is already present.
  
  Run ``bin/test_pytz`` to run the tests with ``pytz`` on the path.
  

Changed:
  U   zope.security/trunk/CHANGES.txt
  U   zope.security/trunk/buildout.cfg
  U   zope.security/trunk/setup.py
  U   zope.security/trunk/src/zope/security/checker.py
  U   zope.security/trunk/src/zope/security/tests/test_standard_checkers.py

-=-
Modified: zope.security/trunk/CHANGES.txt
===================================================================
--- zope.security/trunk/CHANGES.txt	2009-05-13 22:13:35 UTC (rev 99937)
+++ zope.security/trunk/CHANGES.txt	2009-05-13 22:49:50 UTC (rev 99938)
@@ -5,7 +5,9 @@
 3.6.4 (unreleased)
 ------------------
 
-- None so far.
+- Made ``pytz`` a soft dependency:  the checker for ``pytz.UTC`` is
+  created / tested only if the package is already present.  Run
+  ``bin/test_pytz`` to run the tests with ``pytz`` on the path.
 
 3.6.3 (2009-03-23)
 ------------------

Modified: zope.security/trunk/buildout.cfg
===================================================================
--- zope.security/trunk/buildout.cfg	2009-05-13 22:13:35 UTC (rev 99937)
+++ zope.security/trunk/buildout.cfg	2009-05-13 22:49:50 UTC (rev 99938)
@@ -1,11 +1,15 @@
 [buildout]
 develop = .
-parts = test python coverage-test coverage-report
+parts = test test_pytz python coverage-test coverage-report
 
 [test]
 recipe = zc.recipe.testrunner
 eggs = zope.security [test]
 
+[test_pytz]
+recipe = zc.recipe.testrunner
+eggs = zope.security [test,pytz]
+
 [python]
 recipe = zc.recipe.egg
 eggs = zope.security [untrustedpython]

Modified: zope.security/trunk/setup.py
===================================================================
--- zope.security/trunk/setup.py	2009-05-13 22:13:35 UTC (rev 99937)
+++ zope.security/trunk/setup.py	2009-05-13 22:49:50 UTC (rev 99938)
@@ -61,7 +61,6 @@
                               ]),
                    ],
       install_requires=['setuptools',
-                        'pytz',
                         'zope.component',
                         'zope.configuration',
                         'zope.exceptions',
@@ -74,6 +73,7 @@
       extras_require = dict(
           untrustedpython=["RestrictedPython"],
           test=["RestrictedPython"],
+          pytz=["pytz"],
           ),
       include_package_data = True,
       zip_safe = False,

Modified: zope.security/trunk/src/zope/security/checker.py
===================================================================
--- zope.security/trunk/src/zope/security/checker.py	2009-05-13 22:13:35 UTC (rev 99937)
+++ zope.security/trunk/src/zope/security/checker.py	2009-05-13 22:49:50 UTC (rev 99938)
@@ -30,7 +30,6 @@
 import types
 import datetime
 import decimal
-import pytz
 import weakref
 
 from zope.exceptions import DuplicationError
@@ -605,7 +604,7 @@
         super(BasicTypes.__class__, self).update(d)
         _checkers.update(d)
 
-BasicTypes = BasicTypes({
+_basic_types = {
     object: NoProxy,
     int: NoProxy,
     float: NoProxy,
@@ -621,9 +620,17 @@
     datetime.date: NoProxy,
     datetime.time: NoProxy,
     datetime.tzinfo: NoProxy,
-    type(pytz.UTC): NoProxy,
-})
+}
+try:
+    import pytz
+except ImportError:
+    pass
+else:
+    _basic_types[type(pytz.UTC)] = NoProxy
 
+BasicTypes = BasicTypes(_basic_types)
+del _basic_types
+
 # Available for tests. Located here so it can be kept in sync with BasicTypes.
 BasicTypes_examples = {
     object: object(),

Modified: zope.security/trunk/src/zope/security/tests/test_standard_checkers.py
===================================================================
--- zope.security/trunk/src/zope/security/tests/test_standard_checkers.py	2009-05-13 22:13:35 UTC (rev 99937)
+++ zope.security/trunk/src/zope/security/tests/test_standard_checkers.py	2009-05-13 22:49:50 UTC (rev 99938)
@@ -421,8 +421,11 @@
     >>> int(type(ProxyFactory(  tzinfo() )) is tzinfo)
     1
 
-    >>> from pytz import UTC
-    >>> int(type(ProxyFactory(  UTC )) is type(UTC))
+    >>> try:
+    ...     from pytz import UTC
+    ... except ImportError:  # pytz checker only if pytz is present.
+    ...     UTC = None
+    >>> int(UTC is None or type(ProxyFactory(  UTC )) is type(UTC))
     1
     """
 



More information about the Checkins mailing list