forked from 0101/pipetools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
publish_docs.py
86 lines (53 loc) · 1.8 KB
/
publish_docs.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
"""
A script for generating a README file and publishing docs on github pages.
"""
import codecs
import re
from paver.easy import sh, BuildFailure
from pipetools import foreach, foreach_do, where, X, pipe, unless
DOC_ROOT = 'http://0101.github.io/pipetools/doc/'
readme_template = """
`Complete documentation in full color <{0}>`_.
.. image:: https://travis-ci.org/0101/pipetools.svg?branch=master
:target: https://travis-ci.org/0101/pipetools
Pipetools
=========
{{0}}
But wait, there is more
-----------------------
See the `full documentation <{0}#contents>`_.
""".format(DOC_ROOT)
link_template = u"`{text} <%s{url}>`_" % DOC_ROOT
link_replacements = (
# :doc:`pipe-utils' documentation<pipeutils>`.
(r":doc:`([^<]*)<([^>]*)>`", {'url': r'\2.html', 'text': r'\1'}),
# :func:`~pipetools.utils.where`
(r":func:`~pipetools\.utils\.([^`]*)`",
{'url': r'pipeutils.html#pipetools.utils.\1', 'text': r'\1()'}),
) > foreach([X[0] | re.compile, X[1] | link_template])
def create_readme():
with codecs.open('docs/source/overview.rst', 'r', 'utf-8') as overview:
with codecs.open('README.rst', 'w+', 'utf-8') as readme:
overview.read() > pipe | fix_links | readme_template | readme.write
def fix_links(string):
for pattern, replacement in link_replacements:
string = pattern.sub(replacement, string)
return string
commit_readme = """
git add README.rst
git commit -m "(readme update)"
"""
update_gh_pages = """
git checkout gh-pages
git merge master
git rm -rf doc
sphinx-build -b html docs/source/ doc
git add doc
git commit -m "doc update"
git checkout master
"""
runscript = X.split('\n') | where(X) | unless(BuildFailure, foreach_do(sh))
if __name__ == '__main__':
create_readme()
runscript(commit_readme)
runscript(update_gh_pages)