Skip to content
This repository has been archived by the owner on Dec 10, 2021. It is now read-only.

Commit

Permalink
Blackify, updateify
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiask committed Jun 12, 2019
1 parent ffb8803 commit cb0abd4
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 121 deletions.
47 changes: 34 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,42 @@
language: python
dist: xenial
sudo: false
language: python
cache: pip

python:
- "3.6"
- "3.5"
- "2.7"
env:
- REQ="Django>=1.10,<1.11"
- REQ="Django>=1.11,<2.0"
- REQ="Django>=2.0,<2.1"
- 3.7
matrix:
exclude:
- python: '2.7'
fast_finish: true
include:
- python: 3.7
env: REQ="https://github.com/django/django/archive/master.zip#egg=Django"
- python: 3.7
env: REQ="Django>=2.2,<3.0"
- python: 3.6
env: REQ="Django>=2.2,<3.0"
- python: 3.5
env: REQ="Django>=2.2,<3.0"
- python: 3.7
env: REQ="Django>=2.1,<2.2"
- python: 3.7
env: REQ="Django>=2.0,<2.1"
- python: 3.7
env: REQ="Django>=1.11,<2.0"
- python: 3.6
env: REQ="Django>=1.11,<2.0"
- python: 3.5
env: REQ="Django>=1.11,<2.0"
- python: 3.4
env: REQ="Django>=1.11,<2.0"
- python: 3.7
env: REQ="black flake8"
install: skip
script:
- pip install black flake8
- flake8 .
- black --check privacy_killer tests
install:
- pip install -U pip wheel
- pip install $REQ flake8
- pip install $REQ
- python setup.py install
# command to run tests, e.g. python setup.py test
script: "cd tests && ./manage.py test testapp && cd .. && flake8 ."
script: cd tests && ./manage.py test -v2 testapp
2 changes: 1 addition & 1 deletion privacy_killer/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
VERSION = (0, 1, 0)
__version__ = '.'.join(map(str, VERSION))
__version__ = ".".join(map(str, VERSION))
21 changes: 7 additions & 14 deletions privacy_killer/templatetags/privacy_killer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,25 @@

SNIPPETS = [
(
r'^GTM-',
'privacy_killer/google_tag_manager_head.html',
'privacy_killer/google_tag_manager_body.html',
),
(
r'^UA-',
'privacy_killer/google_analytics_head.html',
None,
r"^GTM-",
"privacy_killer/google_tag_manager_head.html",
"privacy_killer/google_tag_manager_body.html",
),
(r"^UA-", "privacy_killer/google_analytics_head.html", None),
]


def _snippets(index):
parts = []
for id in getattr(settings, 'PRIVACY_KILLER_IDS', ()):
for id in getattr(settings, "PRIVACY_KILLER_IDS", ()):
for snippet in SNIPPETS:
if re.search(snippet[0], id) and snippet[index]:
parts.append(render_to_string(
snippet[index],
{'id': id},
))
parts.append(render_to_string(snippet[index], {"id": id}))
break
else:
# TODO Emit a warning.
pass
return mark_safe(''.join(parts))
return mark_safe("".join(parts))


@register.simple_tag
Expand Down
21 changes: 11 additions & 10 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
[flake8]
exclude=venv,.tox,migrations,docs
ignore=E203,W503
max-complexity=10
max-line-length=88

[bdist_wheel]
universal = 1

[isort]
combine_as_imports = true
default_section = THIRDPARTY
include_trailing_comma = true
multi_line_output=3
include_trailing_comma=True
force_grid_wrap=0
use_parentheses=True
line_length=88
lines_after_imports=2
known_django=django
known_standard_library=PIL
line_length = 79
multi_line_output = 5
not_skip = __init__.py
skip = migrations
sections = FUTURE,STDLIB,DJANGO,THIRDPARTY,FIRSTPARTY,LOCALFOLDER
lines_after_imports = 2
combine_as_imports=True
sections=FUTURE,STDLIB,DJANGO,THIRDPARTY,FIRSTPARTY,LOCALFOLDER

[coverage:run]
branch = True
Expand Down
41 changes: 20 additions & 21 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,28 @@ def read(filename):


