-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtasks.py
85 lines (69 loc) · 2.45 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
# -*- coding: utf-8 -*-
# pylint: disable=wildcard-import, unused-wildcard-import, bad-continuation
""" Project automation for Invoke.
"""
from __future__ import absolute_import, unicode_literals
import os
import shutil
import tempfile
from invoke import run, task
from rituals.invoke_tasks import * # pylint: disable=redefined-builtin
@task(name='fresh-cookies',
help={
'mold': "git URL or directory to use for the refresh",
},
)
def fresh_cookies(mold=''):
"""Refresh the project from the original cookiecutter template."""
mold = mold or "https://github.com/Springerle/py-generic-project.git" # TODO: URL from config
tmpdir = os.path.join(tempfile.gettempdir(), "moar-jmx4py")
if os.path.isdir('.git'):
# TODO: Ensure there are no local unstashed changes
pass
# Make a copy of the new mold version
if os.path.isdir(tmpdir):
shutil.rmtree(tmpdir)
if os.path.exists(mold):
shutil.copytree(mold, tmpdir, ignore=shutil.ignore_patterns(
".git", ".svn", "*~",
))
else:
run("git clone {} {}".format(mold, tmpdir), echo=True)
# Copy recorded "cookiecutter.json" into mold
shutil.copy2("project.d/cookiecutter.json", tmpdir)
with pushd('..'):
run("cookiecutter --no-input {}".format(tmpdir), echo=True)
if os.path.exists('.git'):
run("git status", echo=True)
@task(help={
'verbose': "Make 'tox' more talkative",
'env-list': "Override list of environments to use (e.g. 'py27,py34')",
'opts': "Extra flags for tox",
})
def tox(verbose=False, env_list='', opts=''):
"""Perform multi-environment tests."""
snakepits = ['/opt/pyenv/bin'] # TODO: config value
cmd = []
snakepits = [i for i in snakepits if os.path.isdir(i)]
if snakepits:
cmd += ['PATH="{}:$PATH"'.format(os.pathsep.join(snakepits),)]
cmd += ['tox']
if verbose:
cmd += ['-v']
if env_list:
cmd += ['-e', env_list]
cmd += opts
cmd += ['2>&1']
run(' '.join(cmd), echo=True)
@task(help={
'pty': "Whether to run commands under a pseudo-tty",
}) # pylint: disable=invalid-name
def ci(pty=True):
"""Perform continuous integration tasks."""
opts = ['']
# 'tox' makes no sense in Travis
if os.environ.get('TRAVIS', '').lower() == 'true':
opts += ['test']
else:
opts += ['tox']
run("invoke clean --all build --docs check --reports{} 2>&1".format(' '.join(opts)), echo=True, pty=pty)