forked from Python-Markdown/markdown
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabfile.py
109 lines (94 loc) · 3.75 KB
/
fabfile.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
107
108
109
"""
Common maintenance commands for the Python-Markdown package.
"""
from fabric.api import local, lcd, settings, hide, prefix, prompt, abort
from sys import version as _pyversion
from sys import platform
def _get_versions():
""" Find and comfirm all supported versions of Python. """
vs = []
for v in ['2.6', '2.7', '3.1', '3.2', '3.3']:
with settings(
hide('warnings', 'running', 'stdout', 'stderr'),
warn_only=True
):
result = local('hash python%s' % v)
if not result.failed:
vs.append(v)
return vs
confirmed_versions = _get_versions()
def clean():
""" Clean up dir. """
local('git clean -dfx')
def list_versions():
""" List all supported versions of Python. """
print('Supported Python versions available on this system:')
print(' Python ' + '\n Python '.join(confirmed_versions))
def test(version=_pyversion[:3]):
""" Run tests with given Python Version. Defaults to system default. """
if version in confirmed_versions:
build_tests(version=version)
#with prefix('bash $HOME/.virtualenvs/md%s/bin/activate' % version):
with lcd('build/test.%s/' % version):
local('python%s run-tests.py' % version)
else:
print('Python %s is not an available supported version.' % version)
list_versions()
def test_all():
""" Run tests in all available supported versions. """
for v in confirmed_versions:
test(v)
def build_tests(version=_pyversion[:3]):
""" Build tests for given Python Version. """
local('python%s setup.py build --build-purelib build/test.%s' % \
(version, version))
local('rm -rf build/test.%s/tests' % version)
local('mkdir build/test.%s/tests' % version)
local('cp -r tests/* build/test.%s/tests' % version)
local('cp run-tests.py build/test.%s/run-tests.py' % version)
local('cp setup.cfg build/test.%s/setup.cfg' % version)
if version.startswith('3'):
# Do 2to3 conversion
local('2to3-%s -w -d build/test.%s/markdown' % (version, version))
def generate_test(file):
""" Generate a given test. """
import sys, os
sys.path.insert(0, os.path.abspath(os.path.dirname(__file__)))
import tests
config = tests.get_config(os.path.dirname(file))
root, ext = os.path.splitext(file)
if ext == config.get(tests.get_section(os.path.basename(root), config),
'input_ext'):
tests.generate(root, config)
else:
print file, 'does not have a valid file extension. Check config.'
def generate_tests():
""" Generate all outdated tests. """
import sys, os
sys.path.insert(0, os.path.abspath(os.path.dirname(__file__)))
from tests import generate_all
generate_all()
def build_env(version=_pyversion[:3]):
""" Build testing environment for given Python version. """
if version in confirmed_versions:
if version == '2.4':
local('sudo pip%s install ElementTree' % version)
local('sudo pip%s install nose' % version)
def build_envs():
""" Build testing env in all supported versions. """
for v in confirmed_versions:
build_env(v)
def build_release():
""" Build a package for distribution. """
ans = prompt('Have you updated the version_info in __version__.py?', default='Y')
if ans.lower() == 'y':
local('./setup.py sdist --formats zip,gztar')
if platform == 'win32':
local('./setup.py bdist_wininst')
else:
abort('Try again after updating the version numbers.')
def deploy_release():
""" Register and upload release to PyPI and Github. """
build_release()
local('./setup.py register')
local('./setup.py upload')