From dadb8f1ff65ba1e609e2cb11b56c0b4cbd03ead4 Mon Sep 17 00:00:00 2001 From: Peter Bittner Date: Sun, 10 Apr 2016 19:42:24 +0200 Subject: [PATCH 1/3] Add tox configuration and integration with setup.py Add Travis CI build server configuration Add badges and Tests section to README Bump version (development) --- .gitignore | 2 ++ .travis.yml | 5 +++++ README.rst | 39 ++++++++++++++++++++++++++++++++++---- setup.cfg | 2 +- setup.py | 49 ++++++++++++++++++++++++++++++++++++++++-------- todo/__init__.py | 6 ++++-- tox.ini | 18 ++++++++++++++++++ 7 files changed, 106 insertions(+), 15 deletions(-) create mode 100644 .travis.yml create mode 100644 tox.ini diff --git a/.gitignore b/.gitignore index 5f1d4d5..9ae827f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ # tools, IDEs, build folders /.coverage/ +/.eggs/ /.idea/ +/.tox/ /build/ /dist/ /docs/build/ diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..0e6a36b --- /dev/null +++ b/.travis.yml @@ -0,0 +1,5 @@ +language: python +install: + - pip install virtualenv +script: + - python setup.py test diff --git a/README.rst b/README.rst index 4da4741..8e255d8 100644 --- a/README.rst +++ b/README.rst @@ -1,9 +1,11 @@ -=========== -django todo -=========== +============================ +django todo |latest-version| +============================ + +|build-status| |health| |downloads| |license| django-todo is a pluggable multi-user, multi-group task management and -assignment application for Django. It can serve as anything from a personal +assignment application for Django. It can serve as anything from a personal to-do system to a complete, working ticketing system for organizations. Documentation @@ -19,3 +21,32 @@ For documentation, see the django-todo wiki pages: - `Version history `_ + +Tests +===== + +Serious tests are missing, but we're checking PEP8 conformity of our syntax on +both Python 2 and 3 using ``tox``. You can run the tests locally via:: + + $ python setup.py test + +No prerequisites are required, all test dependencies will be installed +automatically by ``tox`` in virtual environments created on the fly. +Unfortunately, you'll have to install ``virtualenv`` for this to work, though. + + +.. |latest-version| image:: https://img.shields.io/pypi/v/django-todo.svg + :alt: Latest version on PyPI + :target: https://pypi.python.org/pypi/django-todo +.. |build-status| image:: https://travis-ci.org/shacker/django-todo.svg + :alt: Build status + :target: https://travis-ci.org/shacker/django-todo +.. |health| image:: https://landscape.io/github/shacker/django-todo/master/landscape.svg?style=flat + :target: https://landscape.io/github/shacker/django-todo/master + :alt: Code health +.. |downloads| image:: https://img.shields.io/pypi/dm/django-todo.svg + :alt: Monthly downloads from PyPI + :target: https://pypi.python.org/pypi/django-todo +.. |license| image:: https://img.shields.io/pypi/l/django-todo.svg + :alt: Software license + :target: https://github.com/shacker/django-todo/blob/master/LICENSE diff --git a/setup.cfg b/setup.cfg index 789b9c3..ed39ce3 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,4 +1,4 @@ [flake8] max-line-length = 120 max-complexity = 10 -exclude = build,dist,docs/conf.py,todo/migrations,*.egg-info +exclude = build,dist,docs/conf.py,*/migrations,*.egg-info diff --git a/setup.py b/setup.py index dcdd7bd..4bf0074 100755 --- a/setup.py +++ b/setup.py @@ -1,26 +1,59 @@ #!/usr/bin/env python from setuptools import setup, find_packages -import todo +from setuptools.command.test import test as TestCommand +import shlex +import sys + +import todo as package + + +class Tox(TestCommand): + user_options = [('tox-args=', 'a', "Arguments to pass to tox")] + + def initialize_options(self): + TestCommand.initialize_options(self) + self.tox_args = None + + def finalize_options(self): + TestCommand.finalize_options(self) + self.test_args = [] + self.test_suite = True + + def run_tests(self): + import tox + args = self.tox_args + if args: + args = shlex.split(self.tox_args) + errno = tox.cmdline(args=args) + sys.exit(errno) setup( name='django-todo', - version=todo.__version__, - description='A multi-user, multi-group task management and assignment system for Django.', - author=todo.__author__, - author_email=todo.__email__, - url=todo.__url__, - license=todo.__license__, + version=package.__version__, + description=package.__doc__.strip(), + author=package.__author__, + author_email=package.__email__, + url=package.__url__, + license=package.__license__, packages=find_packages(), classifiers=[ 'Development Status :: 4 - Beta', 'Environment :: Web Environment', + 'Framework :: Django', 'Intended Audience :: Developers', 'License :: OSI Approved :: BSD License', 'Operating System :: OS Independent', 'Programming Language :: Python', - 'Framework :: Django', + 'Programming Language :: Python :: 2', + 'Programming Language :: Python :: 3', + 'Topic :: Office/Business :: Groupware', + 'Topic :: Software Development :: Bug Tracking', ], include_package_data=True, zip_safe=False, + tests_require=['tox'], + cmdclass={ + 'test': Tox, + }, ) diff --git a/todo/__init__.py b/todo/__init__.py index abfd735..e579e68 100644 --- a/todo/__init__.py +++ b/todo/__init__.py @@ -1,5 +1,7 @@ -"""django todo""" -__version__ = '1.5' +""" +A multi-user, multi-group task management and assignment system for Django. +""" +__version__ = '1.6.dev1' __author__ = 'Scot Hacker' __email__ = 'shacker@birdhouse.org' diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..9e7eeb5 --- /dev/null +++ b/tox.ini @@ -0,0 +1,18 @@ +[tox] +envlist = + flake8py{2,3} + +[testenv] +# deps = pytest +commands = + # py.test + +[testenv:flake8py2] +basepython = python2.7 +deps = flake8 +commands = flake8 . + +[testenv:flake8py3] +basepython = python3.4 +deps = flake8 +commands = flake8 . From a0b92e38c839edc5227c963a8f7af2145e9a2e28 Mon Sep 17 00:00:00 2001 From: Peter Bittner Date: Sun, 10 Apr 2016 20:05:49 +0200 Subject: [PATCH 2/3] Fix flake8 complaints Move flake8 configuration into tox config file --- setup.cfg | 4 ---- todo/settings.py | 1 - todo/views.py | 8 ++++---- tox.ini | 6 ++++++ 4 files changed, 10 insertions(+), 9 deletions(-) delete mode 100644 setup.cfg diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index ed39ce3..0000000 --- a/setup.cfg +++ /dev/null @@ -1,4 +0,0 @@ -[flake8] -max-line-length = 120 -max-complexity = 10 -exclude = build,dist,docs/conf.py,*/migrations,*.egg-info diff --git a/todo/settings.py b/todo/settings.py index 3c9099e..e9231b5 100644 --- a/todo/settings.py +++ b/todo/settings.py @@ -1,5 +1,4 @@ from django.conf import settings -from django.contrib.auth.models import User STAFF_ONLY = getattr(settings, 'TODO_STAFF_ONLY', False) diff --git a/todo/views.py b/todo/views.py index 4624735..27f83a3 100644 --- a/todo/views.py +++ b/todo/views.py @@ -389,7 +389,7 @@ def search(request): query_string = None found_items = None - return render(request, - 'todo/search_results.html', - {'query_string': query_string, 'found_items': found_items}, - context_instance=RequestContext(request)) + return render(request, 'todo/search_results.html', { + 'query_string': query_string, + 'found_items': found_items + }, context_instance=RequestContext(request)) diff --git a/tox.ini b/tox.ini index 9e7eeb5..a0d1671 100644 --- a/tox.ini +++ b/tox.ini @@ -16,3 +16,9 @@ commands = flake8 . basepython = python3.4 deps = flake8 commands = flake8 . + +[flake8] +# TODO: reduce max-complexity, ideally to 10 +max-line-length = 120 +max-complexity = 21 +exclude = build,dist,docs/conf.py,*/migrations,*.egg-info From 9413e7b590b010583e36ec5589a8484edada15d2 Mon Sep 17 00:00:00 2001 From: Peter Bittner Date: Sun, 10 Apr 2016 23:40:16 +0200 Subject: [PATCH 3/3] Add long_description and custom clean command (setup.py) --- README.rst | 4 ++++ setup.py | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 54 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index 8e255d8..04a6f49 100644 --- a/README.rst +++ b/README.rst @@ -34,6 +34,10 @@ No prerequisites are required, all test dependencies will be installed automatically by ``tox`` in virtual environments created on the fly. Unfortunately, you'll have to install ``virtualenv`` for this to work, though. +To remove all build files and folders including Python byte code you can run:: + + $ python setup.py clean + .. |latest-version| image:: https://img.shields.io/pypi/v/django-todo.svg :alt: Latest version on PyPI diff --git a/setup.py b/setup.py index 4bf0074..58e305c 100755 --- a/setup.py +++ b/setup.py @@ -1,9 +1,13 @@ #!/usr/bin/env python +from glob import glob +from os import remove +from os.path import abspath, dirname, join from setuptools import setup, find_packages from setuptools.command.test import test as TestCommand -import shlex -import sys +from shlex import split +from shutil import rmtree +from sys import exit import todo as package @@ -24,14 +28,55 @@ class Tox(TestCommand): import tox args = self.tox_args if args: - args = shlex.split(self.tox_args) + args = split(self.tox_args) errno = tox.cmdline(args=args) - sys.exit(errno) + exit(errno) + + +class Clean(TestCommand): + def run(self): + delete_in_root = [ + 'build', + 'dist', + '.eggs', + '*.egg-info', + '.tox', + ] + delete_everywhere = [ + '__pycache__', + '*.pyc', + ] + for candidate in delete_in_root: + rmtree_glob(candidate) + for visible_dir in glob('[A-Za-z0-9]*'): + for candidate in delete_everywhere: + rmtree_glob(join(visible_dir, candidate)) + rmtree_glob(join(visible_dir, '*', candidate)) + rmtree_glob(join(visible_dir, '*', '*', candidate)) + + +def rmtree_glob(file_glob): + for fobj in glob(file_glob): + try: + rmtree(fobj) + print('%s/ removed ...' % fobj) + except OSError: + try: + remove(fobj) + print('%s removed ...' % fobj) + except OSError: + pass + + +def read_file(*pathname): + with open(join(dirname(abspath(__file__)), *pathname)) as f: + return f.read() setup( name='django-todo', version=package.__version__, description=package.__doc__.strip(), + long_description=read_file('README.rst'), author=package.__author__, author_email=package.__email__, url=package.__url__, @@ -54,6 +99,7 @@ setup( zip_safe=False, tests_require=['tox'], cmdclass={ + 'clean': Clean, 'test': Tox, }, )