Skip to content
This repository has been archived by the owner on May 5, 2021. It is now read-only.

Commit

Permalink
Merge pull request #10 from agronholm/master
Browse files Browse the repository at this point in the history
Fixed Python 3 compatibility, packaging and code style problems
  • Loading branch information
optimuspaul committed May 11, 2015
2 parents 663f1d3 + 3947d26 commit 142545d
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 16 deletions.
3 changes: 2 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
recursive-include redlock *
include LICENSE.txt
recursive-include tests *.py
7 changes: 5 additions & 2 deletions redlock/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import redis
import string
import random
import time
from collections import namedtuple

import redis

# Python 3 compatibility
string_type = getattr(__builtins__, 'basestring', str)

Lock = namedtuple("Lock", ("validity", "resource", "key"))

Expand All @@ -28,7 +31,7 @@ def __init__(self, connection_list, retry_count=None, retry_delay=None):
self.servers = []
for connection_info in connection_list:
try:
if isinstance(connection_info, basestring):
if isinstance(connection_info, string_type):
server = redis.StrictRedis.from_url(connection_info)
else:
server = redis.StrictRedis(**connection_info)
Expand Down
1 change: 0 additions & 1 deletion redlock/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def lock(name, validity, redis, retry_count=3, retry_delay=200, **kwargs):
is_blocking = False

while True:
err = None
try:
dlm = redlock.Redlock(redis, retry_count=retry_count+1, retry_delay=retry_delay / 1000.0)
lock = dlm.lock(name, validity)
Expand Down
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[bdist_wheel]
universal = 1
28 changes: 20 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import os

from setuptools import setup, find_packages

# allow setup.py to be run from any path
os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir)))

REQUIREMENTS = ["redis"]

README = """
redlock-py - Redis distributed locks in Python
This python lib implements the Redis-based distributed lock manager algorithm [described in this blog post](http://antirez.com/news/77).
This python lib implements the Redis-based distributed lock manager algorithm
[described in this blog post](http://antirez.com/news/77).
To create a lock manager:
Expand Down Expand Up @@ -37,7 +37,9 @@
delay (by default 200 milliseconds) used to acquire the lock.
**Disclaimer**: This code implements an algorithm which is currently a proposal, it was not formally analyzed. Make sure to understand how it works before using it in your production environments.
**Disclaimer**: This code implements an algorithm which is currently a proposal,
it was not formally analyzed. Make sure to understand how it works before using it
in your production environments.
The MIT License (MIT)
Expand Down Expand Up @@ -66,18 +68,28 @@
setup(
name='redlock-py',
version='1.0.4',
license='MIT',
packages=find_packages(),
include_package_data=True,
description='Redis locking mechanism',
long_description=README,
url='https://github.com/SPSCommerce/identity-service',
classifiers=[
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.2',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4'
],
author='pjdecoursey@spscommerce.com',
author_email='webapps@spscommerce.com',
install_requires=REQUIREMENTS,
entry_points = {
install_requires=["redis"],
entry_points={
'console_scripts': [
'redlock = redlock.cli:main',
],
},
}
)
5 changes: 1 addition & 4 deletions tests/test_redlock.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import unittest

from redlock import Redlock


Expand All @@ -23,7 +24,3 @@ def test_blocked(self):
def test_bad_connection_info(self):
with self.assertRaises(Warning):
Redlock([{"cat": "hog"}])




0 comments on commit 142545d

Please sign in to comment.