setup(
name='django-privacy-killer',
version=__import__('privacy_killer').__version__,
description='Template tags for including tracker codes',
long_description=read('README.rst'),
author='Matthias Kestenholz',
author_email='mk@feinheit.ch',
url='http://github.com/matthiask/django-privacy-killer/',
license='BSD License',
platforms=['OS Independent'],
packages=find_packages(exclude=['tests']),
name="django-privacy-killer",
version=__import__("privacy_killer").__version__,
description="Template tags for including tracker codes",
long_description=read("README.rst"),
author="Matthias Kestenholz",
author_email="mk@feinheit.ch",
url="http://github.com/matthiask/django-privacy-killer/",
license="BSD License",
platforms=["OS Independent"],
packages=find_packages(exclude=["tests"]),
include_package_data=True,
classifiers=[
'Environment :: Web Environment',
'Framework :: Django',
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 3',
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
'Topic :: Software Development',
'Topic :: Software Development :: Libraries :: Application Frameworks',
"Environment :: Web Environment",
"Framework :: Django",
"Intended Audience :: Developers",
"License :: OSI Approved :: BSD License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Topic :: Internet :: WWW/HTTP :: Dynamic Content",
"Topic :: Software Development",
"Topic :: Software Development :: Libraries :: Application Frameworks",
],
zip_safe=False,
)
40 changes: 15 additions & 25 deletions tests/testapp/settings.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,28 @@
from __future__ import absolute_import, unicode_literals

import os


BASE_DIR = os.path.dirname(os.path.dirname(__file__))

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory:',
}
}
DATABASES = {"default": {"ENGINE": "django.db.backends.sqlite3", "NAME": ":memory:"}}

INSTALLED_APPS = [
'testapp',
'privacy_killer',
]
INSTALLED_APPS = ["testapp", "privacy_killer"]

BASEDIR = os.path.dirname(__file__)
SECRET_KEY = 'supersikret'
SECRET_KEY = "supersikret"
# ROOT_URLCONF = 'testapp.urls'
ALLOWED_HOSTS = ['*']
ALLOWED_HOSTS = ["*"]
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
]
},
},
}
]
47 changes: 11 additions & 36 deletions tests/testapp/test_privacy_killer.py
Original file line number Diff line number Diff line change
@@ -1,53 +1,28 @@
from __future__ import absolute_import, unicode_literals

from django.test import TestCase
from django.test.utils import override_settings

from privacy_killer.templatetags.privacy_killer import (
privacy_killer_body, privacy_killer_head,
privacy_killer_body,
privacy_killer_head,
)


@override_settings(
PRIVACY_KILLER_IDS=[],
)
@override_settings(PRIVACY_KILLER_IDS=[])
class NotUsed(TestCase):
def test_tag(self):
self.assertEqual(
privacy_killer_head(),
'',
)
self.assertEqual(
privacy_killer_body(),
'',
)
self.assertEqual(privacy_killer_head(), "")
self.assertEqual(privacy_killer_body(), "")


@override_settings(
PRIVACY_KILLER_IDS=['GTM-bla'],
)
@override_settings(PRIVACY_KILLER_IDS=["GTM-bla"])
class GTM(TestCase):
def test_tag(self):
self.assertIn(
'<!-- Google Tag Manager -->\n<script>',
privacy_killer_head(),
)
self.assertIn(
'<!-- Google Tag Manager (noscript) -->',
privacy_killer_body(),
)
self.assertIn("<!-- Google Tag Manager -->\n<script>", privacy_killer_head())
self.assertIn("<!-- Google Tag Manager (noscript) -->", privacy_killer_body())


@override_settings(
PRIVACY_KILLER_IDS=['UA-bla'],
)
@override_settings(PRIVACY_KILLER_IDS=["UA-bla"])
class Analytics(TestCase):
def test_tag(self):
self.assertIn(
'<!-- Google Analytics -->\n<script>',
privacy_killer_head(),
)
self.assertEqual(
privacy_killer_body(),
'',
)
self.assertIn("<!-- Google Analytics -->\n<script>", privacy_killer_head())
self.assertEqual(privacy_killer_body(), "")
4 changes: 3 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ basepython = python3

[testenv:style]
deps =
black
flake8
isort
changedir = {toxinidir}
commands =
isort --recursive privacy_killer tests
black setup.py privacy_killer tests
flake8 .
isort --recursive --check-only --diff privacy_killer tests
skip_install = true

[testenv:docs]
Expand Down

0 comments on commit cb0abd4

Please sign in to comment.