Skip to content

Commit

Permalink
Rely on zope.vocabularyregistry instead of duplicating ZopeVocabulary…
Browse files Browse the repository at this point in the history
…Registry

Fixes #2.

Also add tests for ``configure.zcml``.
  • Loading branch information
jamadden committed May 10, 2017
1 parent c67d33b commit 674e521
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 77 deletions.
22 changes: 12 additions & 10 deletions CHANGES.txt → CHANGES.rst
@@ -1,21 +1,23 @@
=======
CHANGES
=======
=========
CHANGES
=========

4.0.2 (unreleased)
------------------
==================

- Nothing changed yet.
- Replaced the local implementation of ``ZopeVocabularyRegistry`` with
one imported from ``zope.vocabularyregistry``. Backwards
compatibility imports remain.


4.0.1 (2017-05-10)
------------------
==================

- Packaging: Add the Python version and implementation classifiers.


4.0.0 (2017-04-17)
------------------
==================

- Support for Python 3.5, 3.6 and PyPy has been added.

Expand All @@ -25,19 +27,19 @@ CHANGES


3.6.0 (2017-04-17)
------------------
==================

- Package modernization including manifest.


3.5.0 (2008-12-16)
------------------
==================

- Remove deprecated ``vocabulary`` directive.
- Add test for component-based vocabulary registry.


3.4.0 (2007-10-27)
------------------
==================

- Initial release independent of the main Zope tree.
3 changes: 2 additions & 1 deletion MANIFEST.in
@@ -1,10 +1,11 @@
include *.py
include *.txt
include *.rst
include buildout.cfg
include tox.ini
include .travis.yml
include .coveragerc

recursive-include src *.cfg
recursive-include src *.txt
recursive-include src *.rst
recursive-include src *.zcml
File renamed without changes.
37 changes: 21 additions & 16 deletions setup.py
Expand Up @@ -24,25 +24,30 @@
def read(*rnames):
return open(os.path.join(os.path.dirname(__file__), *rnames)).read()

ZCML_REQUIRE = [
'zope.configuration',
'zope.security',
]

TESTS_REQUIRE = [
'zope.testing',
'zope.testrunner',
]
] + ZCML_REQUIRE

setup(name='zope.app.schema',
version='4.0.2.dev0',
version='4.1.0.dev0',
author='Zope Corporation and Contributors',
author_email='zope-dev@zope.org',
description='Component Architecture based Vocabulary Registry',
long_description=(
read('README.txt')
read('README.rst')
+ '\n\n' +
read('src', 'zope', 'app', 'schema', 'README.txt')
read('src', 'zope', 'app', 'schema', 'README.rst')
+ '\n\n' +
read('CHANGES.txt')
read('CHANGES.rst')
),
keywords = "zope3 vocabulary registry local component",
classifiers = [
keywords="zope3 vocabulary registry local component",
classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: Web Environment',
'Intended Audience :: Developers',
Expand All @@ -63,18 +68,18 @@ def read(*rnames):
url='http://pypi.python.org/pypi/zope.app.schema',
license='ZPL 2.1',
packages=find_packages('src'),
package_dir = {'': 'src'},
package_dir={'': 'src'},
namespace_packages=['zope', 'zope.app'],
extras_require = dict(
test=TESTS_REQUIRE),
extras_require={
'test': TESTS_REQUIRE,
'zcml': ZCML_REQUIRE,
},
install_requires=[
'setuptools',
'zope.component',
'zope.interface',
'zope.schema',
'zope.vocabularyregistry >= 1.0.0',
],
include_package_data = True,
include_package_data=True,
tests_require=TESTS_REQUIRE,
test_suite='zope.app.schema.tests.test_suite',
zip_safe = False,
)
zip_safe=False,
)
28 changes: 24 additions & 4 deletions src/zope/app/schema/README.txt → src/zope/app/schema/README.rst
@@ -1,19 +1,25 @@
Component-based Vocabulary Registry
===================================
=====================================
Component-based Vocabulary Registry
=====================================

This package provides a vocabulary registry for zope.schema,
based on the component architecture.

**NOTE:** This functionality has been replaced with
``zope.vocabularyregistry``. These imports continue to work
for backwards compatibility.

It replaces the zope.schema's simple vocabulary registry
when ``zope.app.schema`` package is imported, so it's done
automatically. All we need is provide vocabulary factory
utilities:

>>> import zope.app.schema
>>> from zope.component import provideUtility
>>> from zope.schema.interfaces import IVocabularyFactory
>>> from zope.schema.vocabulary import SimpleTerm
>>> from zope.schema.vocabulary import SimpleVocabulary

