From eba014828b5c1ddfa53b4d9fd320755335144d11 Mon Sep 17 00:00:00 2001 From: kindlycat Date: Thu, 16 Apr 2020 02:03:58 +0300 Subject: [PATCH 1/4] Update supported versions; add black --- .travis.yml | 8 +------- Makefile | 12 +++++++++++- pyproject.toml | 12 ++++++++++++ request_vars/conf.py | 4 +--- request_vars/decorators.py | 1 + request_vars/middleware.py | 4 ++-- request_vars/templatetags/request_vars.py | 4 +--- request_vars/utils.py | 8 ++++++-- requirements.txt | 2 -- setup.cfg | 22 ++++++++++++++++------ setup.py | 16 +++++++++++----- tests/settings.py | 11 ++--------- tests/test_app/urls.py | 11 ++++++++--- tests/test_app/views.py | 8 +++++--- tests/test_middleware.py | 11 ++++++----- tests/test_templatetags.py | 8 ++++---- tests/test_utils.py | 9 ++++++--- tox.ini | 18 ++++++++---------- 18 files changed, 101 insertions(+), 68 deletions(-) create mode 100644 pyproject.toml diff --git a/.travis.yml b/.travis.yml index 7189b2f..0774683 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,26 +1,20 @@ language: python sudo: false python: - - 2.7 - 3.5 - 3.6 - 3.7 - 3.8 env: - - DJANGO=1.11 - DJANGO=2.2 - DJANGO=3.0 - DJANGO=master matrix: exclude: - - { python: 2.7, env: DJANGO=2.2 } - - { python: 2.7, env: DJANGO=3.0 } - - { python: 2.7, env: DJANGO=master } - { python: 3.5, env: DJANGO=3.0 } - { python: 3.5, env: DJANGO=master } include: - - { python: 3.8, env: TOXENV=flake } - + - { python: 3.8, env: TOXENV=linters } install: - pip install tox-travis coveralls diff --git a/Makefile b/Makefile index 6a0e9da..47d8e7a 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,7 @@ -.PHONY: clean, build +.PHONY: help, clean, build, docs + +help: + @cat $(MAKEFILE_LIST) clean: rm -rf build dist *.egg-info @@ -6,3 +9,10 @@ clean: build: python setup.py sdist python setup.py bdist_wheel + +docs: + make -C ./docs html + +linters: + flake8 . + black . --check diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..2beae63 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,12 @@ +[tool.black] +line-length = 79 +include = '\.pyi?$' +skip-string-normalization = true +exclude = ''' +( + migrations + | \.\* + | .venv + | docs +) +''' diff --git a/request_vars/conf.py b/request_vars/conf.py index 29094f8..1493971 100644 --- a/request_vars/conf.py +++ b/request_vars/conf.py @@ -2,9 +2,7 @@ from django.core.signals import setting_changed -DEFAULTS = { - 'REQUEST_VARS_MIDDLEWARE_CALLBACK': None -} +DEFAULTS = {'REQUEST_VARS_MIDDLEWARE_CALLBACK': None} class Settings(object): diff --git a/request_vars/decorators.py b/request_vars/decorators.py index 13fea66..c01d1de 100644 --- a/request_vars/decorators.py +++ b/request_vars/decorators.py @@ -18,4 +18,5 @@ def wrapped(*args, **kwargs): if get_variable('request'): set_variable(name, result) return result + return wrapped diff --git a/request_vars/middleware.py b/request_vars/middleware.py index 6a2d487..307b8d7 100644 --- a/request_vars/middleware.py +++ b/request_vars/middleware.py @@ -1,8 +1,8 @@ -from django.utils.module_loading import import_string - from request_vars.conf import settings from request_vars.utils import clear_thread_variable, set_variable +from django.utils.module_loading import import_string + class RequestVarsMiddleware(object): def __init__(self, get_response): diff --git a/request_vars/templatetags/request_vars.py b/request_vars/templatetags/request_vars.py index 3c08eea..46007ea 100644 --- a/request_vars/templatetags/request_vars.py +++ b/request_vars/templatetags/request_vars.py @@ -1,9 +1,7 @@ -from __future__ import absolute_import +from request_vars.utils import get_variable from django import template -from request_vars.utils import get_variable - try: from django_jinja import library diff --git a/request_vars/utils.py b/request_vars/utils.py index 6a5213a..c24a8cf 100644 --- a/request_vars/utils.py +++ b/request_vars/utils.py @@ -1,8 +1,12 @@ from request_vars import REQUEST_VARS -__all__ = ['set_variable', 'get_variable', 'del_variable', - 'clear_thread_variable'] +__all__ = [ + 'set_variable', + 'get_variable', + 'del_variable', + 'clear_thread_variable', +] def set_variable(key, val): diff --git a/requirements.txt b/requirements.txt index d344041..36027e4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,2 @@ django-jinja -sphinx -sphinx_rtd_theme tox diff --git a/setup.cfg b/setup.cfg index f5f1894..d1baa30 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,14 +1,24 @@ [bdist_wheel] -universal=1 +universal = 1 [isort] -multi_line_output=5 -lines_after_imports=2 +line_length = 79 +multi_line_output = 3 +lines_after_imports = 2 not_skip = __init__.py -skip=migrations,docs,build,.git,.tox,__pycache__ +skip = migrations,docs,build,.git,.tox,__pycache__ known_django = django -default_section=FIRSTPARTY +known_third_party = request_vars +default_section = FIRSTPARTY sections = FUTURE,STDLIB,THIRDPARTY,DJANGO,FIRSTPARTY,LOCALFOLDER +include_trailing_comma = True [flake8] -exclude=.git,.tox,__pycache__,build,docs,migrations +max-line-length = 79 +max-complexity = 12 +inline-quotes = ' +ignore = A003,W503 +exclude = .git,.tox,__pycache__,build,docs,migrations + +[coverage:run] +omit = */management/* diff --git a/setup.py b/setup.py index f7f8bff..2c72e5f 100644 --- a/setup.py +++ b/setup.py @@ -2,9 +2,8 @@ from distutils.core import setup -from setuptools import find_packages - from request_vars import __version__ +from setuptools import find_packages def readme(): @@ -16,10 +15,17 @@ def readme(): name='django-request-vars', version=__version__, description='Stores current request, user and your defined data in thread ' - 'local variable.', + 'local variable.', long_description=readme(), - keywords=['django', 'thread', 'variable', 'request', 'user', 'cache', - 'middleware'], + keywords=[ + 'django', + 'thread', + 'variable', + 'request', + 'user', + 'cache', + 'middleware', + ], author='Grigory Mishchenko', author_email='grishkokot@gmail.com', url='https://github.com/kindlycat/django-request-vars/', diff --git a/tests/settings.py b/tests/settings.py index 401b1f9..8a14108 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -9,7 +9,6 @@ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', - 'request_vars', 'django_jinja', 'tests.test_app', @@ -23,7 +22,6 @@ 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', - 'request_vars.middleware.RequestVarsMiddleware', ] @@ -33,9 +31,7 @@ { "BACKEND": "django_jinja.backend.Jinja2", "APP_DIRS": True, - "OPTIONS": { - "match_extension": ".jinja", - } + "OPTIONS": {"match_extension": ".jinja"}, }, { 'BACKEND': 'django.template.backends.django.DjangoTemplates', @@ -53,8 +49,5 @@ ] DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': ':memory:', - } + 'default': {'ENGINE': 'django.db.backends.sqlite3', 'NAME': ':memory:'} } diff --git a/tests/test_app/urls.py b/tests/test_app/urls.py index 35d41f2..1022fc1 100644 --- a/tests/test_app/urls.py +++ b/tests/test_app/urls.py @@ -1,7 +1,9 @@ from django.conf.urls import url from tests.test_app.views import ( - request_cache_view, test_template_tag_view, test_view + request_cache_view, + test_template_tag_view, + test_view, ) @@ -9,6 +11,9 @@ url(r'^test_view/$', test_view), url(r'^request_cache_view/$', request_cache_view), url(r'^test_django_template_tag/$', test_template_tag_view), - url(r'^test_jinja_template_tag/$', test_template_tag_view, - kwargs={'template': 'index.jinja'}) + url( + r'^test_jinja_template_tag/$', + test_template_tag_view, + kwargs={'template': 'index.jinja'}, + ), ] diff --git a/tests/test_app/views.py b/tests/test_app/views.py index 3172a0d..c4b07b9 100644 --- a/tests/test_app/views.py +++ b/tests/test_app/views.py @@ -1,7 +1,8 @@ +from request_vars.utils import get_variable, set_variable + from django.http import HttpResponse from django.shortcuts import render -from request_vars.utils import get_variable, set_variable from tests.test_middleware import request_cache_fn @@ -16,8 +17,9 @@ def test_view(request): raise AssertionError('Bad user value.') # test callback - if request.GET.get('callback') and \ - request.GET['callback'] != get_variable('callback'): + if request.GET.get('callback') and request.GET['callback'] != get_variable( + 'callback' + ): raise AssertionError('Bad callback value.') return HttpResponse('') diff --git a/tests/test_middleware.py b/tests/test_middleware.py index d6b63aa..172ff77 100644 --- a/tests/test_middleware.py +++ b/tests/test_middleware.py @@ -1,10 +1,10 @@ +from request_vars import REQUEST_VARS +from request_vars.decorators import request_cache + from django.contrib.auth.models import User from django.test import TestCase from django.test.utils import override_settings -from request_vars import REQUEST_VARS -from request_vars.decorators import request_cache - def middleware_callback(request): REQUEST_VARS.callback = 'test_callback' @@ -23,8 +23,9 @@ def test_anonymous(self): self.assertEqual(response.status_code, 200) def test_logged_in_user(self): - User.objects.create_user(username='test_user', - password='test_password') + User.objects.create_user( + username='test_user', password='test_password' + ) self.client.login(username='test_user', password='test_password') response = self.client.get('/test_view/') self.assertEqual(response.status_code, 200) diff --git a/tests/test_templatetags.py b/tests/test_templatetags.py index 2c035cd..8af567a 100644 --- a/tests/test_templatetags.py +++ b/tests/test_templatetags.py @@ -4,10 +4,10 @@ class TemplatetagsTestCase(TestCase): def setUp(self): - self.user = User.objects.create_user(username='test_user', - password='test_password') - self.client.login(username='test_user', - password='test_password') + self.user = User.objects.create_user( + username='test_user', password='test_password' + ) + self.client.login(username='test_user', password='test_password') def test_django_template(self): response = self.client.get('/test_django_template_tag/') diff --git a/tests/test_utils.py b/tests/test_utils.py index c390ed9..2eaf6d1 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,10 +1,13 @@ -from django.test.testcases import SimpleTestCase - from request_vars import REQUEST_VARS from request_vars.utils import ( - clear_thread_variable, del_variable, get_variable, set_variable + clear_thread_variable, + del_variable, + get_variable, + set_variable, ) +from django.test.testcases import SimpleTestCase + class UtilsTestCase(SimpleTestCase): def test_get_variable(self): diff --git a/tox.ini b/tox.ini index a08d675..66ae4af 100644 --- a/tox.ini +++ b/tox.ini @@ -1,36 +1,34 @@ [tox] skip_missing_interpreters = True envlist = - py{27,35,36,37}-dj{111} py{35,36,37,38}-{dj22} py{36,37,38}-{dj30,djmaster} flake [testenv] basepython = - py27: python2.7 py35: python3.5 py36: python3.6 py37: python3.7 py38: python3.8 deps = - dj111: Django>=1.11,<2.0 dj22: Django>=2.2,<2.3 dj30: Django>=3.0,<3.1 djmaster: https://github.com/django/django/archive/master.tar.gz coverage -r requirements.txt -commands = coverage run --source=request_vars ./runtests.py {posargs} +commands = coverage run --source=simple_log ./runtests.py {posargs} -[testenv:flake] +[testenv:linters] basepython = python3 -deps = flake8-isort -commands = flake8 +deps = + flake8-isort + black +commands = make linters skip_install = True [travis:env] DJANGO = - 1.11: dj111 - 2.0: dj20 - 2.1: dj21 + 2.2: dj22 + 3.0: dj30 master: djmaster From 287228a9e73858dceb007c3e9fe998ca238bed58 Mon Sep 17 00:00:00 2001 From: kindlycat Date: Thu, 16 Apr 2020 02:05:51 +0300 Subject: [PATCH 2/4] Fix tox.ini --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 66ae4af..0896879 100644 --- a/tox.ini +++ b/tox.ini @@ -17,7 +17,7 @@ deps = djmaster: https://github.com/django/django/archive/master.tar.gz coverage -r requirements.txt -commands = coverage run --source=simple_log ./runtests.py {posargs} +commands = coverage run --source=request_vars ./runtests.py {posargs} [testenv:linters] basepython = python3 From a6985105a6bd331ffbd78778f412b980a926d4fc Mon Sep 17 00:00:00 2001 From: kindlycat Date: Thu, 16 Apr 2020 02:26:13 +0300 Subject: [PATCH 3/4] Ignore fails from django master --- tox.ini | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tox.ini b/tox.ini index 0896879..6fa17f0 100644 --- a/tox.ini +++ b/tox.ini @@ -18,6 +18,8 @@ deps = coverage -r requirements.txt commands = coverage run --source=request_vars ./runtests.py {posargs} +ignore_outcome = + djmaster: True [testenv:linters] basepython = python3 From 191916c7b12ef6881c3df2314e7197d6abc12c5d Mon Sep 17 00:00:00 2001 From: kindlycat Date: Thu, 16 Apr 2020 02:36:33 +0300 Subject: [PATCH 4/4] Revert "Ignore fails from django master" This reverts commit a6985105a6bd331ffbd78778f412b980a926d4fc. --- tox.ini | 2 -- 1 file changed, 2 deletions(-) diff --git a/tox.ini b/tox.ini index 6fa17f0..0896879 100644 --- a/tox.ini +++ b/tox.ini @@ -18,8 +18,6 @@ deps = coverage -r requirements.txt commands = coverage run --source=request_vars ./runtests.py {posargs} -ignore_outcome = - djmaster: True [testenv:linters] basepython = python3