[Checkins] SVN: z3c.csvvocabulary/trunk/ - Add Python 3.3 support.

Stephen Richter cvs-admin at zope.org
Wed Feb 20 03:40:26 UTC 2013


Log message for revision 129508:
  - Add Python 3.3 support.
  - Drop Python 2.4 and 2.5 support.
  - Added tox and manifest configs.
  
  

Changed:
  _U  z3c.csvvocabulary/trunk/
  U   z3c.csvvocabulary/trunk/CHANGES.txt
  A   z3c.csvvocabulary/trunk/MANIFEST.in
  U   z3c.csvvocabulary/trunk/bootstrap.py
  U   z3c.csvvocabulary/trunk/setup.py
  U   z3c.csvvocabulary/trunk/src/z3c/csvvocabulary/README.txt
  U   z3c.csvvocabulary/trunk/src/z3c/csvvocabulary/i18nextract.py
  U   z3c.csvvocabulary/trunk/src/z3c/csvvocabulary/tests.py
  U   z3c.csvvocabulary/trunk/src/z3c/csvvocabulary/vocabulary.py
  A   z3c.csvvocabulary/trunk/tox.ini

-=-

Property changes on: z3c.csvvocabulary/trunk
___________________________________________________________________
Added: svn:ignore
   + .installed.cfg
.coverage
.tox
bin
build
dist
develop-eggs
eggs
parts
*.xml


Modified: z3c.csvvocabulary/trunk/CHANGES.txt
===================================================================
--- z3c.csvvocabulary/trunk/CHANGES.txt	2013-02-20 02:35:01 UTC (rev 129507)
+++ z3c.csvvocabulary/trunk/CHANGES.txt	2013-02-20 03:40:24 UTC (rev 129508)
@@ -2,13 +2,21 @@
 Change History
 ==============
 
+2.0.0 (unreleased)
+------------------
+
+- Add Python 3.3 support.
+
+- Drop Python 2.4 and 2.5 support.
+
+
 1.1.0 (2010/01/11)
 ------------------
 
-* enocding of csv file can now be specified ``CSVVocabulary(csvfile, encoding='utf-8')``
-  [fRiSi]
+* enocding of csv file can now be specified ``CSVVocabulary(csvfile,
+  encoding='utf-8')`` [fRiSi]
 
 1.0.0
 -----
 
-* initial release
\ No newline at end of file
+* initial release

Added: z3c.csvvocabulary/trunk/MANIFEST.in
===================================================================
--- z3c.csvvocabulary/trunk/MANIFEST.in	                        (rev 0)
+++ z3c.csvvocabulary/trunk/MANIFEST.in	2013-02-20 03:40:24 UTC (rev 129508)
@@ -0,0 +1,9 @@
+include *.rst
+include *.txt
+include *.py
+include buildout.cfg
+include tox.ini
+
+recursive-include src *
+
+global-exclude *.pyc

Modified: z3c.csvvocabulary/trunk/bootstrap.py
===================================================================
--- z3c.csvvocabulary/trunk/bootstrap.py	2013-02-20 02:35:01 UTC (rev 129507)
+++ z3c.csvvocabulary/trunk/bootstrap.py	2013-02-20 03:40:24 UTC (rev 129508)
@@ -1,6 +1,6 @@
 ##############################################################################
 #
-# Copyright (c) 2007 Zope Foundation and Contributors.
+# Copyright (c) 2006 Zope Foundation and Contributors.
 # All Rights Reserved.
 #
 # This software is subject to the provisions of the Zope Public License,
@@ -16,37 +16,150 @@
 Simply run this script in a directory containing a buildout.cfg.
 The script accepts buildout command-line options, so you can
 use the -c option to specify an alternate configuration file.
