Skip to content

Commit

Permalink
Improved linting with autoflake, black and isort.
Browse files Browse the repository at this point in the history
  • Loading branch information
akornatskyy committed Aug 9, 2020
1 parent 7a11c82 commit da86966
Show file tree
Hide file tree
Showing 25 changed files with 740 additions and 652 deletions.
94 changes: 46 additions & 48 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,72 +8,70 @@
extra = {}
try:
from Cython.Build import cythonize
p = os.path.join('src', 'wheezy', 'caching')
extra['ext_modules'] = cythonize(
[os.path.join(p, '*.py')],
exclude=os.path.join(p, '__init__.py'),
nthreads=2, quiet=True)

p = os.path.join("src", "wheezy", "caching")
extra["ext_modules"] = cythonize(
[os.path.join(p, "*.py")],
exclude=os.path.join(p, "__init__.py"),
nthreads=2,
quiet=True,
)
except ImportError:
pass

README = open(os.path.join(os.path.dirname(__file__), 'README.md')).read()
README = open(os.path.join(os.path.dirname(__file__), "README.md")).read()
VERSION = (
re.search(
r"__version__ = '(.+)'",
open("src/wheezy/caching/__init__.py").read(),
r'__version__ = "(.+)"', open("src/wheezy/caching/__init__.py").read(),
)
.group(1)
.strip()
)

setup(
name='wheezy.caching',
name="wheezy.caching",
version=VERSION,
description='A lightweight caching library',
description="A lightweight caching library",
long_description=README,
long_description_content_type='text/markdown',
url='https://github.com/akornatskyy/wheezy.caching',
author='Andriy Kornatskyy',
author_email='andriy.kornatskyy@live.com',
license='MIT',
long_description_content_type="text/markdown",
url="https://github.com/akornatskyy/wheezy.caching",
author="Andriy Kornatskyy",
author_email="andriy.kornatskyy@live.com",
license="MIT",
classifiers=[
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Natural Language :: English',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.4',
'Programming Language :: Python :: 2.5',
'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',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
'Topic :: Software Development :: Libraries :: Python Modules'
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.4",
"Programming Language :: Python :: 2.5",
"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",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
"Topic :: Software Development :: Libraries :: Python Modules",
],
keywords='caching dependency memory null memcache memcached pylibmc',
packages=['wheezy', 'wheezy.caching'],
package_dir={'': 'src'},
namespace_packages=['wheezy'],
keywords="caching dependency memory null memcache memcached pylibmc",
packages=["wheezy", "wheezy.caching"],
package_dir={"": "src"},
namespace_packages=["wheezy"],
zip_safe=False,
install_requires=[],
extras_require={
'pylibmc': [
'pylibmc'
],
'python-memcached': [
'python-memcached'
]
"pylibmc": ["pylibmc"],
"python-memcached": ["python-memcached"],
},
platforms='any',
platforms="any",
**extra
)
3 changes: 2 additions & 1 deletion src/wheezy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# See
# http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
try:
__import__('pkg_resources').declare_namespace(__name__)
__import__("pkg_resources").declare_namespace(__name__)
except ImportError:
from pkgutil import extend_path

__path__ = extend_path(__path__, __name__)
8 changes: 1 addition & 7 deletions src/wheezy/caching/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@

"""
"""

# flake8: noqa

from wheezy.caching.client import CacheClient
from wheezy.caching.dependency import CacheDependency
from wheezy.caching.memory import MemoryCache
from wheezy.caching.null import NullCache


__version__ = '0.1'
__version__ = "0.1"
31 changes: 14 additions & 17 deletions src/wheezy/caching/client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

""" ``client`` module.
"""

