From d634ee6eabe7b359476c2aa435177ac1e1ab2d62 Mon Sep 17 00:00:00 2001 From: Steven Loria Date: Mon, 1 Dec 2014 00:08:20 -0600 Subject: [PATCH] Replace Makefile with invoke tasks.py file --- .travis.yml | 4 ++-- Makefile | 21 --------------------- tasks.py | 28 ++++++++++++++++++++++++++++ {{cookiecutter.app_name}}/manage.py | 6 ++++-- 4 files changed, 34 insertions(+), 25 deletions(-) delete mode 100644 Makefile create mode 100644 tasks.py diff --git a/.travis.yml b/.travis.yml index 0d32a47..454acf5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,6 @@ python: - 3.3 - 3.4 install: - - pip install cookiecutter coveralls + - pip install invoke==0.9.0 script: - - make + - invoke test diff --git a/Makefile b/Makefile deleted file mode 100644 index 7e2d195..0000000 --- a/Makefile +++ /dev/null @@ -1,21 +0,0 @@ -# match default value of app_name from cookiecutter.json -COOKIE := myflaskapp -COOKIE_JAR := {{cookiecutter.app_name}} -COOKIE_CRUMBS := $(shell find $(COOKIE_JAR)) - -.PHONY: all -all: test - -.PHONY: test -test: $(COOKIE) - cd $(COOKIE); pip install -r requirements/dev.txt - cd $(COOKIE); coverage run --source $(COOKIE) manage.py test - cd $(COOKIE); coverage report -m - cd $(COOKIE); coveralls - -$(COOKIE): Makefile cookiecutter.json $(COOKIE_CRUMBS) - cookiecutter . --no-input - -.PHONY: clean -clean: - rm -r $(COOKIE) diff --git a/tasks.py b/tasks.py new file mode 100644 index 0000000..0ff1a87 --- /dev/null +++ b/tasks.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +import os +import shutil + +from invoke import task, run + +HERE = os.path.abspath(os.path.dirname(__file__)) +# Match default value of app_name from cookiecutter.json +COOKIE = os.path.join(HERE, 'myflaskapp') +REQUIREMENTS = os.path.join(COOKIE, 'requirements', 'dev.txt') + +@task +def build(): + run('cookiecutter {0} --no-input'.format(HERE)) + +@task +def clean(): + if os.path.exists(COOKIE): + shutil.rmtree(COOKIE) + print('Removed {0}'.format(COOKIE)) + else: + print('App directory does not exist. Skipping.') + +@task(pre=[clean, build]) +def test(): + run('pip install -r {0}'.format(REQUIREMENTS), echo=True) + run('python {0} test'.format(os.path.join(COOKIE, 'manage.py')), echo=True) diff --git a/{{cookiecutter.app_name}}/manage.py b/{{cookiecutter.app_name}}/manage.py index 1ce37b7..f5cc479 100644 --- a/{{cookiecutter.app_name}}/manage.py +++ b/{{cookiecutter.app_name}}/manage.py @@ -16,8 +16,10 @@ if os.environ.get("{{cookiecutter.app_name | upper}}_ENV") == 'prod': else: app = create_app(DevConfig) +HERE = os.path.abspath(os.path.dirname(__file__)) +TEST_PATH = os.path.join(HERE, 'tests') + manager = Manager(app) -TEST_CMD = "py.test tests" def _make_context(): """Return context dict for a shell session so you can access @@ -29,7 +31,7 @@ def _make_context(): def test(): """Run the tests.""" import pytest - exit_code = pytest.main(['tests', '--verbose']) + exit_code = pytest.main([TEST_PATH, '--verbose']) return exit_code manager.add_command('server', Server())