-
-$Id$
 """
 
-import os, shutil, sys, tempfile, urllib2
+import os, shutil, sys, tempfile
+from optparse import OptionParser
 
 tmpeggs = tempfile.mkdtemp()
 
-ez = {}
-exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py'
-                     ).read() in ez
-ez['use_setuptools'](to_dir=tmpeggs, download_delay=0)
+usage = '''\
+[DESIRED PYTHON FOR BUILDOUT] bootstrap.py [options]
 
-import pkg_resources
+Bootstraps a buildout-based project.
 
-cmd = 'from setuptools.command.easy_install import main; main()'
-if sys.platform == 'win32':
-    cmd = '"%s"' % cmd # work around spawn lamosity on windows
+Simply run this script in a directory containing a buildout.cfg, using the
+Python that you want bin/buildout to use.
 
-ws = pkg_resources.working_set
-assert os.spawnle(
-    os.P_WAIT, sys.executable, sys.executable,
-    '-c', cmd, '-mqNxd', tmpeggs, 'zc.buildout',
-    dict(os.environ,
-         PYTHONPATH=
-         ws.find(pkg_resources.Requirement.parse('setuptools')).location
-         ),
-    ) == 0
+Note that by using --setup-source and --download-base to point to
+local resources, you can keep this script from going over the network.
+'''
 
+parser = OptionParser(usage=usage)
+parser.add_option("-v", "--version", help="use a specific zc.buildout version")
+
+parser.add_option("-t", "--accept-buildout-test-releases",
+                  dest='accept_buildout_test_releases',
+                  action="store_true", default=False,
+                  help=("Normally, if you do not specify a --version, the "
+                        "bootstrap script and buildout gets the newest "
+                        "*final* versions of zc.buildout and its recipes and "
+                        "extensions for you.  If you use this flag, "
+                        "bootstrap and buildout will get the newest releases "
+                        "even if they are alphas or betas."))
+parser.add_option("-c", "--config-file",
+                   help=("Specify the path to the buildout configuration "
+                         "file to be used."))
+parser.add_option("-f", "--find-links",
+                   help=("Specify a URL to search for buildout releases"))
+
+
+options, args = parser.parse_args()
+
+######################################################################
+# load/install distribute
+
+to_reload = False
+try:
+    import pkg_resources, setuptools
+    if not hasattr(pkg_resources, '_distribute'):
+        to_reload = True
+        raise ImportError
+except ImportError:
+    ez = {}
+
+    try:
+        from urllib.request import urlopen
+    except ImportError:
+        from urllib2 import urlopen
+
+    exec(urlopen('http://python-distribute.org/distribute_setup.py').read(), ez)
+    setup_args = dict(to_dir=tmpeggs, download_delay=0, no_fake=True)
+    ez['use_setuptools'](**setup_args)
+
+    if to_reload:
+        reload(pkg_resources)
+    import pkg_resources
+    # This does not (always?) update the default working set.  We will
+    # do it.
+    for path in sys.path:
+        if path not in pkg_resources.working_set.entries:
+            pkg_resources.working_set.add_entry(path)
+
+######################################################################
+# Install buildout
+
+ws  = pkg_resources.working_set
+
+cmd = [sys.executable, '-c',
+       'from setuptools.command.easy_install import main; main()',
+       '-mZqNxd', tmpeggs]
+
+find_links = os.environ.get(
+    'bootstrap-testing-find-links',
+    options.find_links or
+    ('http://downloads.buildout.org/'
+     if options.accept_buildout_test_releases else None)
+    )
+if find_links:
+    cmd.extend(['-f', find_links])
+
+distribute_path = ws.find(
+    pkg_resources.Requirement.parse('distribute')).location
+
+requirement = 'zc.buildout'
+version = options.version
+if version is None and not options.accept_buildout_test_releases:
+    # Figure out the most recent final version of zc.buildout.
+    import setuptools.package_index
+    _final_parts = '*final-', '*final'
+    def _final_version(parsed_version):
+        for part in parsed_version:
+            if (part[:1] == '*') and (part not in _final_parts):
+                return False
+        return True
+    index = setuptools.package_index.PackageIndex(
+        search_path=[distribute_path])
+    if find_links:
+        index.add_find_links((find_links,))
+    req = pkg_resources.Requirement.parse(requirement)
+    if index.obtain(req) is not None:
+        best = []
+        bestv = None
+        for dist in index[req.project_name]:
+            distv = dist.parsed_version
+            if _final_version(distv):
+                if bestv is None or distv > bestv:
+                    best = [dist]
+                    bestv = distv
+                elif distv == bestv:
+                    best.append(dist)
+        if best:
+            best.sort()
+            version = best[-1].version
+if version:
+    requirement = '=='.join((requirement, version))
+cmd.append(requirement)
+
+import subprocess
+if subprocess.call(cmd, env=dict(os.environ, PYTHONPATH=distribute_path)) != 0:
+    raise Exception(
+        "Failed to execute command:\n%s",
+        repr(cmd)[1:-1])
+
+######################################################################
+# Import and run buildout
+
 ws.add_entry(tmpeggs)
-ws.require('zc.buildout')
+ws.require(requirement)
 import zc.buildout.buildout
-zc.buildout.buildout.main(sys.argv[1:] + ['bootstrap'])
+
+if not [a for a in args if '=' not in a]:
+    args.append('bootstrap')
+
+# if -c was provided, we push it back into args for buildout' main function
+if options.config_file is not None:
+    args[0:0] = ['-c', options.config_file]
+
+zc.buildout.buildout.main(args)
 shutil.rmtree(tmpeggs)

Modified: z3c.csvvocabulary/trunk/setup.py
===================================================================
--- z3c.csvvocabulary/trunk/setup.py	2013-02-20 02:35:01 UTC (rev 129507)
+++ z3c.csvvocabulary/trunk/setup.py	2013-02-20 03:40:24 UTC (rev 129508)
@@ -12,8 +12,6 @@
 #
 ##############################################################################
 """Setup
