##// END OF EJS Templates
Backport PR #8985: override vformat instead of _vformat...
Backport PR #8985: override vformat instead of _vformat in our eval formatters avoids being caught out by changes in private API this needs to be backported in order to support Python 3.4.4 ...

File last commit:

r21687:7fefad27
r21827:d30b2522
Show More
gh-pages.py
141 lines | 4.1 KiB | text/x-python | PythonLexer
MinRK
replace in-repo gh-pages with external ipython-doc, as in datarray
r3311 #!/usr/bin/env python
Matthias Bussonnier
Add compatibility to build docs with Py3....
r21687 from __future__ import print_function
MinRK
replace in-repo gh-pages with external ipython-doc, as in datarray
r3311 """Script to commit the doc build outputs into the github-pages repo.
Use:
gh-pages.py [tag]
If no tag is given, the current output of 'git describe' is used. If given,
that is how the resulting directory will be named.
In practice, you should use either actual clean tags from a current build or
something like 'current' as a stable URL for the most current version of the """
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
import os
import re
import shutil
import sys
from os import chdir as cd
from os.path import join as pjoin
from subprocess import Popen, PIPE, CalledProcessError, check_call
#-----------------------------------------------------------------------------
# Globals
#-----------------------------------------------------------------------------
pages_dir = 'gh-pages'
html_dir = 'build/html'
MinRK
gh-pages includes pdf...
r3315 pdf_dir = 'build/latex'
MinRK
replace in-repo gh-pages with external ipython-doc, as in datarray
r3311 pages_repo = 'git@github.com:ipython/ipython-doc.git'
Matthias Bussonnier
Add compatibility to build docs with Py3....
r21687
if sys.version_info[0] <= 3:
getcwd = os.getcwd
else:
getcwd = os.getcwdu
MinRK
replace in-repo gh-pages with external ipython-doc, as in datarray
r3311 #-----------------------------------------------------------------------------
# Functions
#-----------------------------------------------------------------------------
def sh(cmd):
"""Execute command in a subshell, return status code."""
return check_call(cmd, shell=True)
def sh2(cmd):
"""Execute command in a subshell, return stdout.
Stderr is unbuffered from the subshell.x"""
p = Popen(cmd, stdout=PIPE, shell=True)
out = p.communicate()[0]
retcode = p.returncode
if retcode:
raise CalledProcessError(retcode, cmd)
else:
return out.rstrip()
def sh3(cmd):
"""Execute command in a subshell, return stdout, stderr
If anything appears in stderr, print it out to sys.stderr"""
p = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True)
out, err = p.communicate()
retcode = p.returncode
if retcode:
raise CalledProcessError(retcode, cmd)
else:
return out.rstrip(), err.rstrip()
def init_repo(path):
"""clone the gh-pages repo if we haven't already."""
sh("git clone %s %s"%(pages_repo, path))
Matthias Bussonnier
Add compatibility to build docs with Py3....
r21687 here = getcwd()
MinRK
replace in-repo gh-pages with external ipython-doc, as in datarray
r3311 cd(path)
sh('git checkout gh-pages')
cd(here)
#-----------------------------------------------------------------------------
# Script starts
#-----------------------------------------------------------------------------
if __name__ == '__main__':
# The tag can be given as a positional argument
try:
tag = sys.argv[1]
except IndexError:
MinRK
require specifying the version for gh-pages...
r15316 tag = "dev"
MinRK
gh-pages includes pdf...
r3315
Matthias Bussonnier
Add compatibility to build docs with Py3....
r21687 startdir = getcwd()
MinRK
replace in-repo gh-pages with external ipython-doc, as in datarray
r3311 if not os.path.exists(pages_dir):
MinRK
gh-pages uses reST
r3316 # init the repo
MinRK
replace in-repo gh-pages with external ipython-doc, as in datarray
r3311 init_repo(pages_dir)
MinRK
gh-pages uses reST
r3316 else:
# ensure up-to-date before operating
cd(pages_dir)
sh('git checkout gh-pages')
sh('git pull')
cd(startdir)
MinRK
replace in-repo gh-pages with external ipython-doc, as in datarray
r3311
dest = pjoin(pages_dir, tag)
# don't `make html` here, because gh-pages already depends on html in Makefile
# sh('make html')
MinRK
gh-pages tweaks...
r4672 if tag != 'dev':
# only build pdf for non-dev targets
Fernando Perez
Open 0.13 series for development.
r5796 #sh2('make pdf')
pass
MinRK
replace in-repo gh-pages with external ipython-doc, as in datarray
r3311
# This is pretty unforgiving: we unconditionally nuke the destination
# directory, and then copy the html tree in there
shutil.rmtree(dest, ignore_errors=True)
shutil.copytree(html_dir, dest)
MinRK
gh-pages tweaks...
r4672 if tag != 'dev':
Fernando Perez
Open 0.13 series for development.
r5796 #shutil.copy(pjoin(pdf_dir, 'ipython.pdf'), pjoin(dest, 'ipython.pdf'))
pass
MinRK
replace in-repo gh-pages with external ipython-doc, as in datarray
r3311
try:
cd(pages_dir)
MinRK
require specifying the version for gh-pages...
r15316 branch = sh2('git rev-parse --abbrev-ref HEAD').strip()
Matthias Bussonnier
Add compatibility to build docs with Py3....
r21687 if branch != b'gh-pages':
MinRK
replace in-repo gh-pages with external ipython-doc, as in datarray
r3311 e = 'On %r, git branch is %r, MUST be "gh-pages"' % (pages_dir,
branch)
raise RuntimeError(e)
MinRK
gh-pages tweaks...
r4672 sh('git add -A %s' % tag)
MinRK
gh-pages.py no longer updates index.rst
r3330 sh('git commit -m"Updated doc release: %s"' % tag)
Matthias Bussonnier
Add compatibility to build docs with Py3....
r21687 print()
print( 'Most recent 3 commits:')
MinRK
replace in-repo gh-pages with external ipython-doc, as in datarray
r3311 sys.stdout.flush()
sh('git --no-pager log --oneline HEAD~3..')
finally:
cd(startdir)
Matthias Bussonnier
Add compatibility to build docs with Py3....
r21687 print()
print( 'Now verify the build in: %r' % dest)
print( "If everything looks good, 'git push'")