Skip to content

Commit

Permalink
Make 'persistent'/'BTrees' soft dependencies.
Browse files Browse the repository at this point in the history
- 'persistent' is used only for doctests.

- If 'BTrees' is not importable ('OOBTree' used for attribute storage),
  fall back to using 'dict'.

- Both are installable via the 'zope.annotation[btree]' extra.

- Closes LP #878265.
  • Loading branch information
tseaver committed Jan 9, 2015
1 parent f3fd145 commit 5542da0
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 10 deletions.
11 changes: 9 additions & 2 deletions CHANGES.rst
@@ -1,10 +1,17 @@
Changes
=======

4.3.1 (unreleased)
4.4.0 (unreleased)
------------------

- TBD
- LP #878265:

- Make ``persistent`` (used only for doctests) a soft dependency,
installable via the ``zope.annotation[btree]`` extra.

- Make ``BTrees`` (used for attribute storage) a soft dependency,
installable via the ``zope.annotation[btree]`` extra. Fall back to
using ``dict`` for attribute storage if ``BTrees`` is not importable.

4.3.0 (2014-12-26)
------------------
Expand Down
8 changes: 5 additions & 3 deletions setup.py
Expand Up @@ -42,7 +42,7 @@ def alltests():

setup(
name='zope.annotation',
version='4.3.1.dev0',
version='4.4.0.dev0',
url='http://pypi.python.org/pypi/zope.annotation',
license='ZPL 2.1',
description='Object annotation mechanism',
Expand Down Expand Up @@ -76,15 +76,17 @@ def alltests():
package_dir={'': 'src'},
namespace_packages=['zope',],
install_requires=[
'persistent',
'BTrees',
'setuptools',
'zope.interface',
'zope.component',
'zope.location',
'zope.proxy',
],
extras_require=dict(
btrees=[
'BTrees',
'persistent',
],
test=[
'zope.testing'
],
Expand Down
6 changes: 5 additions & 1 deletion src/zope/annotation/README.txt
Expand Up @@ -15,7 +15,11 @@ First, let's make a persistent object we can create annotations for:
>>> class IFoo(interface.Interface):
... pass
>>> from zope.annotation.interfaces import IAttributeAnnotatable
>>> from persistent import Persistent
>>> try:
... from persistent import Persistent
... except ImportError:
... class Persistent(object):
... pass
>>> @interface.implementer(IFoo, IAttributeAnnotatable)
... class Foo(Persistent):
... pass
Expand Down
13 changes: 11 additions & 2 deletions src/zope/annotation/attribute.py
Expand Up @@ -12,7 +12,16 @@
#
##############################################################################
"""Attribute Annotations implementation"""
from BTrees.OOBTree import OOBTree
import logging

try:
from BTrees.OOBTree import OOBTree
except ImportError:
logging.getLogger(__name__).warn(
'BTrees not available: falling back to dict for attribute storage')
_STORAGE = dict
else:
_STORAGE = OOBTree

from zope import component, interface
from zope.annotation import interfaces
Expand Down Expand Up @@ -80,7 +89,7 @@ def __setitem__(self, key, value):
try:
annotations = self.obj.__annotations__
except AttributeError:
annotations = self.obj.__annotations__ = OOBTree()
annotations = self.obj.__annotations__ = _STORAGE()

annotations[key] = value

Expand Down
13 changes: 11 additions & 2 deletions tox.ini
Expand Up @@ -2,8 +2,8 @@
envlist =
# PyPy3 support is pending release of a fix for:
# https://bitbucket.org/pypy/pypy/issue/1946
# py26,py27,py33,py34,pypy,pypy3,coverage
py26,py27,py33,py34,pypy,coverage
# py26,py27,py33,py34,pypy,pypy3,coverage,nobtree
py26,py27,py33,py34,pypy,coverage,nobtree

[base]
deps =
Expand All @@ -24,6 +24,15 @@ deps =
BTrees
persistent

[testenv:nobtree]
basepython =
python2.7
commands =
python setup.py test -q
# without explicit deps, setup.py test will download a bunch of eggs into $PWD
deps =
{[base]deps}

[testenv:coverage]
basepython =
python2.7
Expand Down

0 comments on commit 5542da0

Please sign in to comment.