-
-$Id$
 """
 import os
 from setuptools import setup, find_packages
@@ -23,7 +21,7 @@
 
 setup (
     name='z3c.csvvocabulary',
-    version='1.1.0',
+    version='2.0.0dev',
     author = "Zope Community",
     author_email = "zope-dev at zope.org",
     description = "A package to create vocabularies based on CSV files.",
@@ -41,15 +39,21 @@
     keywords = "zope3 vocabulary csv",
     classifiers = [
         'Development Status :: 5 - Production/Stable',
-        'Environment :: Web Environment',
         'Intended Audience :: Developers',
         'License :: OSI Approved :: Zope Public License',
-        'Programming Language :: Python',
         'Natural Language :: English',
         'Operating System :: OS Independent',
+        'Programming Language :: Python',
+        'Programming Language :: Python :: 2',
+        'Programming Language :: Python :: 2.6',
+        'Programming Language :: Python :: 2.7',
+        'Programming Language :: Python :: 3',
+        'Programming Language :: Python :: 3.3',
+        'Programming Language :: Python :: Implementation :: CPython',
+        'Programming Language :: Python :: Implementation :: PyPy',
         'Topic :: Internet :: WWW/HTTP',
         'Framework :: Zope3'],
-    url = 'http://svn.zope.org/z3c.csvvocabulary',
+    url = 'https://pypi.python.org/pypi/z3c.csvvocabulary',
     packages = find_packages('src'),
     include_package_data = True,
     package_dir = {'':'src'},
@@ -62,6 +66,7 @@
         'zope.i18nmessageid',
         'zope.schema',
         ],
-    dependency_links = ['http://download.zope.org/distribution'],
+    tests_require = ['zope.testing'],
+    test_suite = 'z3c.csvvocabulary.tests.test_suite',
     zip_safe = False,
     )

Modified: z3c.csvvocabulary/trunk/src/z3c/csvvocabulary/README.txt
===================================================================
--- z3c.csvvocabulary/trunk/src/z3c/csvvocabulary/README.txt	2013-02-20 02:35:01 UTC (rev 129507)
+++ z3c.csvvocabulary/trunk/src/z3c/csvvocabulary/README.txt	2013-02-20 03:40:24 UTC (rev 129508)
@@ -61,10 +61,10 @@
 message. You can specify the message factory when initializing the vocabulary:
 
   >>> from zope.i18nmessageid import MessageFactory
-  >>> exampleDomain = MessageFactory('example')
+  >>> exampleDomain = MessageFactory(u'example')
 
   >>> samples = z3c.csvvocabulary.CSVVocabulary(csvfile, exampleDomain)
-  >>> term1 = samples.getTerm('value1')
+  >>> term1 = samples.getTerm(u'value1')
   >>> term1.title.domain
   'example'
 

Modified: z3c.csvvocabulary/trunk/src/z3c/csvvocabulary/i18nextract.py
===================================================================
--- z3c.csvvocabulary/trunk/src/z3c/csvvocabulary/i18nextract.py	2013-02-20 02:35:01 UTC (rev 129507)
+++ z3c.csvvocabulary/trunk/src/z3c/csvvocabulary/i18nextract.py	2013-02-20 03:40:24 UTC (rev 129508)
@@ -15,16 +15,12 @@
 
 Important: The functionality provided in this package must be manually
 integrated into your string extraction script/tool.
-
-$Id$
 """
-__docformat__ = "reStructuredText"
-import os.path
+import os
 
 from z3c.csvvocabulary import vocabulary
 
-def _extractCsvStrings(arg, dirname, fnames):
-    catalog, basepath, exclude_dirs = arg
+def _extractCsvStrings(dirname, fnames, catalog, basepath, exclude_dirs):
     # Make sure we have a data directory
     if os.path.split(dirname)[-1] != 'data':
         return
