##// END OF EJS Templates
replace in-repo gh-pages with external ipython-doc, as in datarray
MinRK -
Show More
@@ -0,0 +1,143 b''
1 #!/usr/bin/env python
2 """Script to commit the doc build outputs into the github-pages repo.
3
4 Use:
5
6 gh-pages.py [tag]
7
8 If no tag is given, the current output of 'git describe' is used. If given,
9 that is how the resulting directory will be named.
10
11 In practice, you should use either actual clean tags from a current build or
12 something like 'current' as a stable URL for the most current version of the """
13
14 #-----------------------------------------------------------------------------
15 # Imports
16 #-----------------------------------------------------------------------------
17 import os
18 import re
19 import shutil
20 import sys
21 from os import chdir as cd
22 from os.path import join as pjoin
23
24 from subprocess import Popen, PIPE, CalledProcessError, check_call
25
26 #-----------------------------------------------------------------------------
27 # Globals
28 #-----------------------------------------------------------------------------
29
30 pages_dir = 'gh-pages'
31 html_dir = 'build/html'
32 pages_repo = 'git@github.com:ipython/ipython-doc.git'
33
34 #-----------------------------------------------------------------------------
35 # Functions
36 #-----------------------------------------------------------------------------
37 def sh(cmd):
38 """Execute command in a subshell, return status code."""
39 return check_call(cmd, shell=True)
40
41
42 def sh2(cmd):
43 """Execute command in a subshell, return stdout.
44
45 Stderr is unbuffered from the subshell.x"""
46 p = Popen(cmd, stdout=PIPE, shell=True)
47 out = p.communicate()[0]
48 retcode = p.returncode
49 if retcode:
50 raise CalledProcessError(retcode, cmd)
51 else:
52 return out.rstrip()
53
54
55 def sh3(cmd):
56 """Execute command in a subshell, return stdout, stderr
57
58 If anything appears in stderr, print it out to sys.stderr"""
59 p = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True)
60 out, err = p.communicate()
61 retcode = p.returncode
62 if retcode:
63 raise CalledProcessError(retcode, cmd)
64 else:
65 return out.rstrip(), err.rstrip()
66
67
68 def init_repo(path):
69 """clone the gh-pages repo if we haven't already."""
70 sh("git clone %s %s"%(pages_repo, path))
71 here = os.getcwd()
72 cd(path)
73 sh('git checkout gh-pages')
74 cd(here)
75
76
77 def render_htmlindex(fname, tag):
78 rel = '<li> Release: <a href="{t}/index.html">{t}</a>'.format(t=tag)
79 rep = re.compile('<!-- RELEASE -->')
80 out = []
81 with file(fname) as f:
82 for line in f:
83 out.append(line)
84 if rep.search(line):
85 out.append(rep.sub(rel, line))
86 return ''.join(out)
87
88
89 def new_htmlindex(fname, tag):
90 new_page = render_htmlindex(fname, tag)
91 os.rename(fname, fname+'~')
92 with file(fname, 'w') as f:
93 f.write(new_page)
94
95
96 #-----------------------------------------------------------------------------
97 # Script starts
98 #-----------------------------------------------------------------------------
99 if __name__ == '__main__':
100 # The tag can be given as a positional argument
101 try:
102 tag = sys.argv[1]
103 except IndexError:
104 tag = sh2('git describe')
105
106 startdir = os.getcwd()
107 if not os.path.exists(pages_dir):
108 init_repo(pages_dir)
109
110 dest = pjoin(pages_dir, tag)
111
112 # don't `make html` here, because gh-pages already depends on html in Makefile
113 # sh('make html')
114
115 # This is pretty unforgiving: we unconditionally nuke the destination
116 # directory, and then copy the html tree in there
117 shutil.rmtree(dest, ignore_errors=True)
118 shutil.copytree(html_dir, dest)
119
120 try:
121 cd(pages_dir)
122 sh('git checkout gh-pages')
123 status = sh2('git status | head -1')
124 branch = re.match('\# On branch (.*)$', status).group(1)
125 if branch != 'gh-pages':
126 e = 'On %r, git branch is %r, MUST be "gh-pages"' % (pages_dir,
127 branch)
128 raise RuntimeError(e)
129
130 sh('git add %s' % tag)
131 new_htmlindex('index.html', tag)
132 sh('git add index.html')
133 sh('git commit -m"Created new doc release, named: %s"' % tag)
134 print
135 print 'Most recent 3 commits:'
136 sys.stdout.flush()
137 sh('git --no-pager log --oneline HEAD~3..')
138 finally:
139 cd(startdir)
140
141 print
142 print 'Now verify the build in: %r' % dest
143 print "If everything looks good, 'git push'"
@@ -32,7 +32,7 b' help:'
32 @echo "gitwash-update update git workflow from source repo"
32 @echo "gitwash-update update git workflow from source repo"
33
33
34 clean:
34 clean:
35 -rm -rf build/* dist/* $(SRCDIR)/api/generated gh-pages
35 -rm -rf build/* dist/* $(SRCDIR)/api/generated
36
36
37 pdf: latex
37 pdf: latex
38 cd build/latex && make all-pdf
38 cd build/latex && make all-pdf
@@ -104,4 +104,7 b' nightly: dist'
104 rsync -avH --delete dist/ ipython:www/doc/nightly
104 rsync -avH --delete dist/ ipython:www/doc/nightly
105
105
106 gh-pages: html
106 gh-pages: html
107 sh update_ghpages.sh
107 python gh-pages.py
108
109 gh-pages-current: html
110 python gh-pages.py current
@@ -44,7 +44,6 b' extensions = ['
44 'inheritance_diagram',
44 'inheritance_diagram',
45 'ipython_console_highlighting',
45 'ipython_console_highlighting',
46 'numpydoc', # to preprocess docstrings
46 'numpydoc', # to preprocess docstrings
47 'sphinxtogithub',
48 ]
47 ]
49
48
50 # Add any paths that contain templates here, relative to this directory.
49 # Add any paths that contain templates here, relative to this directory.
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now