-
Notifications
You must be signed in to change notification settings - Fork 106
/
Copy pathtasks.py
87 lines (70 loc) · 1.92 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
# -*- coding: utf-8 -*-
"""
This file defines tasks for the Invoke tool: http://www.pyinvoke.org
Basic usage::
inv -l # list all available tasks
inv --help task # show help for task
"""
# pragma: nocover
from __future__ import print_function
import glob
import os
import re
import sys
import invoke
from invoke import task # invoke==1.2.0
DIRNAME = os.path.dirname(__file__)
@task
def version(ctx):
"""Print the current version number.
"""
os.chdir(DIRNAME)
ctx.run('python setup.py --version')
@task
def setversion(ctx, version):
"""Set the version number
"""
os.chdir(DIRNAME)
with open('setup.py', 'r') as fp:
txt = fp.read()
with open('setup.py', 'w') as fp:
fp.write(re.sub(
r'^VERSION\s*=\s*.*?$', "VERSION = '%s'" % version,
txt,
flags=re.MULTILINE
))
print("Changed version in setup.py to:", version)
@task(
help={
'clean': 'remove the build/ and dist/ directory before starting',
'wheel': 'build wheel (in addition to sdist)',
'upload': 'upload to PyPI after building'
}
)
def build(ctx, clean=False, wheel=True, upload=False):
"""Build and publish (inv --help build for details)
"""
os.chdir(DIRNAME)
if clean:
ctx.run('rmdir dist /s /q', warn=True)
ctx.run('rmdir build /s /q', warn=True)
targets = 'sdist'
if wheel:
targets += ' bdist_wheel'
ctx.run("python setup.py " + targets)
print("Check generated .whl files..")
ctx.run("twine check dist/*")
# ctx.run("python setup.py build_sphinx")
if upload:
ctx.run("twine upload dist/*")
# individual tasks that can be run from this project
ns = invoke.Collection(
version,
setversion,
build
)
ns.configure({
'run': {
'echo': True
}
})