-
Notifications
You must be signed in to change notification settings - Fork 0
/
tasks.py
103 lines (84 loc) · 2.18 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
94
95
96
97
98
99
100
101
102
103
"""
invoke Tasks for maintaining the moreman project
"""
import platform
import shutil
from pathlib import Path
from invoke import task
ROOT_DIR = Path(__file__).parent
SETUP_FILE = ROOT_DIR.joinpath("setup.py")
SOURCE_DIR = ROOT_DIR.joinpath("moreman")
PYTHON_DIRS = [str(d) for d in [SOURCE_DIR]]
# pipenv short cut constants
PER = 'pipenv run'
def pe_run(ctx, cmd):
"""
Run `cmd` inside the virtualenv via `pipenv run`
"""
ctx.run(f'{PER} {cmd}')
#
# Source code tasks
#
@task(help={'check': "Checks if source is formatted without applying changes"})
def format(c, check=False):
"""
Format code
"""
python_dirs_string = " ".join(PYTHON_DIRS)
# Run black
black_opts = f'{"--check" if check else ""}'
pe_run(c, f'black {black_opts} {python_dirs_string}')
# Run isort
isort_opts = f'--recursive {"--check-only" if check else ""}'
pe_run(c, f'isort {isort_opts} {python_dirs_string}')
@task(help={'part': "Specify version number part (default: 'patch')"})
def newver(c, part='patch'):
"""
Bump version number
"""
opts = '--allow-dirty --verbose'
pe_run(c, f'bumpversion {opts} {part}')
#
# Cleaning tasks
#
@task
def clean_build(c):
"""
Clean up files from package building
"""
pe_run(c, "rm -fr build/")
pe_run(c, "rm -fr dist/")
pe_run(c, "rm -fr .eggs/")
pe_run(c, "find . -name '*.egg-info' -exec rm -fr {} +")
pe_run(c, "find . -name '*.egg' -exec rm -f {} +")
@task
def clean_python(c):
"""
Clean up python file artifacts
"""
pe_run(c, "find . -name '*.pyc' -exec rm -f {} +")
pe_run(c, "find . -name '*.pyo' -exec rm -f {} +")
pe_run(c, "find . -name '*~' -exec rm -f {} +")
pe_run(c, "find . -name '__pycache__' -exec rm -fr {} +")
@task(pre=[clean_build, clean_python])
def clean(c):
"""
Runs all clean sub-tasks
"""
pass
#
# Release tasks
#
@task(clean)
def dist(c):
"""
Build source and wheel packages
"""
pe_run(c, "python setup.py sdist")
pe_run(c, "python setup.py bdist_wheel")
@task(pre=[clean, dist])
def publish(c):
"""
Publish a release of the python package on PyPI
"""
pe_run(c, "twine upload dist/*")