>>> def SomeVocabulary(context=None):
... terms = [SimpleTerm(1), SimpleTerm(2)]
... return SimpleVocabulary(terms)
Expand All @@ -28,4 +34,18 @@ way:
>>> vr = getVocabularyRegistry()
>>> voc = vr.get(None, 'SomeVocabulary')
>>> [term.value for term in voc]
[1, 2]
[1, 2]

Configuration
=============

This package provides configuration that sets security permissions and
factories for the objects provided in ``zope.schema``. The
``zope.security`` package must be installed to use it.

>>> from zope.configuration import xmlconfig
>>> _ = xmlconfig.string(r"""
... <configure xmlns="http://namespaces.zope.org/zope" i18n_domain="zope">
... <include package="zope.app.schema" />
... </configure>
... """)
1 change: 0 additions & 1 deletion src/zope/app/schema/__init__.py
Expand Up @@ -13,7 +13,6 @@
##############################################################################
"""Schemas
$Id$
"""
# we want to hook-up our own vocabulary registry; importing the module
# is enough for that
Expand Down
11 changes: 7 additions & 4 deletions src/zope/app/schema/configure.zcml
@@ -1,5 +1,8 @@
<configure xmlns="http://namespaces.zope.org/zope" i18n_domain="zope">

<include package="zope.security" file="meta.zcml" />
<include package="zope.security" />

<class class="zope.schema.Field">

<factory
Expand Down Expand Up @@ -208,7 +211,7 @@
<factory
id="zope.schema.Choice"
title="Choice Field"
description="Choice Field"
description="Choice Field"
/>

<require like_class="zope.schema.Field" />
Expand Down Expand Up @@ -267,7 +270,7 @@
<factory
id="zope.schema.Date"
title="Date Field"
description="Date Field"
description="Date Field"
/>

<require like_class="zope.schema.Orderable" />
Expand All @@ -280,7 +283,7 @@
<factory
id="zope.schema.Timedelta"
title="Timedelta Field"
description="Timedelta Field"
description="Timedelta Field"
/>

<require like_class="zope.schema.Orderable" />
Expand Down Expand Up @@ -329,7 +332,7 @@
<factory
id="zope.schema.DottedName"
title="Dotted Name"
description="Dotted Name"
description="Dotted Name"
/>

<require like_class="zope.schema.MinMaxLen" />
Expand Down
14 changes: 6 additions & 8 deletions src/zope/app/schema/tests.py
@@ -1,19 +1,17 @@
import doctest
import unittest

from zope.component import testing
from zope.app.schema.vocabulary import _clear
from zope.testing import cleanup

def setUp(test):
testing.setUp()
_clear()
def setUp(_test):
cleanup.setUp()

def tearDown(test):
testing.tearDown()
def tearDown(_test):
cleanup.tearDown()

def test_suite():
return unittest.TestSuite((
doctest.DocFileSuite('README.txt',
doctest.DocFileSuite('README.rst',
setUp=setUp, tearDown=tearDown,
optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS,
),
Expand Down
39 changes: 6 additions & 33 deletions src/zope/app/schema/vocabulary.py
Expand Up @@ -11,39 +11,12 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Implementation of ZCML action to register vocabulary factories.
"""
import zope.component
from zope.interface import implementer
Backward-compatibility imports. The primary home of these objects is now
zope.vocabularyregistry.registry.
"""

from zope.schema.interfaces import IVocabularyRegistry
from zope.schema import vocabulary
from zope.schema.interfaces import IVocabularyFactory

@implementer(IVocabularyRegistry)
class ZopeVocabularyRegistry(object):
"""IVocabularyRegistry that supports global and local utilities."""
__slots__ = ()

def get(self, context, name):
"""See zope.schema.interfaces.IVocabularyRegistry"""
factory = zope.component.getUtility(IVocabularyFactory, name)
return factory(context)

def _clear():
"""Re-initialize the vocabulary registry."""
# This should normally only be needed by the testing framework,
# but is also used for module initialization.
global vocabularyRegistry
vocabulary._clear()
vocabularyRegistry = vocabulary.getVocabularyRegistry()
vocabulary._clear()
vocabulary.setVocabularyRegistry(ZopeVocabularyRegistry())

_clear()
try:
from zope.testing import cleanup
except ImportError: # pragma: no cover
pass
else:
cleanup.addCleanUp(_clear)
from zope.vocabularyregistry.registry import ZopeVocabularyRegistry
from zope.vocabularyregistry.registry import vocabularyRegistry

0 comments on commit 674e521

Please sign in to comment.