-
Notifications
You must be signed in to change notification settings - Fork 1
/
tasks.py
93 lines (77 loc) · 3.35 KB
/
tasks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# *- coding: utf-8 -*-
# pylint: disable=locally-disabled, bad-continuation
# pylint: disable=wildcard-import, unused-import, unused-wildcard-import
# pylint: disable=superfluous-parens, redefined-builtin
""" Project automation for Invoke.
"""
# Copyright (c) 2015 Jürgen Hermann
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import os
import sys
import shlex
import shutil
from rituals.easy import task, Collection, pushd
from rituals.util import antglob, notify
from rituals.acts.documentation import namespace as _docs
@task(help=dict(
docs="Also clean the documentation build area",
venv="Include an existing virtualenv (in '.venv')",
extra="Any extra patterns, space-separated and possibly quoted",
))
def clean(ctx, docs=False, venv=False, extra=''):
"""Perform house-keeping."""
notify.banner("Cleaning up project files")
# Add patterns based on given parameters
venv_dirs = ['.venv']
patterns = ['new-script/', 'pip-selfcheck.json', '**/*~']
if docs:
patterns.append('docs/_build/')
if venv:
patterns.extend([i + '/' for i in venv_dirs])
if extra:
patterns.extend(shlex.split(extra))
# Build fileset
patterns = [antglob.includes(i) for i in patterns]
if not venv:
# Do not scan venv dirs when not cleaning them
patterns.extend([antglob.excludes(i + '/') for i in venv_dirs])
fileset = antglob.FileSet('.', patterns)
# Iterate over matches and remove them
for name in fileset:
notify.info('rm {0}'.format(name))
if name.endswith('/'):
shutil.rmtree(name)
else:
os.unlink(name)
@task(pre=[clean])
def test(ctx):
"""Perform integration tests."""
#ctx.run("touch '{{cookiecutter.repo_name}}/empty-testfile'")
ctx.run("py.test")
#ctx.run("rm '{{cookiecutter.repo_name}}/empty-testfile'")
with pushd('new-script'):
#assert not os.path.exists('empty-testfile'), "empty file is removed"
opts = ''
if os.environ.get('TRAVIS', '') == 'true':
opts = '--echo --pty'
venv_bin = '.venv/new-script/bin/'
ctx.run("bash -c '. .env --yes --develop && invoke {} build test check'".format(opts))
ctx.run(venv_bin + "new-script --help")
ctx.run(venv_bin + "new-script --version")
namespace = Collection.from_module(sys.modules[__name__], name='')
namespace.add_collection(_docs)