From d587c515f035fd8c326335dea8d025aace47ee85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Bryon?= Date: Mon, 10 Feb 2014 01:27:14 +0100 Subject: [PATCH] Refs #74 - Switched to tox as test-environment manager. Added flake8 to the test suite. Dropped python 2.6 tests. Makefile no longer creates a virtualenv. --- .gitignore | 7 +++ .travis.yml | 13 +++-- CHANGELOG | 4 +- docs/dev.txt => CONTRIBUTING.rst | 27 ++++------ INSTALL | 20 ++----- LICENSE | 2 +- MANIFEST.in | 2 +- Makefile | 85 ++++++++++-------------------- demo/demoproject/lighttpd/views.py | 5 +- demo/setup.py | 1 - django_downloadview/files.py | 1 - django_downloadview/io.py | 2 +- django_downloadview/response.py | 6 +-- django_downloadview/test.py | 2 +- docs/Makefile | 2 +- docs/conf.py | 2 +- docs/contributing.txt | 1 + docs/index.txt | 2 +- docs/optimizations/lighttpd.txt | 4 +- etc/ci-requirements.txt | 10 ---- etc/virtualenv.cfg | 3 -- setup.py | 9 +++- tox.ini | 44 ++++++++++++++++ 23 files changed, 129 insertions(+), 125 deletions(-) rename docs/dev.txt => CONTRIBUTING.rst (82%) create mode 100644 docs/contributing.txt delete mode 100644 etc/ci-requirements.txt delete mode 100644 etc/virtualenv.cfg create mode 100644 tox.ini diff --git a/.gitignore b/.gitignore index 9a43def..07da98d 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,13 @@ *.pyo *.egg-info +# Tox files. +/.tox/ + +# Virtualenv files (created by tox). +/build/ +/dist/ + # Editors' temporary buffers. .*.swp *~ diff --git a/.travis.yml b/.travis.yml index 9d1a631..f447312 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,10 @@ language: python -python: - - "2.7" -install: make configure develop -script: make test +env: + - TOXENV=py27 + - TOXENV=flake8 + - TOXENV=sphinx + - TOXENV=readme +install: + - pip install tox +script: + - tox diff --git a/CHANGELOG b/CHANGELOG index 4f320c6..89f37c9 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -8,7 +8,9 @@ future releases, check `milestones`_ and :doc:`/about/vision`. 1.6 (unreleased) ---------------- -- Nothing changed yet. +- Feature #74: the Makefile in project's repository no longer creates a + virtualenv. Developers setup the environment as they like, i.e. using + virtualenv, virtualenvwrapper or whatever. Tests are run with tox. 1.5 (2013-11-29) diff --git a/docs/dev.txt b/CONTRIBUTING.rst similarity index 82% rename from docs/dev.txt rename to CONTRIBUTING.rst index 5e23e5a..b4a8212 100644 --- a/docs/dev.txt +++ b/CONTRIBUTING.rst @@ -1,9 +1,9 @@ -########################### -Contributing to the project -########################### +############ +Contributing +############ -This document provides guidelines for people who want to contribute to the -project. +This document provides guidelines for people who want to contribute to +`django-downloadview`. ************** @@ -42,13 +42,8 @@ Fork and branch Setup a development environment ******************************* -System requirements: - -* `Python`_ version 2.7, available as ``python`` command - -* `Virtualenv`_ version >= 1.9.1, available as ``virtualenv`` command - -* make and wget to use the provided :file:`Makefile`. +System requirements: `Python`_ version 2.7 and `tox`_ (you may use a +`Virtualenv`_). Execute: @@ -68,8 +63,7 @@ The Makefile A :file:`Makefile` is provided to ease development. Use it to: -* setup the development environment: ``make develop`` -* update it, as an example, after a pull: ``make update`` +* setup a minimal development environment: ``make develop`` * run tests: ``make test`` * build documentation: ``make documentation`` @@ -85,9 +79,7 @@ The :doc:`/demo` is part of the tests. Maintain it along with code and documentation. -********** -References -********** +.. rubric:: Notes & references .. target-notes:: @@ -96,6 +88,7 @@ References .. _`rebase`: http://git-scm.com/book/en/Git-Branching-Rebasing .. _`merge-based rebase`: http://tech.novapost.fr/psycho-rebasing-en.html .. _`Python`: http://python.org +.. _`tox`: http://tox.testrun.org .. _`Virtualenv`: http://virtualenv.org .. _`style guide for Sphinx-based documentations`: http://documentation-style-guide-sphinx.readthedocs.org/ diff --git a/INSTALL b/INSTALL index 76e59f9..03347af 100644 --- a/INSTALL +++ b/INSTALL @@ -4,11 +4,12 @@ Install .. note:: - If you want to install a development environment, please see :doc:`/dev`. + If you want to install a development environment, please see + :doc:`/contributing`. System requirements: -* Python 2.7 +* Python version 2.7 Install the package with your favorite Python installer. As an example, with pip: @@ -22,7 +23,7 @@ the following requirements: .. literalinclude:: /../setup.py :language: python - :lines: 35 + :lines: 39 .. note:: @@ -30,19 +31,6 @@ the following requirements: :py:class:`~django.http.StreamingHttpResponse`. -************************** -Known good set of versions -************************** - -`django-downloadview` has been tested in an environment with the following set -of versions. If something is going wrong with other versions, please report it -in `django-downloadview's bugtracker`_. - -.. literalinclude:: /../etc/buildout.cfg - :language: ini - :lines: 67- - - .. rubric:: Notes & references .. seealso:: diff --git a/LICENSE b/LICENSE index 8a9f051..b0c9234 100644 --- a/LICENSE +++ b/LICENSE @@ -2,7 +2,7 @@ License ####### -Copyright (c) 2012-2013, Benoît Bryon. +Copyright (c) 2012-2014, Benoît Bryon. All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/MANIFEST.in b/MANIFEST.in index c14ef6b..452390b 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,4 +1,4 @@ recursive-include django_downloadview * global-exclude *.pyc .*.swp include *.txt -include AUTHORS CHANGELOG INSTALL LICENSE README VERSION +include AUTHORS CHANGELOG CONTRIBUTING.rst INSTALL LICENSE README.rst VERSION diff --git a/Makefile b/Makefile index 840f5ca..29be069 100644 --- a/Makefile +++ b/Makefile @@ -1,92 +1,65 @@ -# Makefile for development. -# See INSTALL and docs/dev.txt for details. -SHELL = /bin/bash -ROOT_DIR = $(shell pwd) -DATA_DIR = $(ROOT_DIR)/var -VIRTUALENV_DIR = $(ROOT_DIR)/lib/virtualenv -BIN_DIR = $(VIRTUALENV_DIR)/bin -PIP = $(BIN_DIR)/pip -WGET = wget -PYTHON = $(BIN_DIR)/python -PROJECT = $(shell $(PYTHON) -c "import setup; print setup.NAME") -PACKAGE = $(shell $(PYTHON) -c "import setup; print setup.PACKAGES[0]") -NOSE = $(BIN_DIR)/nosetests +# Reference card for usual actions in development environment. +# +# For standard installation of hospital as a library, see INSTALL. +# For details about hospital's development environment, see CONTRIBUTING.rst. -configure: - # Configuration is stored in etc/ folder. Not generated yet. - - -develop: directories pip - - -virtualenv: - if [ ! -d $(VIRTUALENV_DIR)/bin/ ]; then virtualenv --no-site-packages $(VIRTUALENV_DIR); fi - $(PIP) install -r $(ROOT_DIR)/etc/virtualenv.cfg - - -pip: virtualenv - $(PIP) install -r etc/ci-requirements.txt - - -directories: - mkdir -p var/docs - mkdir -p docs/_static - mkdir -p var/test +develop: + pip install tox zest.releaser + pip install -e ./ + pip install -e ./demo/ clean: - find $(ROOT_DIR)/ -name "*.pyc" -delete - find $(ROOT_DIR)/ -name ".noseids" -delete + find . -name "*.pyc" -delete + find . -name ".noseids" -delete distclean: clean - rm -rf $(ROOT_DIR)/*.egg-info - rm -rf $(ROOT_DIR)/demo/*.egg-info + rm -rf *.egg-info + rm -rf demo/*.egg-info maintainer-clean: distclean - rm -rf $(BIN_DIR)/ - rm -rf $(ROOT_DIR)/lib/ + rm -rf bin/ + rm -rf lib/ + rm -rf build/ + rm -rf dist/ + rm -rf .tox/ -test: test-app test-demo test-documentation +test: + tox test-app: - $(BIN_DIR)/demo test --nose-verbosity=2 -c $(ROOT_DIR)/etc/nose/base.cfg -c $(ROOT_DIR)/etc/nose/$(PACKAGE).cfg django_downloadview - mv $(ROOT_DIR)/.coverage $(ROOT_DIR)/var/test/app.coverage + tox -e py27 test-demo: - $(BIN_DIR)/demo test --nose-verbosity=2 - mv $(ROOT_DIR)/.coverage $(ROOT_DIR)/var/test/demo.coverage - - -test-documentation: - $(NOSE) -c $(ROOT_DIR)/etc/nose/base.cfg sphinxcontrib.testbuild.tests + tox -e demo sphinx: - make --directory=docs clean html doctest + tox -e sphinx documentation: sphinx demo: develop - $(BIN_DIR)/demo syncdb --noinput + demo syncdb --noinput # Install fixtures. mkdir -p var/media - cp -r $(ROOT_DIR)/demo/demoproject/fixtures var/media/object - cp -r $(ROOT_DIR)/demo/demoproject/fixtures var/media/object-other - cp -r $(ROOT_DIR)/demo/demoproject/fixtures var/media/nginx - $(BIN_DIR)/demo loaddata demo.json + cp -r demo/demoproject/fixtures var/media/object + cp -r demo/demoproject/fixtures var/media/object-other + cp -r demo/demoproject/fixtures var/media/nginx + demo loaddata demo.json runserver: demo - $(BIN_DIR)/demo runserver + demo runserver release: - $(BIN_DIR)/fullrelease + fullrelease diff --git a/demo/demoproject/lighttpd/views.py b/demo/demoproject/lighttpd/views.py index d9b4e1b..e2eea86 100644 --- a/demo/demoproject/lighttpd/views.py +++ b/demo/demoproject/lighttpd/views.py @@ -8,8 +8,9 @@ from django_downloadview.lighttpd import x_sendfile storage_dir = os.path.join(settings.MEDIA_ROOT, 'lighttpd') -storage = FileSystemStorage(location=storage_dir, - base_url=''.join([settings.MEDIA_URL, 'lighttpd/'])) +storage = FileSystemStorage( + location=storage_dir, + base_url=''.join([settings.MEDIA_URL, 'lighttpd/'])) optimized_by_middleware = StorageDownloadView.as_view(storage=storage, diff --git a/demo/setup.py b/demo/setup.py index 810b219..b9c5dcc 100644 --- a/demo/setup.py +++ b/demo/setup.py @@ -19,7 +19,6 @@ URL = 'https://{name}.readthedocs.org/'.format(name=NAME) CLASSIFIERS = ['Development Status :: 4 - Beta', 'License :: OSI Approved :: BSD License', 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: 2.6', 'Framework :: Django'] KEYWORDS = [] PACKAGES = ['demoproject'] diff --git a/django_downloadview/files.py b/django_downloadview/files.py index 993fb8f..41ebb6b 100644 --- a/django_downloadview/files.py +++ b/django_downloadview/files.py @@ -203,7 +203,6 @@ class VirtualFile(File): yield buffer_ - class HTTPFile(File): """Wrapper for files that live on remote HTTP servers. diff --git a/django_downloadview/io.py b/django_downloadview/io.py index 9eacc42..9c3056e 100644 --- a/django_downloadview/io.py +++ b/django_downloadview/io.py @@ -9,7 +9,7 @@ class StringIteratorIO(io.TextIOBase): Original code by Matt Joiner from: - * http://stackoverflow.com/questions/12593576/adapt-an-iterator-to-behave-like-a-file-like-object-in-python + * http://stackoverflow.com/questions/12593576/ * https://gist.github.com/anacrolix/3788413 """ diff --git a/django_downloadview/response.py b/django_downloadview/response.py index a3e6ff5..9cb7de7 100644 --- a/django_downloadview/response.py +++ b/django_downloadview/response.py @@ -136,8 +136,8 @@ class DownloadResponse(StreamingHttpResponse): generator-iterator) that produces the output in a block-by-block fashion. - * `Django WSGI handler (application implementation) return response object - `_. + * Django WSGI handler (application implementation) returns response object + (see :mod:`django.core.handlers.wsgi`). * :class:`django.http.HttpResponse` and subclasses are iterators. @@ -179,7 +179,7 @@ class DownloadResponse(StreamingHttpResponse): ``Content-Disposition`` header is encoded according to `RFC 5987 `_. See also - http://stackoverflow.com/questions/93551/how-to-encode-the-filename-parameter-of-content-disposition-header-in-http. + http://stackoverflow.com/questions/93551/. """ try: diff --git a/django_downloadview/test.py b/django_downloadview/test.py index ac72999..e9fc454 100644 --- a/django_downloadview/test.py +++ b/django_downloadview/test.py @@ -46,7 +46,7 @@ class temporary_media_root(override_settings): Use this function as a context manager: >>> from django_downloadview.test import temporary_media_root - >>> from django.conf import settings + >>> from django.conf import settings # NoQA >>> global_media_root = settings.MEDIA_ROOT >>> with temporary_media_root(): ... global_media_root == settings.MEDIA_ROOT diff --git a/docs/Makefile b/docs/Makefile index 4461b26..f059983 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -3,7 +3,7 @@ # You can set these variables from the command line. SPHINXOPTS = -SPHINXBUILD = ../bin/sphinx-build +SPHINXBUILD = sphinx-build -W # Turn warnings into errors. PAPER = BUILDDIR = ../var/docs diff --git a/docs/conf.py b/docs/conf.py index f02cf91..ec40789 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -139,7 +139,7 @@ html_theme = 'default' # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] +html_static_path = [] # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. diff --git a/docs/contributing.txt b/docs/contributing.txt new file mode 100644 index 0000000..e582053 --- /dev/null +++ b/docs/contributing.txt @@ -0,0 +1 @@ +.. include:: ../CONTRIBUTING.rst diff --git a/docs/index.txt b/docs/index.txt index e5150a7..d601a69 100644 --- a/docs/index.txt +++ b/docs/index.txt @@ -21,4 +21,4 @@ Contents django-sendfile demo about/index - dev + contributing diff --git a/docs/optimizations/lighttpd.txt b/docs/optimizations/lighttpd.txt index f3d34f9..a75ba4f 100644 --- a/docs/optimizations/lighttpd.txt +++ b/docs/optimizations/lighttpd.txt @@ -33,7 +33,7 @@ Let's consider the following view: .. literalinclude:: /../demo/demoproject/lighttpd/views.py :language: python - :lines: 1-6, 8-16 + :lines: 1-6, 8-17 What is important here is that the files will have an ``url`` property implemented by storage. Let's setup an optimization rule based on that URL. @@ -97,7 +97,7 @@ As an example: .. literalinclude:: /../demo/demoproject/lighttpd/views.py :language: python - :lines: 1-7, 17- + :lines: 1-7, 18- ************************************* diff --git a/etc/ci-requirements.txt b/etc/ci-requirements.txt deleted file mode 100644 index e1f97eb..0000000 --- a/etc/ci-requirements.txt +++ /dev/null @@ -1,10 +0,0 @@ -coverage -docutils --e ./ --e ./demo/ -mock -nose -rednose -Sphinx -sphinxcontrib-testbuild -zest.releaser diff --git a/etc/virtualenv.cfg b/etc/virtualenv.cfg deleted file mode 100644 index c5b0ec8..0000000 --- a/etc/virtualenv.cfg +++ /dev/null @@ -1,3 +0,0 @@ ---index-url https://simple.crate.io -pip==1.4.1 -setuptools==1.4.1 diff --git a/setup.py b/setup.py index 72909f2..12809e6 100644 --- a/setup.py +++ b/setup.py @@ -1,11 +1,15 @@ # -*- coding: utf-8 -*- """Python packaging.""" import os +import sys from setuptools import setup +#: Absolute path to directory containing setup.py file. here = os.path.abspath(os.path.dirname(__file__)) +#: Boolean, ``True`` if environment is running Python version 2. +IS_PYTHON2 = sys.version_info[0] == 2 NAME = 'django-downloadview' @@ -13,12 +17,11 @@ DESCRIPTION = 'Serve files with Django and reverse-proxies.' README = open(os.path.join(here, 'README.rst')).read() VERSION = open(os.path.join(here, 'VERSION')).read().strip() AUTHOR = u'Benoît Bryon' -EMAIL = u'benoit@marmelune.net' +EMAIL = 'benoit@marmelune.net' URL = 'https://{name}.readthedocs.org/'.format(name=NAME) CLASSIFIERS = ['Development Status :: 4 - Beta', 'License :: OSI Approved :: BSD License', 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: 2.6', 'Framework :: Django'] KEYWORDS = ['file', 'stream', @@ -33,6 +36,8 @@ KEYWORDS = ['file', 'offload'] PACKAGES = [NAME.replace('-', '_')] REQUIREMENTS = ['setuptools', 'Django>=1.5', 'requests'] +if IS_PYTHON2: + REQUIREMENTS.append('mock') ENTRY_POINTS = {} diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..266a4d5 --- /dev/null +++ b/tox.ini @@ -0,0 +1,44 @@ +[tox] +envlist = py27,flake8,sphinx,readme + +[testenv] +deps = + nose + rednose + coverage +commands = + pip install -e ./ + pip install -e demo/ + demo test --nose-verbosity=2 -c etc/nose/base.cfg -c etc/nose/django_downloadview.cfg django_downloadview + demo test --nose-verbosity=2 demoproject + rm .coverage + pip freeze +whitelist_externals = + rm + +[testenv:flake8] +deps = + flake8 +commands = + flake8 django_downloadview/ + flake8 demo/demoproject/ + +[testenv:sphinx] +deps = + nose + rednose + Sphinx +commands = + make --directory=docs clean html doctest +whitelist_externals = + make + +[testenv:readme] +deps = + docutils + pygments +commands = + mkdir -p var/docs + rst2html.py --exit-status=2 README.rst var/docs/README.html +whitelist_externals = + mkdir