Expand Down Expand Up @@ -26,46 +25,42 @@ def set(self, key, value, time=0, namespace=None):
in cache.
"""
namespace = namespace or self.default_namespace
return self.namespaces[namespace].set(
key, value, time, namespace)
return self.namespaces[namespace].set(key, value, time, namespace)

def set_multi(self, mapping, time=0, namespace=None):
""" Set multiple keys' values at once.
"""
namespace = namespace or self.default_namespace
return self.namespaces[namespace].set_multi(
mapping, time, namespace)
return self.namespaces[namespace].set_multi(mapping, time, namespace)

def add(self, key, value, time=0, namespace=None):
""" Sets a key's value, if and only if the item is not
already.
"""
namespace = namespace or self.default_namespace
return self.namespaces[namespace].add(
key, value, time, namespace)
return self.namespaces[namespace].add(key, value, time, namespace)

def add_multi(self, mapping, time=0, namespace=None):
""" Adds multiple values at once, with no effect for keys
already in cache.
"""
namespace = namespace or self.default_namespace
return self.namespaces[namespace].add_multi(
mapping, time, namespace)
return self.namespaces[namespace].add_multi(mapping, time, namespace)

def replace(self, key, value, time=0, namespace=None):
""" Replaces a key's value, failing if item isn't already.
"""
namespace = namespace or self.default_namespace
return self.namespaces[namespace].replace(
key, value, time, namespace)
return self.namespaces[namespace].replace(key, value, time, namespace)

def replace_multi(self, mapping, time=0, namespace=None):
""" Replaces multiple values at once, with no effect for
keys not in cache.
"""
namespace = namespace or self.default_namespace
return self.namespaces[namespace].replace_multi(
mapping, time, namespace)
mapping, time, namespace
)

def get(self, key, namespace=None):
""" Looks up a single key.
Expand All @@ -78,8 +73,7 @@ def get_multi(self, keys, namespace=None):
This is the recommended way to do bulk loads.
"""
namespace = namespace or self.default_namespace
return self.namespaces[namespace].get_multi(
keys, namespace)
return self.namespaces[namespace].get_multi(keys, namespace)

def delete(self, key, seconds=0, namespace=None):
""" Deletes a key from cache.
Expand All @@ -92,7 +86,8 @@ def delete_multi(self, keys, seconds=0, namespace=None):
"""
namespace = namespace or self.default_namespace
return self.namespaces[namespace].delete_multi(
keys, seconds, namespace)
keys, seconds, namespace
)

def incr(self, key, delta=1, namespace=None, initial_value=None):
""" Atomically increments a key's value. The value, if too
Expand All @@ -106,7 +101,8 @@ def incr(self, key, delta=1, namespace=None, initial_value=None):
"""
namespace = namespace or self.default_namespace
return self.namespaces[namespace].incr(
key, delta, namespace, initial_value)
key, delta, namespace, initial_value
)

def decr(self, key, delta=1, namespace=None, initial_value=None):
""" Atomically decrements a key's value. The value, if too
Expand All @@ -120,7 +116,8 @@ def decr(self, key, delta=1, namespace=None, initial_value=None):
"""
namespace = namespace or self.default_namespace
return self.namespaces[namespace].decr(
key, delta, namespace, initial_value)
key, delta, namespace, initial_value
)

def flush_all(self):
""" Deletes everything in cache.
Expand Down
7 changes: 5 additions & 2 deletions src/wheezy/caching/comp.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@

""" ``comp`` module.
"""

import sys


PY_MAJOR = sys.version_info[0]
PY_MINOR = sys.version_info[1]
PY2 = PY_MAJOR == 2
PY3 = PY_MAJOR >= 3


if PY3: # pragma: nocover

def iteritems(d):
return d.items()

Expand All @@ -23,7 +22,10 @@ def itervalues(d):

def list_map(f, iter):
return list(map(f, iter))


else: # pragma: nocover

def iteritems(d):
return d.iteritems() # noqa: B301

Expand All @@ -50,6 +52,7 @@ def itervalues(d):
def __import__(name, globals=None, locals=None, f=None): # noqa: N807
return __saved_import__(name, globals, locals, f, 0)


if PY3: # pragma: nocover
from queue import Queue
else: # pragma: nocover
Expand Down
35 changes: 18 additions & 17 deletions src/wheezy/caching/dependency.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@

""" ``dependency`` module.
"""

from wheezy.caching.comp import itervalues
from wheezy.caching.comp import xrange
from wheezy.caching.comp import itervalues, xrange
from wheezy.caching.utils import total_seconds


Expand All @@ -28,29 +26,31 @@ def next_key(self, master_key):
*master_key* - a key used to track a number of issued dependencies.
"""
return master_key + str(self.cache.incr(
master_key, 1, self.namespace, 0))
return master_key + str(
self.cache.incr(master_key, 1, self.namespace, 0)
)

def next_keys(self, master_key, n):
""" Returns *n* number of dependency keys.
*master_key* - a key used to track a number of issued dependencies.
"""
last_id = self.cache.incr(master_key, n, self.namespace, 0)
return [master_key + str(i)
for i in xrange(last_id - n + 1, last_id + 1)]
return [
master_key + str(i) for i in xrange(last_id - n + 1, last_id + 1)
]

def add(self, master_key, key):
""" Adds a given *key* to dependency.
"""
return self.cache.add(self.next_key(master_key),
key, self.time, self.namespace)
return self.cache.add(
self.next_key(master_key), key, self.time, self.namespace
)

def add_multi(self, master_key, keys):
""" Adds several *keys* to dependency.
"""
mapping = dict(zip(
self.next_keys(master_key, len(keys)), keys))
mapping = dict(zip(self.next_keys(master_key, len(keys)), keys))
return self.cache.add_multi(mapping, self.time, self.namespace)

def get_keys(self, master_key):
Expand All @@ -60,8 +60,7 @@ def get_keys(self, master_key):
if n is None:
return []
keys = [master_key + str(i) for i in xrange(1, n + 1)]
keys.extend(itervalues(self.cache.get_multi(
keys, self.namespace)))
keys.extend(itervalues(self.cache.get_multi(keys, self.namespace)))
keys.append(master_key)
return keys

Expand All @@ -71,10 +70,12 @@ def get_multi_keys(self, master_keys):
numbers = self.cache.get_multi(master_keys, self.namespace)
if not numbers:
return []
keys = [master_key + str(i) for master_key, n in numbers.items()
for i in xrange(1, n + 1)]
keys.extend(itervalues(self.cache.get_multi(
keys, self.namespace)))
keys = [
master_key + str(i)
for master_key, n in numbers.items()
for i in xrange(1, n + 1)
]
keys.extend(itervalues(self.cache.get_multi(keys, self.namespace)))
keys.extend(master_keys)
return keys

Expand Down
Loading

0 comments on commit da86966

Please sign in to comment.