Show More
@@ -1,111 +1,107 | |||
|
1 | 1 | # Makefile for Sphinx documentation |
|
2 | 2 | # |
|
3 | 3 | |
|
4 | 4 | # You can set these variables from the command line. |
|
5 | 5 | SPHINXOPTS = |
|
6 | 6 | SPHINXBUILD = sphinx-build |
|
7 | 7 | PAPER = |
|
8 | 8 | SRCDIR = source |
|
9 | 9 | |
|
10 | 10 | # Internal variables. |
|
11 | 11 | PAPEROPT_a4 = -D latex_paper_size=a4 |
|
12 | 12 | PAPEROPT_letter = -D latex_paper_size=letter |
|
13 | 13 | ALLSPHINXOPTS = -d build/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) $(SRCDIR) |
|
14 | 14 | |
|
15 | 15 | .PHONY: help clean html web pickle htmlhelp latex changes linkcheck api |
|
16 | 16 | |
|
17 | 17 | default: html |
|
18 | 18 | |
|
19 | 19 | help: |
|
20 | 20 | @echo "Please use \`make <target>' where <target> is one of" |
|
21 | 21 | @echo " html to make standalone HTML files" |
|
22 | 22 | @echo " pickle to make pickle files (usable by e.g. sphinx-web)" |
|
23 | 23 | @echo " htmlhelp to make HTML files and a HTML help project" |
|
24 | 24 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" |
|
25 | 25 | @echo " changes to make an overview over all changed/added/deprecated items" |
|
26 | 26 | @echo " linkcheck to check all external links for integrity" |
|
27 | 27 | @echo |
|
28 | 28 | @echo "Compound utility targets:" |
|
29 | 29 | @echo "pdf latex and then runs the PDF generation" |
|
30 | 30 | @echo "all html and pdf" |
|
31 | 31 | @echo "dist all, and then puts the results in dist/" |
|
32 | 32 | @echo "gitwash-update update git workflow from source repo" |
|
33 | 33 | |
|
34 | 34 | clean: |
|
35 | 35 | -rm -rf build/* dist/* $(SRCDIR)/api/generated |
|
36 | 36 | |
|
37 | 37 | pdf: latex |
|
38 | 38 | cd build/latex && make all-pdf |
|
39 | 39 | |
|
40 | 40 | all: html pdf |
|
41 | 41 | |
|
42 | 42 | dist: all |
|
43 | 43 | mkdir -p dist |
|
44 | 44 | rm -rf dist/* |
|
45 | 45 | ln build/latex/ipython.pdf dist/ |
|
46 | 46 | cp -al build/html dist/ |
|
47 | 47 | @echo "Build finished. Final docs are in dist/" |
|
48 | 48 | |
|
49 | 49 | html: api |
|
50 | 50 | mkdir -p build/html build/doctrees |
|
51 | 51 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) build/html |
|
52 | 52 | @echo |
|
53 | 53 | @echo "Build finished. The HTML pages are in build/html." |
|
54 | 54 | |
|
55 | 55 | api: source/api/generated/gen.txt |
|
56 | 56 | |
|
57 | 57 | source/api/generated/gen.txt: |
|
58 | 58 | python autogen_api.py |
|
59 | 59 | @echo "Build API docs finished." |
|
60 | 60 | |
|
61 | 61 | pickle: |
|
62 | 62 | mkdir -p build/pickle build/doctrees |
|
63 | 63 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) build/pickle |
|
64 | 64 | @echo |
|
65 | 65 | @echo "Build finished; now you can process the pickle files or run" |
|
66 | 66 | @echo " sphinx-web build/pickle" |
|
67 | 67 | @echo "to start the sphinx-web server." |
|
68 | 68 | |
|
69 | 69 | web: pickle |
|
70 | 70 | |
|
71 | 71 | htmlhelp: |
|
72 | 72 | mkdir -p build/htmlhelp build/doctrees |
|
73 | 73 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) build/htmlhelp |
|
74 | 74 | @echo |
|
75 | 75 | @echo "Build finished; now you can run HTML Help Workshop with the" \ |
|
76 | 76 | ".hhp project file in build/htmlhelp." |
|
77 | 77 | |
|
78 | 78 | latex: api |
|
79 | 79 | mkdir -p build/latex build/doctrees |
|
80 | 80 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) build/latex |
|
81 | 81 | @echo |
|
82 | 82 | @echo "Build finished; the LaTeX files are in build/latex." |
|
83 | 83 | @echo "Run \`make all-pdf' or \`make all-ps' in that directory to" \ |
|
84 | 84 | "run these through (pdf)latex." |
|
85 | 85 | |
|
86 | 86 | changes: |
|
87 | 87 | mkdir -p build/changes build/doctrees |
|
88 | 88 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) build/changes |
|
89 | 89 | @echo |
|
90 | 90 | @echo "The overview file is in build/changes." |
|
91 | 91 | |
|
92 | 92 | linkcheck: |
|
93 | 93 | mkdir -p build/linkcheck build/doctrees |
|
94 | 94 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) build/linkcheck |
|
95 | 95 | @echo |
|
96 | 96 | @echo "Link check complete; look for any errors in the above output " \ |
|
97 | 97 | "or in build/linkcheck/output.txt." |
|
98 | 98 | |
|
99 | 99 | gitwash-update: |
|
100 | 100 | python ../tools/gitwash_dumper.py source/development ipython |
|
101 | 101 | cd source/development/gitwash && rename 's/.rst/.txt/' *.rst |
|
102 | 102 | |
|
103 | 103 | nightly: dist |
|
104 | 104 | rsync -avH --delete dist/ ipython:www/doc/nightly |
|
105 | 105 | |
|
106 | 106 | gh-pages: html pdf |
|
107 | 107 | python gh-pages.py |
|
108 | ||
|
109 | gh-pages-current: html pdf | |
|
110 | ipver="$(ipython -v 2>&1)" | |
|
111 | python gh-pages.py dev "Current Development Version ($ipver)" |
@@ -1,168 +1,132 | |||
|
1 | 1 | #!/usr/bin/env python |
|
2 | 2 | """Script to commit the doc build outputs into the github-pages repo. |
|
3 | 3 | |
|
4 | 4 | Use: |
|
5 | 5 | |
|
6 | 6 | gh-pages.py [tag] |
|
7 | 7 | |
|
8 | 8 | If no tag is given, the current output of 'git describe' is used. If given, |
|
9 | 9 | that is how the resulting directory will be named. |
|
10 | 10 | |
|
11 | 11 | In practice, you should use either actual clean tags from a current build or |
|
12 | 12 | something like 'current' as a stable URL for the most current version of the """ |
|
13 | 13 | |
|
14 | 14 | #----------------------------------------------------------------------------- |
|
15 | 15 | # Imports |
|
16 | 16 | #----------------------------------------------------------------------------- |
|
17 | 17 | import os |
|
18 | 18 | import re |
|
19 | 19 | import shutil |
|
20 | 20 | import sys |
|
21 | 21 | from os import chdir as cd |
|
22 | 22 | from os.path import join as pjoin |
|
23 | 23 | |
|
24 | 24 | from subprocess import Popen, PIPE, CalledProcessError, check_call |
|
25 | 25 | |
|
26 | 26 | #----------------------------------------------------------------------------- |
|
27 | 27 | # Globals |
|
28 | 28 | #----------------------------------------------------------------------------- |
|
29 | 29 | |
|
30 | 30 | pages_dir = 'gh-pages' |
|
31 | 31 | html_dir = 'build/html' |
|
32 | 32 | pdf_dir = 'build/latex' |
|
33 | 33 | pages_repo = 'git@github.com:ipython/ipython-doc.git' |
|
34 | 34 | |
|
35 | 35 | #----------------------------------------------------------------------------- |
|
36 | 36 | # Functions |
|
37 | 37 | #----------------------------------------------------------------------------- |
|
38 | 38 | def sh(cmd): |
|
39 | 39 | """Execute command in a subshell, return status code.""" |
|
40 | 40 | return check_call(cmd, shell=True) |
|
41 | 41 | |
|
42 | 42 | |
|
43 | 43 | def sh2(cmd): |
|
44 | 44 | """Execute command in a subshell, return stdout. |
|
45 | 45 | |
|
46 | 46 | Stderr is unbuffered from the subshell.x""" |
|
47 | 47 | p = Popen(cmd, stdout=PIPE, shell=True) |
|
48 | 48 | out = p.communicate()[0] |
|
49 | 49 | retcode = p.returncode |
|
50 | 50 | if retcode: |
|
51 | 51 | raise CalledProcessError(retcode, cmd) |
|
52 | 52 | else: |
|
53 | 53 | return out.rstrip() |
|
54 | 54 | |
|
55 | 55 | |
|
56 | 56 | def sh3(cmd): |
|
57 | 57 | """Execute command in a subshell, return stdout, stderr |
|
58 | 58 | |
|
59 | 59 | If anything appears in stderr, print it out to sys.stderr""" |
|
60 | 60 | p = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True) |
|
61 | 61 | out, err = p.communicate() |
|
62 | 62 | retcode = p.returncode |
|
63 | 63 | if retcode: |
|
64 | 64 | raise CalledProcessError(retcode, cmd) |
|
65 | 65 | else: |
|
66 | 66 | return out.rstrip(), err.rstrip() |
|
67 | 67 | |
|
68 | 68 | |
|
69 | 69 | def init_repo(path): |
|
70 | 70 | """clone the gh-pages repo if we haven't already.""" |
|
71 | 71 | sh("git clone %s %s"%(pages_repo, path)) |
|
72 | 72 | here = os.getcwd() |
|
73 | 73 | cd(path) |
|
74 | 74 | sh('git checkout gh-pages') |
|
75 | 75 | cd(here) |
|
76 | 76 | |
|
77 | ||
|
78 | def render_rstindex(fname, tag, desc=None): | |
|
79 | if desc is None: | |
|
80 | desc = tag | |
|
81 | ||
|
82 | rel = '* {d}: `HTML <{t}/index.html>`_ and `PDF <{t}/ipython.pdf>`_.'.format(t=tag,d=desc) | |
|
83 | rep = re.compile(r'\.\. release') | |
|
84 | out = [] | |
|
85 | with file(fname) as f: | |
|
86 | contents = f.read() | |
|
87 | lines = contents.splitlines() | |
|
88 | if rel in contents: | |
|
89 | out = lines | |
|
90 | else: | |
|
91 | for line in lines: | |
|
92 | out.append(line) | |
|
93 | if rep.search(line): | |
|
94 | out.append(rep.sub(rel, line)) | |
|
95 | return '\n'.join(out)+'\n' | |
|
96 | ||
|
97 | ||
|
98 | def new_rstindex(fname, tag, desc=None): | |
|
99 | new_page = render_rstindex(fname, tag, desc) | |
|
100 | os.rename(fname, fname+'~') | |
|
101 | with file(fname, 'w') as f: | |
|
102 | f.write(new_page) | |
|
103 | ||
|
104 | ||
|
105 | 77 | #----------------------------------------------------------------------------- |
|
106 | 78 | # Script starts |
|
107 | 79 | #----------------------------------------------------------------------------- |
|
108 | 80 | if __name__ == '__main__': |
|
109 | 81 | # The tag can be given as a positional argument |
|
110 | 82 | try: |
|
111 | 83 | tag = sys.argv[1] |
|
112 | 84 | except IndexError: |
|
113 | 85 | try: |
|
114 | 86 | tag = sh2('git describe') |
|
115 | 87 | except CalledProcessError: |
|
116 | 88 | tag = "dev" # Fallback |
|
117 | 89 | |
|
118 | try: | |
|
119 | desc = sys.argv[2] | |
|
120 | except IndexError: | |
|
121 | desc="Release (%s)"%tag | |
|
122 | ||
|
123 | 90 | startdir = os.getcwd() |
|
124 | 91 | if not os.path.exists(pages_dir): |
|
125 | 92 | # init the repo |
|
126 | 93 | init_repo(pages_dir) |
|
127 | 94 | else: |
|
128 | 95 | # ensure up-to-date before operating |
|
129 | 96 | cd(pages_dir) |
|
130 | 97 | sh('git checkout gh-pages') |
|
131 | 98 | sh('git pull') |
|
132 | 99 | cd(startdir) |
|
133 | 100 | |
|
134 | 101 | dest = pjoin(pages_dir, tag) |
|
135 | 102 | |
|
136 | 103 | # don't `make html` here, because gh-pages already depends on html in Makefile |
|
137 | 104 | # sh('make html') |
|
138 | 105 | |
|
139 | 106 | # This is pretty unforgiving: we unconditionally nuke the destination |
|
140 | 107 | # directory, and then copy the html tree in there |
|
141 | 108 | shutil.rmtree(dest, ignore_errors=True) |
|
142 | 109 | shutil.copytree(html_dir, dest) |
|
143 | 110 | shutil.copy(pjoin(pdf_dir, 'ipython.pdf'), pjoin(dest, 'ipython.pdf')) |
|
144 | 111 | |
|
145 | 112 | try: |
|
146 | 113 | cd(pages_dir) |
|
147 | 114 | status = sh2('git status | head -1') |
|
148 | 115 | branch = re.match('\# On branch (.*)$', status).group(1) |
|
149 | 116 | if branch != 'gh-pages': |
|
150 | 117 | e = 'On %r, git branch is %r, MUST be "gh-pages"' % (pages_dir, |
|
151 | 118 | branch) |
|
152 | 119 | raise RuntimeError(e) |
|
153 | 120 | |
|
154 | 121 | sh('git add %s' % tag) |
|
155 | new_rstindex('index.rst', tag, desc) | |
|
156 | sh('python build_index.py') | |
|
157 | sh('git add index.rst index.html') | |
|
158 | sh('git commit -m"Created new doc release, named: %s"' % tag) | |
|
122 | sh('git commit -m"Updated doc release: %s"' % tag) | |
|
159 | 123 | |
|
160 | 124 | print 'Most recent 3 commits:' |
|
161 | 125 | sys.stdout.flush() |
|
162 | 126 | sh('git --no-pager log --oneline HEAD~3..') |
|
163 | 127 | finally: |
|
164 | 128 | cd(startdir) |
|
165 | 129 | |
|
166 | 130 | |
|
167 | 131 | print 'Now verify the build in: %r' % dest |
|
168 | 132 | print "If everything looks good, 'git push'" |
@@ -1,165 +1,167 | |||
|
1 | 1 | .. _documenting-ipython: |
|
2 | 2 | |
|
3 | 3 | ===================== |
|
4 | 4 | Documenting IPython |
|
5 | 5 | ===================== |
|
6 | 6 | |
|
7 | 7 | When contributing code to IPython, you should strive for clarity and |
|
8 | 8 | consistency, without falling prey to a style straitjacket. Basically, |
|
9 | 9 | 'document everything, try to be consistent, do what makes sense.' |
|
10 | 10 | |
|
11 | 11 | By and large we follow existing Python practices in major projects like Python |
|
12 | 12 | itself or NumPy, this document provides some additional detail for IPython. |
|
13 | 13 | |
|
14 | 14 | |
|
15 | 15 | Standalone documentation |
|
16 | 16 | ======================== |
|
17 | 17 | |
|
18 | 18 | All standalone documentation should be written in plain text (``.txt``) files |
|
19 | 19 | using reStructuredText [reStructuredText]_ for markup and formatting. All such |
|
20 | 20 | documentation should be placed in the directory :file:`docs/source` of the |
|
21 | 21 | IPython source tree. Or, when appropriate, a suitably named subdirectory |
|
22 | 22 | should be used. The documentation in this location will serve as the main |
|
23 | 23 | source for IPython documentation. |
|
24 | 24 | |
|
25 | 25 | The actual HTML and PDF docs are built using the Sphinx [Sphinx]_ |
|
26 | 26 | documentation generation tool. Once you have Sphinx installed, you can build |
|
27 | 27 | the html docs yourself by doing: |
|
28 | 28 | |
|
29 | 29 | .. code-block:: bash |
|
30 | 30 | |
|
31 | 31 | $ cd ipython-mybranch/docs |
|
32 | 32 | $ make html |
|
33 | 33 | |
|
34 | 34 | Our usage of Sphinx follows that of matplotlib [Matplotlib]_ closely. We are |
|
35 | 35 | using a number of Sphinx tools and extensions written by the matplotlib team |
|
36 | 36 | and will mostly follow their conventions, which are nicely spelled out in |
|
37 | 37 | their documentation guide [MatplotlibDocGuide]_. What follows is thus a |
|
38 | 38 | abridged version of the matplotlib documentation guide, taken with permission |
|
39 | 39 | from the matplotlib team. |
|
40 | 40 | |
|
41 | 41 | If you are reading this in a web browser, you can click on the "Show Source" |
|
42 | 42 | link to see the original reStricturedText for the following examples. |
|
43 | 43 | |
|
44 | 44 | A bit of Python code:: |
|
45 | 45 | |
|
46 | 46 | for i in range(10): |
|
47 | 47 | print i, |
|
48 | 48 | print "A big number:",2**34 |
|
49 | 49 | |
|
50 | 50 | An interactive Python session:: |
|
51 | 51 | |
|
52 | 52 | >>> from IPython.utils.path import get_ipython_dir |
|
53 | 53 | >>> get_ipython_dir() |
|
54 | 54 | '/home/fperez/.ipython' |
|
55 | 55 | |
|
56 | 56 | An IPython session: |
|
57 | 57 | |
|
58 | 58 | .. code-block:: ipython |
|
59 | 59 | |
|
60 | 60 | In [7]: import IPython |
|
61 | 61 | |
|
62 | 62 | In [8]: print "This IPython is version:",IPython.__version__ |
|
63 | 63 | This IPython is version: 0.9.1 |
|
64 | 64 | |
|
65 | 65 | In [9]: 2+4 |
|
66 | 66 | Out[9]: 6 |
|
67 | 67 | |
|
68 | 68 | |
|
69 | 69 | A bit of shell code: |
|
70 | 70 | |
|
71 | 71 | .. code-block:: bash |
|
72 | 72 | |
|
73 | 73 | cd /tmp |
|
74 | 74 | echo "My home directory is: $HOME" |
|
75 | 75 | ls |
|
76 | 76 | |
|
77 | 77 | Docstring format |
|
78 | 78 | ================ |
|
79 | 79 | |
|
80 | 80 | Good docstrings are very important. Unfortunately, Python itself only provides |
|
81 | 81 | a rather loose standard for docstrings [PEP257]_, and there is no universally |
|
82 | 82 | accepted convention for all the different parts of a complete docstring. |
|
83 | 83 | However, the NumPy project has established a very reasonable standard, and has |
|
84 | 84 | developed some tools to support the smooth inclusion of such docstrings in |
|
85 | 85 | Sphinx-generated manuals. Rather than inventing yet another pseudo-standard, |
|
86 | 86 | IPython will be henceforth documented using the NumPy conventions; we carry |
|
87 | 87 | copies of some of the NumPy support tools to remain self-contained, but share |
|
88 | 88 | back upstream with NumPy any improvements or fixes we may make to the tools. |
|
89 | 89 | |
|
90 | 90 | The NumPy documentation guidelines [NumPyDocGuide]_ contain detailed |
|
91 | 91 | information on this standard, and for a quick overview, the NumPy example |
|
92 | 92 | docstring [NumPyExampleDocstring]_ is a useful read. |
|
93 | 93 | |
|
94 | 94 | |
|
95 | 95 | For user-facing APIs, we try to be fairly strict about following the above |
|
96 | 96 | standards (even though they mean more verbose and detailed docstrings). |
|
97 | 97 | Wherever you can reasonably expect people to do introspection with:: |
|
98 | 98 | |
|
99 | 99 | In [1]: some_function? |
|
100 | 100 | |
|
101 | 101 | the docstring should follow the NumPy style and be fairly detailed. |
|
102 | 102 | |
|
103 | 103 | For purely internal methods that are only likely to be read by others extending |
|
104 | 104 | IPython itself we are a bit more relaxed, especially for small/short methods |
|
105 | 105 | and functions whose intent is reasonably obvious. We still expect docstrings |
|
106 | 106 | to be written, but they can be simpler. For very short functions with a |
|
107 | 107 | single-line docstring you can use something like:: |
|
108 | 108 | |
|
109 | 109 | def add(a, b): |
|
110 | 110 | """The sum of two numbers. |
|
111 | 111 | """ |
|
112 | 112 | code |
|
113 | 113 | |
|
114 | 114 | and for longer multiline strings:: |
|
115 | 115 | |
|
116 | 116 | def add(a, b): |
|
117 | 117 | """The sum of two numbers. |
|
118 | 118 | |
|
119 | 119 | Here is the rest of the docs. |
|
120 | 120 | """ |
|
121 | 121 | code |
|
122 | 122 | |
|
123 | 123 | |
|
124 | 124 | Here are two additional PEPs of interest regarding documentation of code. |
|
125 | 125 | While both of these were rejected, the ideas therein form much of the basis of |
|
126 | 126 | docutils (the machinery to process reStructuredText): |
|
127 | 127 | |
|
128 | 128 | * `Docstring Processing System Framework <http://www.python.org/peps/pep-0256.html>`_ |
|
129 | 129 | * `Docutils Design Specification <http://www.python.org/peps/pep-0258.html>`_ |
|
130 | 130 | |
|
131 | 131 | .. note:: |
|
132 | 132 | |
|
133 | 133 | In the past IPython used epydoc so currently many docstrings still use |
|
134 | 134 | epydoc conventions. We will update them as we go, but all new code should |
|
135 | 135 | be documented using the NumPy standard. |
|
136 | 136 | |
|
137 | 137 | Building and uploading |
|
138 | 138 | ====================== |
|
139 | 139 | The built docs are stored in a separate repository. Through some github magic, |
|
140 | 140 | they're automatically exposed as a website. It works like this: |
|
141 | 141 | |
|
142 | 142 | * You will need to have sphinx and latex installed. In Ubuntu, install |
|
143 | 143 | ``texlive-latex-recommended texlive-latex-extra texlive-fonts-recommended``. |
|
144 | 144 | Install the latest version of sphinx from PyPI (``pip install sphinx``). |
|
145 | 145 | * Ensure that the development version of IPython is the first in your system |
|
146 | 146 | path. You can either use a virtualenv, or modify your PYTHONPATH. |
|
147 | 147 | * Switch into the docs directory, and run ``make gh-pages``. This will build |
|
148 | 148 | your updated docs as html and pdf, then automatically check out the latest |
|
149 | 149 | version of the docs repository, copy the built docs into it, and commit your |
|
150 | 150 | changes. |
|
151 | 151 | * Open the built docs in a web browser, and check that they're as expected. |
|
152 | * (If rebuilding the docs for the development version, it may have duplicated | |
|
153 | the link to the development version in the homepage. Remove this from | |
|
152 | * (When building the docs for a new tagged release, you will have to add its link to | |
|
154 | 153 | index.rst, then run ``python build_index.py`` to update index.html. Commit the |
|
155 | 154 | change.) |
|
156 | 155 | * Upload the docs with ``git push``. This only works if you have write access to |
|
157 | 156 | the docs repository. |
|
157 | * If you are building a version that is not the current dev branch, nor a tagged release, | |
|
158 | then you must run gh-pages.py directly with ``python gh-pages.py <version>``, and *not* | |
|
159 | with ``make gh-pages``. | |
|
158 | 160 | |
|
159 | 161 | .. [reStructuredText] reStructuredText. http://docutils.sourceforge.net/rst.html |
|
160 | 162 | .. [Sphinx] Sphinx. http://sphinx.pocoo.org/ |
|
161 | 163 | .. [MatplotlibDocGuide] http://matplotlib.sourceforge.net/devel/documenting_mpl.html |
|
162 | 164 | .. [PEP257] PEP 257. http://www.python.org/peps/pep-0257.html |
|
163 | 165 | .. [NumPyDocGuide] NumPy documentation guide. http://projects.scipy.org/numpy/wiki/CodingStyleGuidelines |
|
164 | 166 | .. [NumPyExampleDocstring] NumPy example docstring. http://projects.scipy.org/numpy/browser/trunk/doc/EXAMPLE_DOCSTRING.txt |
|
165 | 167 |
General Comments 0
You need to be logged in to leave comments.
Login now