forked from kurtmckee/feedparser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dodo.py
127 lines (94 loc) · 3.5 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# This file is part of feedparser.
# Copyright 2020 Kurt McKee <[email protected]>
# Released under the BSD 2-clause license.
# The tasks defined in this file automates the entire
# development-to-release process.
import os
import pathlib
import random
import subprocess
import platform
import colorama
import docutils.core
import doit.action
# Initialize colorama so that tox can output ANSI escape codes.
colorama.init()
DOIT_CONFIG = {'default_tasks': ['build', 'test']}
PROJECT = 'feedparser'
root = pathlib.Path(__file__).parent
def task_build():
"""Build the documentation.
The documentation will be converted to HTML files to help double-check
syntax and formatting on PyPI and on GitHub. Note that the HTML files
will not be included in the distribution files.
"""
def build_single_files():
docutils.core.publish_cmdline(writer_name='html', argv=['README.rst', 'README.html'])
return {
'actions': [
build_single_files,
'sphinx-build -b html docs/ fpdocs',
],
'verbosity': 2,
'file_dep': [root / 'README.rst'] + list((root / 'docs').rglob('*.rst')),
'targets': [root / 'README.html'],
}
def task_test():
"""Run the unit tests."""
env = {k: v for k, v in os.environ.items()}
env.update({
'PY_COLORS': '1',
})
return {
'actions': [
doit.action.CmdAction('tox', env=env),
],
'verbosity': 2,
}
def remove_dist_files():
"""Erase existing files in the ``dist`` directory."""
for file in (root / 'dist/').glob('*'):
file.unlink()
def open_browser(url):
"""Open *url* in the default browser on Windows or Linux."""
if platform.system() == 'Windows':
subprocess.check_output(['start', url], shell=True)
elif platform.system() == 'Linux':
subprocess.check_output(['xdg-open', url], shell=True)
def task_test_release():
"""Upload to test.pypi.org."""
# Generate random suffixes to help prevent name and version conflicts
# on PyPI. These environment variables are used in `setup.py`.
env = {k: v for k, v in os.environ.items()}
env.update({
'NAME_SUFFIX': ''.join(chr(i) for i in random.sample(range(0x61, 0x61+26), 10)),
'VERSION_SUFFIX': str(random.choice(range(1, 1000))),
})
return {
'actions': [
remove_dist_files,
doit.action.CmdAction('python setup.py sdist bdist_wheel', env=env),
f'twine upload --repository testpypi dist/*{env["NAME_SUFFIX"]}*',
(open_browser, [f'https://test.pypi.org/project/{PROJECT}_{env["NAME_SUFFIX"]}']),
],
'verbosity': 2,
}
def validate_in_git_master_branch():
"""Validate that the repository is in the git master branch."""
branch = subprocess.check_output('git rev-parse --abbrev-ref HEAD', shell=True)
return branch.decode('utf8', errors='ignore').strip() == 'master'
def task_release():
"""Upload to pypi.org.
This step must *always* be taken while in the git master branch.
This is an enforced requirement.
"""
return {
'actions': [
validate_in_git_master_branch,
remove_dist_files,
'python setup.py sdist bdist_wheel',
'twine upload dist/*',
(open_browser, [f'https://pypi.org/project/{PROJECT}']),
],
'verbosity': 2,
}