diff --git a/CHANGELOG.md b/CHANGELOG.md index cd53ff4f55e3162183d90f0b7286b4fca720079f..72d89add3f327a72178903cf21591b641fb4c79f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## v2.0.22rc4 + +* fixes #14 + ## v2.0.22rc3 * fixes #15 diff --git a/satella/__init__.py b/satella/__init__.py index df3b3c231d188902da7909fa0ba4200604daa320..2e0230c7729eeefd822f9e0d26d266b68553848d 100644 --- a/satella/__init__.py +++ b/satella/__init__.py @@ -1,2 +1,2 @@ # coding=UTF-8 -__version__ = '2.0.22rc3' +__version__ = '2.0.22rc4' diff --git a/satella/coding/__init__.py b/satella/coding/__init__.py index 186075c7261377b4ebe0fae1f9d7fedd17b5f4c9..e0bcd88a33f01f09e6c6db45be3d6aa553f27c3e 100644 --- a/satella/coding/__init__.py +++ b/satella/coding/__init__.py @@ -13,7 +13,8 @@ from .typecheck import typed, Callable, Sequence, \ Number, coerce, Set, Dict, List, Tuple, checked_coerce, for_argument, \ precondition, PreconditionError from .structures import TimeBasedHeap, Heap, typednamedtuple, OmniHashableMixin -from .singleton import Singleton +from singleton_decorator import singleton as Singleton + __all__ = [ 'typednamedtuple', 'OmniHashableMixin' diff --git a/satella/coding/singleton.py b/satella/coding/singleton.py deleted file mode 100644 index 0c8f9d4fd6641a2ad4c605d57ee53c013fa1f24b..0000000000000000000000000000000000000000 --- a/satella/coding/singleton.py +++ /dev/null @@ -1,68 +0,0 @@ -# coding=UTF-8 -from __future__ import print_function, absolute_import, division - -import functools - -import six - -__all__ = [ - 'Singleton', -] - -if six.PY3: - - # Taken from https://wiki.python.org/moin/PythonDecoratorLibrary - def Singleton(cls): - """ - Make a singleton out of decorated class. - - Usage: - - @Singleton - class MyClass(object): - ... - """ - - cls.__new_old__ = cls.__new__ - - @functools.wraps(cls.__new__) - def singleton_new(cls, *args, **kw): - it = cls.__dict__.get('__it__') - if it is not None: - return it - - cls.__it__ = it = cls.__new_old__(cls, *args, **kw) - it.__init_old__(*args, **kw) - return it - - cls.__new__ = singleton_new - cls.__init_old__ = cls.__init__ - cls.__init__ = object.__init__ - - return cls -else: - class _SingletonWrapper: - """ - A singleton wrapper class. Its instances would be created - for each decorated class. - """ - - def __init__(self, cls): - self.__wrapped__ = cls - self._instance = None - - def __call__(self, *args, **kwargs): - """Returns a single instance of decorated class""" - if self._instance is None: - self._instance = self.__wrapped__(*args, **kwargs) - return self._instance - - - # taken from https://pypi.python.org/pypi/singleton-decorator/1.0.0 - def Singleton(cls): - """ - A singleton decorator. Returns a wrapper objects. A call on that object - returns a single instance object of decorated class. Use the __wrapped__ - attribute to access decorated class directly in unit tests. - """ - return _SingletonWrapper(cls) diff --git a/setup.py b/setup.py index 00b5b535556b37c316faf4dcb5c39fe309f55ba8..57c9f4e5674c99dfa1dac1cfe4aca5719c2c0bfe 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,8 @@ setup(keywords=['ha', 'high availability', 'scalable', 'scalability', 'server'], install_requires=[ "six", "monotonic", - "typing" + "typing", + 'singleton-decorator==1.0.0' ], tests_require=[ "nose", "mock", "coverage"