@@ -52,5 +48,6 @@
     """
     catalog = {}
     exclude_dirs = [os.path.join(path, dir) for dir in exclude_dirs]
-    os.path.walk(path, _extractCsvStrings, (catalog, base_dir, exclude_dirs))
+    for dirname, subnames, fnames in os.walk(path):
+        _extractCsvStrings(dirname, fnames, catalog, base_dir, exclude_dirs)
     return catalog

Modified: z3c.csvvocabulary/trunk/src/z3c/csvvocabulary/tests.py
===================================================================
--- z3c.csvvocabulary/trunk/src/z3c/csvvocabulary/tests.py	2013-02-20 02:35:01 UTC (rev 129507)
+++ z3c.csvvocabulary/trunk/src/z3c/csvvocabulary/tests.py	2013-02-20 03:40:24 UTC (rev 129508)
@@ -17,14 +17,26 @@
 """
 __docformat__ = "reStructuredText"
 import doctest
+import re
 import unittest
+from zope.testing import renormalizing
 from zope.testing.doctestunit import DocFileSuite, pprint
 
+checker = renormalizing.RENormalizing([
+    # Python 2 unicode strings add a "u".
+    (re.compile("u('.*?')"),
+     r"\1"),
+    # Python 3 renamed type to class.
+    (re.compile("<type "),
+     r"<class "),
+    ])
+
+
 def test_suite():
     return unittest.TestSuite((
         DocFileSuite('README.txt',
                      optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS,
-                     globs={'pprint': pprint}
+                     globs={'pprint': pprint}, checker=checker
                      ),
         ))
 

Modified: z3c.csvvocabulary/trunk/src/z3c/csvvocabulary/vocabulary.py
===================================================================
--- z3c.csvvocabulary/trunk/src/z3c/csvvocabulary/vocabulary.py	2013-02-20 02:35:01 UTC (rev 129507)
+++ z3c.csvvocabulary/trunk/src/z3c/csvvocabulary/vocabulary.py	2013-02-20 03:40:24 UTC (rev 129508)
@@ -18,10 +18,13 @@
 __docformat__ = "reStructuredText"
 import csv
 import os.path
+import sys
 
 from zope.schema import vocabulary
 from zope.i18nmessageid import MessageFactory
 
+PY3 = sys.version_info[0] == 3
+
 _ = MessageFactory('zope')
 
 
@@ -29,13 +32,21 @@
     # Create a prefix
     prefix = os.path.split(filename)[-1][:-4]
     # Open a file and read the data
-    f = file(filename)
+    if PY3:
+        f = open(filename, 'r', encoding=encoding)
+    else:
+        f = open(filename, 'r')
+    # Py3: The big problem here is that the Py2 CSV Reader is not unicode
+    # aware, so we must handle everything in bytes, but in Py3 it is exactely
+    # the opposite and we are forced decode to unicode early.
     reader = csv.reader(f, delimiter=";")
     # Create the terms and the vocabulary
     terms = []
     for id, title in reader:
-        title = unicode(title, encoding)
+        if not PY3:
+            title = title.decode(encoding)
         term = vocabulary.SimpleTerm(
             id, title=messageFactory(prefix+'-'+id, default=title))
         terms.append(term)
+    f.close()
     return vocabulary.SimpleVocabulary(terms)

Added: z3c.csvvocabulary/trunk/tox.ini
===================================================================
--- z3c.csvvocabulary/trunk/tox.ini	                        (rev 0)
+++ z3c.csvvocabulary/trunk/tox.ini	2013-02-20 03:40:24 UTC (rev 129508)
@@ -0,0 +1,31 @@
+[tox]
+envlist =
+    py26,py27,py33,pypy
+
+[testenv]
+commands =
+    python setup.py test -q
+# without explicit deps, setup.py test will download a bunch of eggs into $PWD
+# (and it seems I can't use zope.dottedname[testing] here, so forget DRY)
+deps =
+    zope.testing
+    zope.i18nmessageid
+    zope.schema
+
+[testenv:coverage]
+basepython =
+    python2.7
+commands =
+#   The installed version messes up nose's test discovery / coverage reporting
+#   So, we uninstall that from the environment, and then install the editable
+#   version, before running nosetests.
+    pip uninstall -y z3c.csvvocabulary
+    pip install -e .
+    nosetests --with-xunit --with-xcoverage
+deps =
+    nose
+    coverage
+    nosexcover
+    zope.testing
+    zope.i18nmessageid
+    zope.schema



More information about the checkins mailing list