Skip to content

Commit

Permalink
Ported to Python 3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
strichter committed Mar 1, 2013
1 parent 07bde99 commit 189cde1
Show file tree
Hide file tree
Showing 12 changed files with 311 additions and 127 deletions.
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
*.pyc
__pycache__
src/*.egg-info
benchmark/*.egg-info

.installed.cfg
.tox
bin
develop-eggs
docs
parts
9 changes: 8 additions & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@
CHANGES
=======

1.4 (unreleased)
2.0.0 (unreleased)
================

- Added support for Python 3.3.

- Replaced deprecated ``zope.interface.implements`` usage with equivalent
``zope.interface.implementer`` decorator.

- Dropped support for Python 2.4 and 2.5.

- Fixed an issue where slicing a composite queue would fail due to a
programming error.
[malthe]
Expand Down
9 changes: 9 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
include *.rst
include *.txt
include *.py
include buildout.cfg
include tox.ini

recursive-include src *

global-exclude *.pyc
Binary file added ZODB-4.0.0dev.tar.gz
Binary file not shown.
157 changes: 135 additions & 22 deletions bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: bootstrap.py 69908 2006-08-31 21:53:00Z jim $
"""

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]
Bootstraps a buildout-based project.
Simply run this script in a directory containing a buildout.cfg, using the
Python that you want bin/buildout to use.
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

import pkg_resources
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)

cmd = 'from setuptools.command.easy_install import main; main()'
if sys.platform == 'win32':
cmd = '"%s"' % cmd # work around spawn lamosity on windows
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)

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
######################################################################
# 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)
9 changes: 3 additions & 6 deletions buildout.cfg
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
[buildout]
develop = .
find-links =
${buildout:directory}/ZODB-4.0.0dev.tar.gz
parts = test py
versions = versions

[versions]
# For python2.6 use these (currently the latest versions):
ZODB3 = 3.10.5
transaction = 1.2.0
# For python2.4:
#ZODB3 = 3.9.7
#transaction = 1.1.1
ZODB = 4.0.0dev

[test]
recipe = zc.recipe.testrunner
Expand Down
68 changes: 44 additions & 24 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,48 +1,68 @@
##############################################################################
#
# Copyright (c) 2011 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Setup
"""
import os

from setuptools import setup


def read(*rnames):
return open(os.path.join(os.path.dirname(__file__), *rnames)).read()


tests_require = ["zope.testing"]


setup(
name="zc.queue",
version="1.4dev",
license="ZPL 2.1",
author="Zope Project",
author_email="zope-dev@zope.org",
# Get more strings from
# http://pypi.python.org/pypi?%3Aaction=list_classifiers
description=read('README.txt'),
long_description='\n\n'.join([
read('src', 'zc', 'queue', 'queue.txt'),
read('CHANGES.txt'),
]),
keywords='zope zope3',
classifiers=[
"Programming Language :: Python",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.5",
"Programming Language :: Python :: 2.6",
"Programming Language :: Python :: 2.7",
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'License :: OSI Approved :: Zope Public License',
'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',
'Natural Language :: English',
'Operating System :: OS Independent',
'Framework :: Zope3'
],
namespace_packages=["zc"],
packages=["zc", "zc.queue"],
package_dir={"": "src"},
url='http://pypi.python.org/pypi/zc.queue',
license="ZPL 2.1",
namespace_packages=['zc'],
packages=['zc', 'zc.queue'],
package_dir={'': 'src'},
include_package_data=True,
install_requires=[
"setuptools",
"ZODB3",
"zope.interface",
'setuptools',
'ZODB',
'persistent',
'zope.interface',
],
tests_require=tests_require,
test_suite='zc.queue.tests.test_suite',
extras_require=dict(
test=tests_require,
),
description=read('README.txt'),
long_description='\n\n'.join([
read('src', 'zc', 'queue', 'queue.txt'),
read('CHANGES.txt'),
]),
keywords="zope zope3",
zip_safe=False
)
30 changes: 21 additions & 9 deletions src/zc/queue/_queue.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
##############################################################################
#
# Copyright (c) 2011 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Queue Implementations
"""
from persistent import Persistent
from ZODB.ConflictResolution import PersistentReference
from ZODB.POSException import ConflictError
from zope import interface

from zc.queue import interfaces


@interface.implementer(interfaces.IQueue)
class Queue(Persistent):

interface.implements(interfaces.IQueue)

def __init__(self):
self._data = ()

Expand Down Expand Up @@ -94,9 +107,9 @@ def resolveQueueConflict(oldstate, committedstate, newstate, bucket=False):
# PersistentReference objects. See 'queue.txt'
wrap = lambda x: (
PersistentReferenceProxy(x) if isinstance(x, PersistentReference) else x)
old = map(wrap, oldstate['_data'])
committed = map(wrap, committedstate['_data'])
new = map(wrap, newstate['_data'])
old = list(map(wrap, oldstate['_data']))
committed = list(map(wrap, committedstate['_data']))
new = list(map(wrap, newstate['_data']))

old_set = set(old)
committed_set = set(committed)
Expand Down Expand Up @@ -132,11 +145,12 @@ def resolveQueueConflict(oldstate, committedstate, newstate, bucket=False):
if new_added:
ordered_new_added = new[-len(new_added):]
assert set(ordered_new_added) == new_added
mod_committed.extend(map(unwrap, ordered_new_added))
mod_committed.extend(list(map(unwrap, ordered_new_added)))
committedstate['_data'] = tuple(mod_committed)
return committedstate


@interface.implementer(interfaces.IQueue)
class CompositeQueue(Persistent):
"""Appropriate for queues that may become large.
Expand Down Expand Up @@ -168,8 +182,6 @@ class CompositeQueue(Persistent):
# when two transactions happen sequentially *while* a third
# transaction happens concurrently to both.

interface.implements(interfaces.IQueue)

def __init__(self, compositeSize=15, subfactory=BucketQueue):
# the compositeSize value is a ballpark. Because of the merging
# policy, a composite queue might get as big as 2n under unusual
Expand Down
Loading

0 comments on commit 189cde1

Please sign in to comment.