Skip to content

Commit

Permalink
Merge pull request #102 from yahoo/handle_unsupported_platforms
Browse files Browse the repository at this point in the history
Give a better exception message
  • Loading branch information
dwighthubbard committed May 5, 2016
2 parents b3c8f1b + 0c1d69a commit bd11122
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 16 deletions.
2 changes: 1 addition & 1 deletion redislite/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from . import __redis_executable__


logger = logging.getLogger(__name__)
logger = logging.getLogger(__name__) # pylint: disable=C0103


class RedisLiteException(Exception):
Expand Down
2 changes: 1 addition & 1 deletion redislite/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from copy import copy


logger = logging.getLogger(__name__)
logger = logging.getLogger(__name__) # pylint: disable=C0103


DEFAULT_REDIS_SETTINGS = {
Expand Down
2 changes: 1 addition & 1 deletion redislite/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@
"""
from __future__ import print_function
from distutils.spawn import find_executable
import os
from .__init__ import __version__, __git_version__, __source_url__, \
__git_hash__, __git_origin__, __git_branch__, __redis_server_info__, \
__redis_executable__
import os


def debug_info_list():
Expand Down
23 changes: 14 additions & 9 deletions redislite/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from .client import Redis, StrictRedis


logger = logging.getLogger(__name__)
logger = logging.getLogger(__name__) # pylint: disable=C0103


original_classes = collections.defaultdict(lambda: None) # pragma: no cover
Expand Down Expand Up @@ -111,8 +111,9 @@ class with no arguments will get a separate redis server. If the
Args:
dbfile(str):
The name of the Redis db file to be used. If this argument is passed all instances of the
:class:`redis.Redis` class will share a single instance of the embedded redis server.
The name of the Redis db file to be used. If this argument is
passed all instances of the :class:`redis.Redis` class will share
a single instance of the embedded redis server.
Returns:
This function does not return any values.
Expand Down Expand Up @@ -170,14 +171,17 @@ def patch_redis(dbfile=None):
Notes:
If the dbfile parameter is not passed, each any instances of :class:`redis.StrictRedis()` class with no
arguments will get a unique instance of the redis server. If the dbfile parameter is provided, all instances
of :class:`redis.Redis()` will share/reference the same instance of the redis server.
If the dbfile parameter is not passed, each any instances of
:class:`redis.StrictRedis()` class with no arguments will get a unique
instance of the redis server. If the dbfile parameter is provided, all
instances of :class:`redis.Redis()` will share/reference the same
instance of the redis server.
Args:
dbfile(str):
The name of the Redis db file to be used. If this argument is passed all instances of the
:class:`redis.Redis()` class will share a single instance of the embedded redis server.
The name of the Redis db file to be used. If this argument is
passed all instances of the :class:`redis.Redis()` class will
share a single instance of the embedded redis server.
Returns:
This function does not return any values.
Expand All @@ -188,7 +192,8 @@ def patch_redis(dbfile=None):

def unpatch_redis():
"""
Unpatch all the redis classes provided by :mod:`redislite` that have been patched.
Unpatch all the redis classes provided by :mod:`redislite` that have been
patched.
Example:
unpatch_redis()
Expand Down
21 changes: 17 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
from distutils.command.build import build
from distutils.core import Extension
import distutils.util
import sys
from subprocess import call


logger = logging.getLogger(__name__)

UNSUPPORTED_PLATFORMS = ['win32', 'win64']
METADATA_FILENAME = 'redislite/package_metadata.json'
BASEPATH = os.path.dirname(os.path.abspath(__file__))
REDIS_PATH = os.path.join(BASEPATH, 'redis.submodule')
Expand All @@ -27,7 +30,7 @@ def readme():
return f.read()


class build_redis(build):
class BuildRedis(build):
global REDIS_SERVER_METADATA

def run(self):
Expand Down Expand Up @@ -71,9 +74,10 @@ def _compile():


class InstallRedis(install):
build_scripts = None

def initialize_options(self):
install.initialize_options(self)
self.build_scripts = None

def finalize_options(self):
install.finalize_options(self)
Expand Down Expand Up @@ -115,7 +119,8 @@ def run(self):
)
# Store the redis-server --version output for later
for line in os.popen('%s --version' % md['redis_bin']).readlines():
for item in line.strip().split():
line = line.strip()
for item in line.split():
if '=' in item:
key, value = item.split('=')
REDIS_SERVER_METADATA[key] = value
Expand Down Expand Up @@ -167,7 +172,7 @@ def run(self):
},
'include_package_data': True,
'cmdclass': {
'build': build_redis,
'build': BuildRedis,
'install': InstallRedis,
},

Expand Down Expand Up @@ -265,6 +270,14 @@ def get_and_update_metadata():


if __name__ == '__main__':
if sys.platform in UNSUPPORTED_PLATFORMS:
print(
'The redislite module is not supported on the %r '
'platform' % sys.platform,
file=sys.stderr
)
sys.exit(1)

os.environ['CC'] = 'gcc'

logging.basicConfig(level=logging.INFO)
Expand Down
4 changes: 4 additions & 0 deletions tests/test_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ def test_redislite_patch_strictredis_with_dbfile(self):
# Both instances should be talking to the same redis server
self.assertEqual(r.pid, s.pid)
redislite.patch.unpatch_redis_StrictRedis()
r._cleanup()
s._cleanup()
if os.path.exists(dbfilename):
os.remove(dbfilename)


if __name__ == '__main__':
Expand Down

0 comments on commit bd11122

Please sign in to comment.