Skip to content

Commit

Permalink
Merge pull request #1 from kindlycat/dev
Browse files Browse the repository at this point in the history
Update supported versions
Add black
  • Loading branch information
kindlycat committed Apr 16, 2020
2 parents 03f8e01 + 191916c commit 752f277
Show file tree
Hide file tree
Showing 18 changed files with 100 additions and 67 deletions.
8 changes: 1 addition & 7 deletions .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

Expand Down
12 changes: 11 additions & 1 deletion Makefile
@@ -1,8 +1,18 @@
.PHONY: clean, build
.PHONY: help, clean, build, docs

help:
@cat $(MAKEFILE_LIST)

clean:
rm -rf build dist *.egg-info

build:
python setup.py sdist
python setup.py bdist_wheel

docs:
make -C ./docs html

linters:
flake8 .
black . --check
12 changes: 12 additions & 0 deletions pyproject.toml
@@ -0,0 +1,12 @@
[tool.black]
line-length = 79
include = '\.pyi?$'
skip-string-normalization = true
exclude = '''
(
migrations
| \.\*
| .venv
| docs
)
'''
4 changes: 1 addition & 3 deletions request_vars/conf.py
Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions request_vars/decorators.py
Expand Up @@ -18,4 +18,5 @@ def wrapped(*args, **kwargs):
if get_variable('request'):
set_variable(name, result)
return result

return wrapped
4 changes: 2 additions & 2 deletions 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):
Expand Down
4 changes: 1 addition & 3 deletions 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
Expand Down
8 changes: 6 additions & 2 deletions 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):
Expand Down
2 changes: 0 additions & 2 deletions requirements.txt
@@ -1,4 +1,2 @@
django-jinja
sphinx
sphinx_rtd_theme
tox
22 changes: 16 additions & 6 deletions 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/*
16 changes: 11 additions & 5 deletions setup.py
Expand Up @@ -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():
Expand All @@ -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/',
Expand Down
11 changes: 2 additions & 9 deletions tests/settings.py
Expand Up @@ -9,7 +9,6 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',

'request_vars',
'django_jinja',
'tests.test_app',
Expand All @@ -23,7 +22,6 @@
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',

'request_vars.middleware.RequestVarsMiddleware',
]

Expand All @@ -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',
Expand All @@ -53,8 +49,5 @@
]

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory:',
}
'default': {'ENGINE': 'django.db.backends.sqlite3', 'NAME': ':memory:'}
}
11 changes: 8 additions & 3 deletions tests/test_app/urls.py
@@ -1,14 +1,19 @@
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,
)


urlpatterns = [
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'},
),
]
8 changes: 5 additions & 3 deletions 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


Expand All @@ -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('')

Expand Down
11 changes: 6 additions & 5 deletions 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'
Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions tests/test_templatetags.py
Expand Up @@ -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/')
Expand Down
9 changes: 6 additions & 3 deletions 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):
Expand Down
16 changes: 7 additions & 9 deletions 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}

[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

0 comments on commit 752f277

Please sign in to comment.