Skip to content

Commit

Permalink
black everything (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Bengtsson authored Dec 3, 2018
1 parent 4ca9c89 commit ed6aea2
Show file tree
Hide file tree
Showing 10 changed files with 177 additions and 133 deletions.
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flake8]
max-line-length = 88
9 changes: 9 additions & 0 deletions .therapist.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
actions:
black:
run: black --check --diff {files}
fix: black {files}
include: "*.py"

flake8:
run: flake8 {files}
include: "*.py"
38 changes: 38 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ django-cache-memoize
:alt: Code Coverage
:target: https://codecov.io/gh/peterbe/django-cache-memoize

.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
:target: https://github.com/ambv/black

Django utility for a memoization decorator that uses the Django cache framework.

Expand Down Expand Up @@ -387,3 +389,39 @@ The most basic thing is to clone the repo and run:
pip install -e ".[dev]"
tox
Code style is all black
~~~~~~~~~~~~~~~~~~~~~~~

All code has to be formatted with `Black <https://pypi.org/project/black/>`_
and the best tool for checking this is
`therapist <https://pypi.org/project/therapist/>`_ since it can help you run
all, help you fix things, and help you make sure linting is passing before
you git commit. This project also uses ``flake8`` to check other things
Black can't check.

To check linting with ``tox`` use:

.. code:: bash
tox -e lint-py36
To install the ``therapist`` pre-commit hook simply run:

.. code:: bash
therapist install
When you run ``therapist run`` it will only check the files you've touched.
To run it for all files use:

.. code:: bash
therapist run --use-tracked-files
And to fix all/any issues run:

.. code:: bash
therapist run --use-tracked-files --fix
68 changes: 39 additions & 29 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,30 @@
extensions = []

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'
source_suffix = ".rst"

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# General information about the project.
project = 'django-cache-memoize'
copyright = '2017, Peter Bengtsson'
author = 'Peter Bengtsson'
project = "django-cache-memoize"
copyright = "2017, Peter Bengtsson"
author = "Peter Bengtsson"

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = ''
version = ""
# The full version, including alpha/beta/rc tags.
release = ''
release = ""

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand All @@ -69,10 +69,10 @@
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This patterns also effect to html_static_path and html_extra_path
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
pygments_style = "sphinx"

# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = False
Expand All @@ -83,7 +83,7 @@
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'alabaster'
html_theme = "alabaster"

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
Expand All @@ -94,25 +94,25 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]

# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
#
# This is required for the alabaster theme
# refs: http://alabaster.readthedocs.io/en/latest/installation.html#sidebars
html_sidebars = {
'**': [
'relations.html', # needs 'show_related': True theme option to display
'searchbox.html',
"**": [
"relations.html", # needs 'show_related': True theme option to display
"searchbox.html",
]
}


# -- Options for HTMLHelp output ------------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = 'django-cache-memoizedoc'
htmlhelp_basename = "django-cache-memoizedoc"


# -- Options for LaTeX output ---------------------------------------------
Expand All @@ -121,15 +121,12 @@
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',

# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
Expand All @@ -139,8 +136,13 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'django-cache-memoize.tex', 'django-cache-memoize Documentation',
'Peter Bengtsson', 'manual'),
(
master_doc,
"django-cache-memoize.tex",
"django-cache-memoize Documentation",
"Peter Bengtsson",
"manual",
)
]


Expand All @@ -149,8 +151,13 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'django-cache-memoize', 'django-cache-memoize Documentation',
[author], 1)
(
master_doc,
"django-cache-memoize",
"django-cache-memoize Documentation",
[author],
1,
)
]


Expand All @@ -160,10 +167,13 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'django-cache-memoize', 'django-cache-memoize Documentation',
author, 'django-cache-memoize', 'One line description of project.',
'Miscellaneous'),
(
master_doc,
"django-cache-memoize",
"django-cache-memoize Documentation",
author,
"django-cache-memoize",
"One line description of project.",
"Miscellaneous",
)
]



46 changes: 22 additions & 24 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,31 @@


setup(
name='django-cache-memoize',
version='0.1.4',
name="django-cache-memoize",
version="0.1.4",
description=(
'Django utility for a memoization decorator that uses the Django '
'cache framework.'
"Django utility for a memoization decorator that uses the Django "
"cache framework."
),
long_description=open(path.join(_here, 'README.rst')).read(),
author='Peter Bengtsson',
author_email='mail@peterbe.com',
license='MPL 2.0',
url='https://github.com/peterbe/django-cache-memoize',
packages=find_packages(where='src'),
package_dir={'': 'src'},
long_description=open(path.join(_here, "README.rst")).read(),
author="Peter Bengtsson",
author_email="mail@peterbe.com",
license="MPL 2.0",
url="https://github.com/peterbe/django-cache-memoize",
packages=find_packages(where="src"),
package_dir={"": "src"},
classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: Web Environment :: Mozilla',
'Framework :: Django',
'Intended Audience :: Developers',
'License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Topic :: Internet :: WWW/HTTP',
"Development Status :: 5 - Production/Stable",
"Environment :: Web Environment :: Mozilla",
"Framework :: Django",
"Intended Audience :: Developers",
"License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Topic :: Internet :: WWW/HTTP",
],
keywords=['django', 'memoize', 'cache', 'decorator'],
keywords=["django", "memoize", "cache", "decorator"],
zip_safe=False,
extras_require={
'dev': ['flake8', 'tox', 'twine'],
}
extras_require={"dev": ["flake8", "tox", "twine", "therapist", "black"]},
)
17 changes: 9 additions & 8 deletions src/cache_memoize/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,30 +82,31 @@ def callmeonce(arg1):
"""

if args_rewrite is None:

def noop(*args):
return args

args_rewrite = noop

cache = caches[cache_alias]

def decorator(func):

def _make_cache_key(*args, **kwargs):
cache_key = ':'.join(
[force_text(x) for x in args_rewrite(*args)] +
[force_text('{}={}'.format(k, v)) for k, v in kwargs.items()]
cache_key = ":".join(
[force_text(x) for x in args_rewrite(*args)]
+ [force_text("{}={}".format(k, v)) for k, v in kwargs.items()]
)
return hashlib.md5(force_bytes(
'cache_memoize' + (prefix or func.__name__) + cache_key
)).hexdigest()
return hashlib.md5(
force_bytes("cache_memoize" + (prefix or func.__name__) + cache_key)
).hexdigest()

@wraps(func)
def inner(*args, **kwargs):
if key_generator_callable is None:
cache_key = _make_cache_key(*args, **kwargs)
else:
cache_key = key_generator_callable(*args, **kwargs)
if kwargs.pop('_refresh', False):
if kwargs.pop("_refresh", False):
result = MARKER
else:
result = cache.get(cache_key, MARKER)
Expand Down
5 changes: 3 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
@pytest.fixture(autouse=True)
def clear_cache():
from django.core.cache import caches
caches['default'].clear()
caches['locmem'].clear()

caches["default"].clear()
caches["locmem"].clear()
Loading

0 comments on commit ed6aea2

Please sign in to comment.