forked from pydoit/doit-py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dodo.py
106 lines (86 loc) · 3.19 KB
/
dodo.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
104
105
106
import glob
import subprocess
from doitpy.pyflakes import Pyflakes
from doitpy.coverage import PythonPackage, Coverage
from doitpy.package import Package
from doitpy import docs
DOIT_CONFIG = {'default_tasks': ['pyflakes', 'test']}
def task_pyflakes():
flakes = Pyflakes()
yield flakes.tasks('*.py')
yield flakes.tasks('doitpy/*.py')
yield flakes.tasks('tests/**/*.py',
exclude_paths=['tests/sample/flake_fail.py',])
def task_test():
"""run unit-tests"""
# XXX
return {'actions': ['py.test tests']}
def task_coverage():
cov = Coverage([PythonPackage('doitpy', test_path='tests')],
config={'branch':False})
yield cov.all()
yield cov.src()
yield cov.by_module()
def task_package():
"""upload package to pypi"""
pkg = Package()
yield pkg.manifest_git()
yield pkg.sdist()
yield pkg.sdist_upload()
def task_docs():
doc_files = glob.glob('doc/*.rst') + ['README.rst']
yield docs.spell(doc_files, 'doc/dictionary.txt')
yield docs.sphinx('doc/', 'doc/_build/html/', task_dep=['spell'])
yield docs.pythonhosted_upload('doc/_build/html/', task_dep=['sphinx'])
##########################
from doit.tools import result_dep
init_file = 'doitpy/__init__.py'
def task_version():
"""update version on <pkg-name>/__init__.py and doc/conf.py"""
# get package version from setup.py
# version must be set with a string literal using single/double quotes
# but not triple-quotes.
def version_str2tuple(string):
parts = []
for part in string.split('.'):
parts.append(part if not part.isdigit() else int(part))
return tuple(repr(x) for x in parts)
def get_version():
#cmd = ("""awk 'match($0, /version[[:space:]]*=[[:space:]]*"""
# r"""['\''"](.*)['\''"].*/, ary) {print ary[1]}' setup.py""")
cmd = 'python setup.py --version'
version_str = subprocess.check_output(cmd, shell=True,
universal_newlines=True)
version_str = version_str.strip()
version_tuple = version_str2tuple(version_str)
return {
'version': '.'.join(version_tuple[:2]),
'release': version_str,
'tuple': version_tuple,
}
yield {
'name': 'get_from_setup',
'file_dep': ['setup.py'],
'actions': [get_version],
}
sed = "sed --in-place --regexp-extended "
yield {
'name': 'set_pkg',
'uptodate': [result_dep('version:get_from_setup')],
'getargs': {'version': ('version:get_from_setup', 'tuple')},
'actions': [
sed + r"'s/(__version__ = )(.*)/\1%(version)s/' " + init_file],
'targets': [init_file]
}
doc_file = 'doc/conf.py'
yield {
'name': 'set_doc',
'uptodate': [result_dep('version:get_from_setup')],
'getargs': {
'version': ('version:get_from_setup', 'version'),
'release': ('version:get_from_setup', 'release')},
'actions': [
sed + r""" "s/(version = )(.*)/\1'%(version)s'/" """ + doc_file,
sed + r""" "s/(release = )(.*)/\1'%(release)s'/" """ + doc_file,
]
}