From 2dbae9cfcdc3f3797825a0cf8ec1948d8c3c3759 Mon Sep 17 00:00:00 2001 From: Angelo Dini Date: Fri, 24 May 2019 15:59:19 +0200 Subject: [PATCH] General cleanup (#45) * adapted test structure * core file adaptions * further adaptions * running isort * fix tests * split envs --- .coveragerc | 19 ++- .editorconfig | 31 ++++ .gitignore | 27 ++- .travis.yml | 58 ++++--- CHANGELOG.rst | 156 ++++++++++++++++++ LICENSE => LICENSE.txt | 0 MANIFEST.in | 3 + README.rst | 72 ++++++-- classytags/__init__.py | 1 + classytags/arguments.py | 15 +- classytags/core.py | 4 +- classytags/exceptions.py | 2 + classytags/helpers.py | 1 + classytags/parser.py | 9 +- classytags/test/__init__.py | 0 classytags/test/project/__init__.py | 0 classytags/utils.py | 1 + classytags/values.py | 1 + docs/changes.rst | 155 +---------------- docs/conf.py | 4 +- setup.cfg | 4 - setup.py | 78 +++++---- tests/__init__.py | 1 + .../test => tests}/context_managers.py | 1 + tests/requirements.txt | 3 + runtests.py => tests/settings.py | 42 ++--- .../project => tests}/templates/basic.html | 0 .../test/project => tests}/templates/css.html | 0 .../project => tests}/templates/css2.html | 0 .../templates/easy_base.html | 0 .../templates/easy_inherit.html | 0 .../test/project => tests}/templates/eat.html | 0 .../templates/errors/failadd.html | 0 .../templates/errors/failbase.html | 0 .../templates/errors/failbase2.html | 0 .../templates/errors/failinc.html | 0 .../templates/errors/failrender.html | 0 .../templates/inclusion.html | 0 .../templates/inherit/base.html | 0 .../templates/inherit/baseinc.html | 0 .../templates/inherit/extend.html | 0 .../templates/inherit/extinc.html | 0 .../templates/inherit/super_blocks.html | 0 .../templates/named_end.html | 0 .../templates/namespaces.html | 0 .../templates/spaceless.html | 0 .../project => tests}/templates/test.html | 0 .../templates/variables.html | 0 .../templates/with_data.html | 0 .../test/project => tests}/templates/yui.html | 0 classytags/tests.py => tests/test_core.py | 25 ++- tox.ini | 57 +++++++ 52 files changed, 487 insertions(+), 283 deletions(-) create mode 100644 .editorconfig create mode 100644 CHANGELOG.rst rename LICENSE => LICENSE.txt (100%) create mode 100644 MANIFEST.in delete mode 100644 classytags/test/__init__.py delete mode 100644 classytags/test/project/__init__.py delete mode 100644 setup.cfg create mode 100644 tests/__init__.py rename {classytags/test => tests}/context_managers.py (99%) create mode 100644 tests/requirements.txt rename runtests.py => tests/settings.py (57%) rename {classytags/test/project => tests}/templates/basic.html (100%) rename {classytags/test/project => tests}/templates/css.html (100%) rename {classytags/test/project => tests}/templates/css2.html (100%) rename {classytags/test/project => tests}/templates/easy_base.html (100%) rename {classytags/test/project => tests}/templates/easy_inherit.html (100%) rename {classytags/test/project => tests}/templates/eat.html (100%) rename {classytags/test/project => tests}/templates/errors/failadd.html (100%) rename {classytags/test/project => tests}/templates/errors/failbase.html (100%) rename {classytags/test/project => tests}/templates/errors/failbase2.html (100%) rename {classytags/test/project => tests}/templates/errors/failinc.html (100%) rename {classytags/test/project => tests}/templates/errors/failrender.html (100%) rename {classytags/test/project => tests}/templates/inclusion.html (100%) rename {classytags/test/project => tests}/templates/inherit/base.html (100%) rename {classytags/test/project => tests}/templates/inherit/baseinc.html (100%) rename {classytags/test/project => tests}/templates/inherit/extend.html (100%) rename {classytags/test/project => tests}/templates/inherit/extinc.html (100%) rename {classytags/test/project => tests}/templates/inherit/super_blocks.html (100%) rename {classytags/test/project => tests}/templates/named_end.html (100%) rename {classytags/test/project => tests}/templates/namespaces.html (100%) rename {classytags/test/project => tests}/templates/spaceless.html (100%) rename {classytags/test/project => tests}/templates/test.html (100%) rename {classytags/test/project => tests}/templates/variables.html (100%) rename {classytags/test/project => tests}/templates/with_data.html (100%) rename {classytags/test/project => tests}/templates/yui.html (100%) rename classytags/tests.py => tests/test_core.py (99%) create mode 100644 tox.ini diff --git a/.coveragerc b/.coveragerc index 0bd6bcd..eabe903 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,5 +1,18 @@ [run] -source=classytags -branch=True +branch = True +source = classytags +omit = + migrations/* + tests/* + [report] -show_missing=True +exclude_lines = + pragma: no cover + def __repr__ + if self.debug: + if settings.DEBUG + raise AssertionError + raise NotImplementedError + if 0: + if __name__ == .__main__.: +ignore_errors = True diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..adafbd5 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,31 @@ +# editorconfig.org + +root = true + +[*] +indent_style = space +indent_size = 4 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true +max_line_length = 80 + +[*.py] +max_line_length = 120 +quote_type = single + +[*.{scss,js,html}] +max_line_length = 120 +indent_style = space +quote_type = double + +[*.js] +max_line_length = 120 +quote_type = single + +[*.rst] +max_line_length = 80 + +[*.yml] +indent_size = 2 diff --git a/.gitignore b/.gitignore index 52a826e..d17a434 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,20 @@ -*.pyc -dist -.* +*.py[cod] +*$py.class *.egg-info -*.egg -*.xml -htmlcov -/*env*/ -/build/ +*.log +*.pot +.DS_Store +.coverage/ +.eggs/ +.idea/ +.project/ +.pydevproject/ +.vscode/ +.settings/ +.tox/ +__pycache__/ +build/ +dist/ +env/ + +local.sqlite diff --git a/.travis.yml b/.travis.yml index 0db588a..2861809 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,43 @@ language: python -python: - - 2.7 - - 3.4 - - 3.5 - - 3.6 -env: - - DJANGO='django>=1.11,<2.0' - - DJANGO='django>=2.0,<2.1' - - DJANGO='django>=2.1,<2.2' + +dist: xenial sudo: false + +matrix: + include: + - python: 3.5 + env: TOX_ENV='flake8' + - python: 3.5 + env: TOX_ENV='isort' + # Django 1.11 + - python: 2.7 + env: DJANGO='dj111' + - python: 3.4 + env: DJANGO='dj111' + - python: 3.5 + env: DJANGO='dj111' + - python: 3.6 + env: DJANGO='dj111' + # Django 2.1 + - python: 3.6 + env: DJANGO='dj21' + # Django 2.2 + - python: 3.6 + env: DJANGO='dj22' + - python: 3.7 + env: DJANGO='dj22' + install: - - pip install $DJANGO + - pip install coverage isort tox pep8 + - "if [[ $TRAVIS_PYTHON_VERSION == '2.7' ]]; then export PY_VER=py27; fi" + - "if [[ $TRAVIS_PYTHON_VERSION == '3.4' ]]; then export PY_VER=py34; fi" + - "if [[ $TRAVIS_PYTHON_VERSION == '3.5' ]]; then export PY_VER=py35; fi" + - "if [[ $TRAVIS_PYTHON_VERSION == '3.6' ]]; then export PY_VER=py36; fi" + - "if [[ $TRAVIS_PYTHON_VERSION == '3.7' ]]; then export PY_VER=py37; fi" + - "if [[ ${DJANGO}z != 'z' ]]; then export TOX_ENV=$PY_VER; fi" + script: - - python runtests.py -matrix: - exclude: - - python: 2.7 - env: DJANGO='django>=2.0,<2.1' - - python: 2.7 - env: DJANGO='django>=2.1,<2.2' - - python: 3.4 - env: DJANGO='django>=2.1,<2.2' + - tox -e $TOX_ENV + +after_success: + - bash <(curl -s https://codecov.io/bash) diff --git a/CHANGELOG.rst b/CHANGELOG.rst new file mode 100644 index 0000000..3e02e8b --- /dev/null +++ b/CHANGELOG.rst @@ -0,0 +1,156 @@ +========= +Changelog +========= + + +1.0.0 (unreleased) +================== + +* Extended test matrix +* Added isort and adapted imports +* Adapted code base to align with other supported addons +* Adapted ``README.rst`` instructions + + +0.9.0 (2019-05-16) +================== + +* Added testing for Django 1.11, 2.0, and 2.1; and dropped testing for older + versions. +* Added support for Python 3.6 + + +0.8.0 (2016-06-28) +================== + +* Removed Python 2.6 support. Supported versions are now 2.7, 3.3, 3.4 and 3.5. +* Added support for Django 1.10. + + +0.7.2 (2016-03-01) +================== + +* Fixed regression introduced in 0.7.1 breaking Django 1.9 and higher. + + +0.7.1 (2016-01-22) +================== + +* Prepare support for Django 1.10. Please note that Django 1.10 is **not** + supported by this release, as Django 1.10 is not released yet. + + +0.7.0 (2015-12-06) +================== + +* Added support for Django 1.9 +* Added support for Python 3.5 +* Added a nice ``__repr__`` to :class:`classytags.core.Options` +* Added ability to combine :class:`classytags.core.Options` instances using the + add operator. + + +0.6.2 (2015-06-11) +================== + +* Fixed Django 1.8 support + + +0.6.1 (2015-01-30) +================== + +* Packaging fixes + + +0.6.0 (2015-01-30) +================== + +* Added support for Django 1.8 +* Dropped support for Django 1.2 + + +0.5.2 (2014-12-11) +================== + +* Added :attr:`classytags.helpers.InclusionTag.push_context`. + + +0.5.1 (2014-04-07) +================== + +* Fixed :attr:`classytags.helpers.InclusionTag.template` being required. + + +0.5.0 (2014-02-28) +================== + +* Added Python 3 support +* Added :ref:`advanced-block-definition`. +* Added :doc:`arguments` documentation. + + +0.3.3 (2011-03-03) +================== + +* Fixed issues with :class:`classytags.helpers.InclusionTag`. + + +0.3.2 (2011-03-02) +================== + +* Fixed issue in :class:`classytags.arguments.MultiKeywordArgument` and + :class:`classytags.arguments.KeywordArgument` and their behavior when given + a default value. + + +0.3.1 (2011-03-02) +================== + +* Fixed :class:`classytags.arguments.MultiKeywordArgument` and + :class:`classytags.arguments.KeywordArgument` not returning sane defaults. +* Added ``child_nodelist`` attribute on tag instances as well as setting the + child nodelists as attributes onto the instance during initialization for + compatiblity with applications that require these attributes to be set. + + +0.3.0 (2010-12-16) +================== + +* Added :class:`classytags.arguments.KeywordArgument` +* Added :class:`classytags.arguments.MultiKeywordArgument` +* Added :class:`classytags.arguments.ChoiceArgument` +* Added ability to override the parser class in the initialization of the + :class:`classytags.core.Options` class, to make the usage of custom parsers + easier. +* Added :class:`classytags.values.DictValue` +* Added :class:`classytags.values.ChoiceValue` + + +0.2.2 (2010-09-12) +================== + +* Fixed issue in :class:`classytags.helpers.AsTag` when trying to extract the + variable to store the value in, but no argument is given. +* Fixed :class:`classytags.helpers.InclusionTag` not validating the ``template`` + attribute on initialization. + + +0.2.1 (2010-09-11) +================== + +* Fixed version in documentation not matching release version. + + +0.2.0 (2010-09-11) +================== + +* Added ability to have typed arguments. +* Added :class:`classytags.arguments.IntegerArgument` +* Added more graceful failing in non-debug mode by using warnings instead of + exceptions. + + +0.1.3 (2010-08-24) +================== + +* Added :class:`classytags.helpers.InclusionTag` diff --git a/LICENSE b/LICENSE.txt similarity index 100% rename from LICENSE rename to LICENSE.txt diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..1375b3e --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,3 @@ +include LICENSE.txt +include README.rst +recursive-exclude * *.py[co] diff --git a/README.rst b/README.rst index f2e9c01..01b2f24 100644 --- a/README.rst +++ b/README.rst @@ -1,24 +1,14 @@ + ================== -django-classy-tags +Django Classy Tags ================== -Please refer to the documentation in the docs/ directory for help. For a HTML -rendered version of it please see `here `_. - -.. image:: https://travis-ci.org/ojii/django-classy-tags.svg?branch=master - :target: https://travis-ci.org/ojii/django-classy-tags - -****************** -About this project -****************** +|pypi| |build| |coverage| The goal of this project is to create a new way of writing Django template tags which is fully compatible with the current Django templating infrastructure. This new way should be easy, clean and require as little boilerplate code as -possible while still staying as powerful as possible. - -Features --------- +possible while still staying as powerful as possible. Some features: * Class based template tags. * Template tag argument parser. @@ -27,9 +17,33 @@ Features * Extensible! -***************** -For the impatient -***************** +Contributing +============ + +This is a an open-source project. We'll be delighted to receive your +feedback in the form of issues and pull requests. Before submitting your +pull request, please review our `contribution guidelines +`_. + +We're grateful to all contributors who have helped create and maintain this package. +Contributors are listed at the `contributors `_ +section. + + +Documentation +============= + +See ``REQUIREMENTS`` in the `setup.py `_ +file for additional dependencies: + +|python| |django| + +Please refer to the documentation in the docs/ directory for more information or visit our +`online documentation `_. + + +Example +------- This is how a tag looks like using django-classy-tags: @@ -62,3 +76,27 @@ That's your standard *hello world* example. Which can be used like this: template variable ``myvar``. * ``{% hello "my friend" as othervar %}``: Outputs nothing but stores ``hello my friend`` into the template variable ``othervar``. + + +Running Tests +------------- + +You can run tests by executing:: + + virtualenv env + source env/bin/activate + pip install -r tests/requirements.txt + python setup.py test + + +.. |pypi| image:: https://badge.fury.io/py/django-classy-tags.svg + :target: http://badge.fury.io/py/django-classy-tags +.. |build| image:: https://travis-ci.org/divio/django-classy-tags.svg?branch=master + :target: https://travis-ci.org/divio/django-classy-tags +.. |coverage| image:: https://codecov.io/gh/divio/django-classy-tags/branch/master/graph/badge.svg + :target: https://codecov.io/gh/divio/django-classy-tags + +.. |python| image:: https://img.shields.io/badge/python-2.7%20%7C%203.4+-blue.svg + :target: https://pypi.org/project/django-classy-tags/ +.. |django| image:: https://img.shields.io/badge/django-1.11%20%7C%202.1%20%7C%202.2-blue.svg + :target: https://www.djangoproject.com/ diff --git a/classytags/__init__.py b/classytags/__init__.py index e4e49b3..3d9a574 100644 --- a/classytags/__init__.py +++ b/classytags/__init__.py @@ -1 +1,2 @@ +# -*- coding: utf-8 -*- __version__ = '0.9.0' diff --git a/classytags/arguments.py b/classytags/arguments.py index 1d5617a..cfd6b63 100644 --- a/classytags/arguments.py +++ b/classytags/arguments.py @@ -1,16 +1,13 @@ +# -*- coding: utf-8 -*- from django import template from django.core.exceptions import ImproperlyConfigured from classytags.exceptions import InvalidFlag -from classytags.utils import NULL -from classytags.utils import TemplateConstant -from classytags.utils import mixin -from classytags.values import ChoiceValue -from classytags.values import DictValue -from classytags.values import IntegerValue -from classytags.values import ListValue -from classytags.values import StrictStringValue -from classytags.values import StringValue +from classytags.utils import NULL, TemplateConstant, mixin +from classytags.values import ( + ChoiceValue, DictValue, IntegerValue, ListValue, StrictStringValue, + StringValue, +) class Argument(object): diff --git a/classytags/core.py b/classytags/core.py index de0ffba..e1f1838 100644 --- a/classytags/core.py +++ b/classytags/core.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- from operator import attrgetter from django.template import Node @@ -5,8 +6,7 @@ from classytags.blocks import BlockDefinition from classytags.parser import Parser -from classytags.utils import StructuredOptions -from classytags.utils import get_default_name +from classytags.utils import StructuredOptions, get_default_name class Options(object): diff --git a/classytags/exceptions.py b/classytags/exceptions.py index 6c632b3..ba1fdae 100644 --- a/classytags/exceptions.py +++ b/classytags/exceptions.py @@ -1,5 +1,7 @@ +# -*- coding: utf-8 -*- from django.template import TemplateSyntaxError + __all__ = ['ArgumentRequiredError', 'InvalidFlag', 'BreakpointExpected', 'TooManyArguments'] diff --git a/classytags/helpers.py b/classytags/helpers.py index 59e2a00..640133f 100644 --- a/classytags/helpers.py +++ b/classytags/helpers.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- from django.core.exceptions import ImproperlyConfigured from django.template.loader import render_to_string diff --git a/classytags/parser.py b/classytags/parser.py index fa59393..ce08865 100644 --- a/classytags/parser.py +++ b/classytags/parser.py @@ -1,11 +1,12 @@ +# -*- coding: utf-8 -*- from copy import deepcopy from django import template -from classytags.exceptions import ArgumentRequiredError -from classytags.exceptions import BreakpointExpected -from classytags.exceptions import TooManyArguments -from classytags.exceptions import TrailingBreakpoint +from classytags.exceptions import ( + ArgumentRequiredError, BreakpointExpected, TooManyArguments, + TrailingBreakpoint, +) class Parser(object): diff --git a/classytags/test/__init__.py b/classytags/test/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/classytags/test/project/__init__.py b/classytags/test/project/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/classytags/utils.py b/classytags/utils.py index 912311a..7d570e0 100644 --- a/classytags/utils.py +++ b/classytags/utils.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- import re from copy import copy diff --git a/classytags/values.py b/classytags/values.py index 842ee31..118cb49 100644 --- a/classytags/values.py +++ b/classytags/values.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- import warnings from django import template diff --git a/docs/changes.rst b/docs/changes.rst index bdb1407..02a73e8 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -2,157 +2,4 @@ Changelog ######### -***** -0.9.0 -***** - -* Added testing for Django 1.11, 2.0, and 2.1; and dropped testing for older - versions. -* Added support for Python 3.6 - - -***** -0.8.0 -***** - -* Removed Python 2.6 support. Supported versions are now 2.7, 3.3, 3.4 and 3.5. -* Added support for Django 1.10. - - -***** -0.7.2 -***** - -* Fixed regression introduced in 0.7.1 breaking Django 1.9 and higher. - - -***** -0.7.1 -***** - -* Prepare support for Django 1.10. Please note that Django 1.10 is **not** - supported by this release, as Django 1.10 is not released yet. - - -***** -0.7.0 -***** - -* Added support for Django 1.9 -* Added support for Python 3.5 -* Added a nice ``__repr__`` to :class:`classytags.core.Options` -* Added ability to combine :class:`classytags.core.Options` instances using the - add operator. - - -***** -0.6.2 -***** - -* Fixed Django 1.8 support - - -***** -0.6.1 -***** - -* Packaging fixes - - -***** -0.6.0 -***** - -* Added support for Django 1.8 -* Dropped support for Django 1.2 - - -***** -0.5.2 -***** - -* Added :attr:`classytags.helpers.InclusionTag.push_context`. - - -***** -0.5.1 -***** - -* Fixed :attr:`classytags.helpers.InclusionTag.template` being required. - - - -***** -0.5.0 -***** - -* Added Python 3 support -* Added :ref:`advanced-block-definition`. -* Added :doc:`arguments` documentation. - -***** -0.3.3 -***** - -* Fixed issues with :class:`classytags.helpers.InclusionTag``. - -***** -0.3.2 -***** - -* Fixed issue in :class:`classytags.arguments.MultiKeywordArgument` and - :class:`classytags.arguments.KeywordArgument` and their behavior when given - a default value. - -***** -0.3.1 -***** - -* Fixed :class:`classytags.arguments.MultiKeywordArgument` and - :class:`classytags.arguments.KeywordArgument` not returning sane defaults. -* Added ``child_nodelist`` attribute on tag instances as well as setting the - child nodelists as attributes onto the instance during initialization for - compatiblity with applications that require these attributes to be set. - -***** -0.3.0 -***** - -* Added :class:`classytags.arguments.KeywordArgument` -* Added :class:`classytags.arguments.MultiKeywordArgument` -* Added :class:`classytags.arguments.ChoiceArgument` -* Added ability to override the parser class in the initialization of the - :class:`classytags.core.Options` class, to make the usage of custom parsers - easier. -* Added :class:`classytags.values.DictValue` -* Added :class:`classytags.values.ChoiceValue` - -***** -0.2.2 -***** - -* Fixed issue in :class:`classytags.helpers.AsTag` when trying to extract the - variable to store the value in, but no argument is given. -* Fixed :class:`classytags.helpers.InclusionTag` not validating the ``template`` - attribute on initialization. - -***** -0.2.1 -***** - -* Fixed version in documentation not matching release version. - -***** -0.2.0 -***** - -* Added ability to have typed arguments. -* Added :class:`classytags.arguments.IntegerArgument` -* Added more graceful failing in non-debug mode by using warnings instead of - exceptions. - -***** -0.1.3 -***** - -* Added :class:`classytags.helpers.InclusionTag` +See `CHANGELOG.rst `_ for a full list. diff --git a/docs/conf.py b/docs/conf.py index 37fcd78..6299494 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -11,7 +11,9 @@ # All configuration values have a default; values that are commented out # serve to show the default. -import sys, os +import os +import sys + # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 50a56dc..0000000 --- a/setup.cfg +++ /dev/null @@ -1,4 +0,0 @@ -[bdist_wheel] -universal=1 -[flake8] -ignore = W293 diff --git a/setup.py b/setup.py index fe6c26e..7694b9e 100644 --- a/setup.py +++ b/setup.py @@ -1,35 +1,53 @@ -from setuptools import setup, find_packages +#!/usr/bin/env python +# -*- coding: utf-8 -*- +from setuptools import find_packages, setup + +from classytags import __version__ + + +REQUIREMENTS = [ + 'django>=1.11', +] + + +CLASSIFIERS = [ + 'Development Status :: 5 - Production/Stable', + 'Environment :: Web Environment', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: BSD License', + 'Operating System :: OS Independent', + 'Programming Language :: Python', + 'Programming Language :: Python :: 2', + 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', + 'Framework :: Django', + 'Framework :: Django :: 1.11', + 'Framework :: Django :: 2.1', + 'Framework :: Django :: 2.2', + 'Topic :: Internet :: WWW/HTTP', + 'Topic :: Internet :: WWW/HTTP :: Dynamic Content', + 'Topic :: Software Development', + 'Topic :: Software Development :: Libraries', +] -version = __import__('classytags').__version__ setup( - name = 'django-classy-tags', - version = version, - description = 'Class based template tags for Django', - author = 'Jonas Obrist', - author_email = 'ojiidotch@gmail.com', - url = 'http://github.com/ojii/django-classy-tags', - packages = find_packages(), + name='django-classy-tags', + version=__version__, + author='Jonas Obrist', + author_email='ojiidotch@gmail.com', + url='http://github.com/ojii/django-classy-tags', + license='BSD', + description='Class based template tags for Django', + long_description=open('README.rst').read(), + packages=find_packages(exclude=['tests']), + include_package_data=True, zip_safe=False, - install_requires=['Django>=1.11'], - test_suite='runtests.main', - classifiers=[ - "Development Status :: 5 - Production/Stable", - "License :: OSI Approved :: BSD License", - "Framework :: Django", - 'Framework :: Django :: 1.11', - 'Framework :: Django :: 2.0', - 'Framework :: Django :: 2.1', - "Intended Audience :: Developers", - "Natural Language :: English", - "Operating System :: OS Independent", - "Programming Language :: Python :: 2.7", - "Programming Language :: Python :: 3.4", - "Programming Language :: Python :: 3.5", - "Programming Language :: Python :: 3.6", - "Topic :: Utilities", - "Topic :: Internet :: WWW/HTTP :: Dynamic Content", - "Topic :: Software Development :: Libraries :: Python Modules", - "Topic :: Text Processing :: Markup :: HTML", - ], + install_requires=REQUIREMENTS, + classifiers=CLASSIFIERS, + test_suite='tests.settings.run', ) diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..40a96af --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1 @@ +# -*- coding: utf-8 -*- diff --git a/classytags/test/context_managers.py b/tests/context_managers.py similarity index 99% rename from classytags/test/context_managers.py rename to tests/context_managers.py index e3a5b0a..8f7ac7f 100644 --- a/classytags/test/context_managers.py +++ b/tests/context_managers.py @@ -3,6 +3,7 @@ from django.conf import settings from django.template.engine import Engine + builtins = Engine.get_default().template_builtins diff --git a/tests/requirements.txt b/tests/requirements.txt new file mode 100644 index 0000000..045a21f --- /dev/null +++ b/tests/requirements.txt @@ -0,0 +1,3 @@ +# other requirements +tox +coverage diff --git a/runtests.py b/tests/settings.py similarity index 57% rename from runtests.py rename to tests/settings.py index 3fccd80..2d162ed 100644 --- a/runtests.py +++ b/tests/settings.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- -import warnings import os import sys + urlpatterns = [] DATABASES = { @@ -15,45 +15,49 @@ INSTALLED_APPS = [ 'classytags', - 'classytags.test.project', + 'tests', ] -TEST_RUNNER = 'django.test.runner.DiscoverRunner' - -ROOT_URLCONF = 'runtests' +ROOT_URLCONF = 'tests.settings' TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'APP_DIRS': True, - 'DIRS': os.path.join(os.path.dirname(__file__), 'test_templates'), + 'DIRS': [ + os.path.join(os.path.dirname(__file__), 'templates') + ], 'OPTIONS': { 'debug': True, }, }, ] -def main(): - import django + +def runtests(): + from django import setup from django.conf import settings + from django.test.utils import get_runner settings.configure( - INSTALLED_APPS = INSTALLED_APPS, - ROOT_URLCONF = ROOT_URLCONF, - DATABASES = DATABASES, - TEST_RUNNER = TEST_RUNNER, + INSTALLED_APPS=INSTALLED_APPS, + ROOT_URLCONF=ROOT_URLCONF, + DATABASES=DATABASES, + TEST_RUNNER='django.test.runner.DiscoverRunner', TEMPLATES=TEMPLATES, ) + setup() # Run the test suite, including the extra validation tests. - from django.test.utils import get_runner TestRunner = get_runner(settings) test_runner = TestRunner(verbosity=1, interactive=False, failfast=False) - warnings.simplefilter("ignore") - django.setup() - failures = test_runner.run_tests(['classytags']) + failures = test_runner.run_tests(INSTALLED_APPS) + return failures + + +def run(): + failures = runtests() sys.exit(failures) -if __name__ == "__main__": - main() +if __name__ == '__main__': + run() diff --git a/classytags/test/project/templates/basic.html b/tests/templates/basic.html similarity index 100% rename from classytags/test/project/templates/basic.html rename to tests/templates/basic.html diff --git a/classytags/test/project/templates/css.html b/tests/templates/css.html similarity index 100% rename from classytags/test/project/templates/css.html rename to tests/templates/css.html diff --git a/classytags/test/project/templates/css2.html b/tests/templates/css2.html similarity index 100% rename from classytags/test/project/templates/css2.html rename to tests/templates/css2.html diff --git a/classytags/test/project/templates/easy_base.html b/tests/templates/easy_base.html similarity index 100% rename from classytags/test/project/templates/easy_base.html rename to tests/templates/easy_base.html diff --git a/classytags/test/project/templates/easy_inherit.html b/tests/templates/easy_inherit.html similarity index 100% rename from classytags/test/project/templates/easy_inherit.html rename to tests/templates/easy_inherit.html diff --git a/classytags/test/project/templates/eat.html b/tests/templates/eat.html similarity index 100% rename from classytags/test/project/templates/eat.html rename to tests/templates/eat.html diff --git a/classytags/test/project/templates/errors/failadd.html b/tests/templates/errors/failadd.html similarity index 100% rename from classytags/test/project/templates/errors/failadd.html rename to tests/templates/errors/failadd.html diff --git a/classytags/test/project/templates/errors/failbase.html b/tests/templates/errors/failbase.html similarity index 100% rename from classytags/test/project/templates/errors/failbase.html rename to tests/templates/errors/failbase.html diff --git a/classytags/test/project/templates/errors/failbase2.html b/tests/templates/errors/failbase2.html similarity index 100% rename from classytags/test/project/templates/errors/failbase2.html rename to tests/templates/errors/failbase2.html diff --git a/classytags/test/project/templates/errors/failinc.html b/tests/templates/errors/failinc.html similarity index 100% rename from classytags/test/project/templates/errors/failinc.html rename to tests/templates/errors/failinc.html diff --git a/classytags/test/project/templates/errors/failrender.html b/tests/templates/errors/failrender.html similarity index 100% rename from classytags/test/project/templates/errors/failrender.html rename to tests/templates/errors/failrender.html diff --git a/classytags/test/project/templates/inclusion.html b/tests/templates/inclusion.html similarity index 100% rename from classytags/test/project/templates/inclusion.html rename to tests/templates/inclusion.html diff --git a/classytags/test/project/templates/inherit/base.html b/tests/templates/inherit/base.html similarity index 100% rename from classytags/test/project/templates/inherit/base.html rename to tests/templates/inherit/base.html diff --git a/classytags/test/project/templates/inherit/baseinc.html b/tests/templates/inherit/baseinc.html similarity index 100% rename from classytags/test/project/templates/inherit/baseinc.html rename to tests/templates/inherit/baseinc.html diff --git a/classytags/test/project/templates/inherit/extend.html b/tests/templates/inherit/extend.html similarity index 100% rename from classytags/test/project/templates/inherit/extend.html rename to tests/templates/inherit/extend.html diff --git a/classytags/test/project/templates/inherit/extinc.html b/tests/templates/inherit/extinc.html similarity index 100% rename from classytags/test/project/templates/inherit/extinc.html rename to tests/templates/inherit/extinc.html diff --git a/classytags/test/project/templates/inherit/super_blocks.html b/tests/templates/inherit/super_blocks.html similarity index 100% rename from classytags/test/project/templates/inherit/super_blocks.html rename to tests/templates/inherit/super_blocks.html diff --git a/classytags/test/project/templates/named_end.html b/tests/templates/named_end.html similarity index 100% rename from classytags/test/project/templates/named_end.html rename to tests/templates/named_end.html diff --git a/classytags/test/project/templates/namespaces.html b/tests/templates/namespaces.html similarity index 100% rename from classytags/test/project/templates/namespaces.html rename to tests/templates/namespaces.html diff --git a/classytags/test/project/templates/spaceless.html b/tests/templates/spaceless.html similarity index 100% rename from classytags/test/project/templates/spaceless.html rename to tests/templates/spaceless.html diff --git a/classytags/test/project/templates/test.html b/tests/templates/test.html similarity index 100% rename from classytags/test/project/templates/test.html rename to tests/templates/test.html diff --git a/classytags/test/project/templates/variables.html b/tests/templates/variables.html similarity index 100% rename from classytags/test/project/templates/variables.html rename to tests/templates/variables.html diff --git a/classytags/test/project/templates/with_data.html b/tests/templates/with_data.html similarity index 100% rename from classytags/test/project/templates/with_data.html rename to tests/templates/with_data.html diff --git a/classytags/test/project/templates/yui.html b/tests/templates/yui.html similarity index 100% rename from classytags/test/project/templates/yui.html rename to tests/templates/yui.html diff --git a/classytags/tests.py b/tests/test_core.py similarity index 99% rename from classytags/tests.py rename to tests/test_core.py index d842250..bf047aa 100644 --- a/classytags/tests.py +++ b/tests/test_core.py @@ -1,7 +1,8 @@ +# -*- coding: utf-8 -*- +import operator import os import sys import warnings -import operator from unittest import TestCase from django import template @@ -10,17 +11,13 @@ from django.test import RequestFactory from django.utils import six -from classytags import arguments -from classytags import core -from classytags import exceptions -from classytags import helpers -from classytags import parser -from classytags import utils -from classytags import values -from classytags.blocks import BlockDefinition -from classytags.blocks import VariableBlockName -from classytags.test.context_managers import SettingsOverride -from classytags.test.context_managers import TemplateTags +from tests.context_managers import SettingsOverride, TemplateTags + +from classytags import ( + arguments, core, exceptions, helpers, parser, utils, values, +) +from classytags.blocks import BlockDefinition, VariableBlockName + CLASSY_TAGS_DIR = os.path.abspath(os.path.dirname(__file__)) @@ -37,6 +34,8 @@ class DummyParser(object): @staticmethod def compile_filter(token): return utils.TemplateConstant(token) + + dummy_parser = DummyParser() @@ -63,7 +62,7 @@ def show_warning(message, category, filename, lineno, file=None, if v is not None: try: v.__warningregistry__ = None - except: + except: # noqa # Don't specify a particular exception type to handle in case # some wacky object raises some wacky exception in response to # the setattr attempt. diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..8a44b23 --- /dev/null +++ b/tox.ini @@ -0,0 +1,57 @@ +[tox] +envlist = + flake8 + isort + py{27,34,35,36}-dj{111} + py{35,36,37}-dj{21,22} + +skip_missing_interpreters=True + +[flake8] +max-line-length = 119 +exclude = + *.egg-info, + .eggs, + .git, + .settings, + .tox, + build, + data, + dist, + docs, + *migrations*, + requirements, + tmp + +[isort] +line_length = 79 +skip = manage.py, *migrations*, .tox, .eggs, data +include_trailing_comma = true +multi_line_output = 5 +not_skip = __init__.py +lines_after_imports = 2 +default_section = THIRDPARTY +sections = FUTURE, STDLIB, DJANGO, THIRDPARTY, FIRSTPARTY, LIB, LOCALFOLDER +known_first_party = classytags +known_django = django + +[testenv] +deps = + -r{toxinidir}/tests/requirements.txt + dj111: Django>=1.11,<2.0 + dj21: Django>=2.1,<2.2 + dj22: Django>=2.2,<3.0 +commands = + {envpython} --version + {env:COMMAND:coverage} erase + {env:COMMAND:coverage} run setup.py test + {env:COMMAND:coverage} report + +[testenv:flake8] +deps = flake8 +commands = flake8 + +[testenv:isort] +deps = isort +commands = isort -c -rc -df classytags +skip_install = true