Skip to content

Commit 4f9f8bd

Browse files
committed
Initial code.
1 parent 565f7e2 commit 4f9f8bd

File tree

8 files changed

+97
-30
lines changed

8 files changed

+97
-30
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,3 @@ _trial_temp/
1010
apidocs/
1111
*.egg-info
1212
.eggs
13-
docs/source/help.txt

docs/source/conf.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
3131
# ones.
3232
extensions = [
33-
"sphinx_rtd_theme", "sphinx.ext.intersphinx"
33+
"sphinx_rtd_theme",
34+
"sphinx.ext.intersphinx",
35+
"pydoctor.sphinx_ext.help_output",
3436
]
3537

3638
# Add any paths that contain templates here, relative to this directory.
@@ -43,7 +45,7 @@
4345

4446
# Configure intersphinx magic
4547
intersphinx_mapping = {
46-
'pydoctor': ('https://pydoctor.readthedocs.io/api/', None),
48+
#'pydoctor': ('https://pydoctor.readthedocs.io/api/', None),
4749
'twisted': ('https://twistedmatrix.com/documents/current/api/', None),
4850
}
4951

@@ -57,12 +59,4 @@
5759
# Add any paths that contain custom static files (such as style sheets) here,
5860
# relative to this directory. They are copied after the builtin static files,
5961
# so a file named "default.css" will overwrite the builtin "default.css".
60-
html_static_path = ['_static']
61-
62-
# -- Automatically generate the Full help text in Shpinx build ---------------
63-
import pathlib
64-
import subprocess
65-
subprocess.run(
66-
["pydoctor", "--help"],
67-
stdout=(pathlib.Path(__file__).parent / "help.txt").open('w')
68-
)
62+
html_static_path = []

docs/source/help.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
Full help
2-
=========
1+
Command line options
2+
====================
33

4-
.. include:: help.txt
4+
Below are the available command line options.
5+
6+
.. help_output::

docs/source/usage.rst

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ Usage
66
Most common options
77
-------------------
88

9-
The following exemple uses all most common options to generate ``pydoctor``'s own API docs under the ``docs/api`` folder.
10-
It will add a link to the project website in all pages header, show a link to source code aside every documented elements and resolve links to standard library objects.
9+
The following exemple uses all most common options to generate ``pydoctor``'s own API docs under the ``docs/api`` folder.
10+
It will add a link to the project website in all pages header, show a link to source code aside every documented elements and resolve links to standard library objects.
1111

1212
::
1313

@@ -22,12 +22,12 @@ It will add a link to the project website in all pages header, show a link to so
2222
--docformat=epytext \
2323
--intersphinx=https://docs.python.org/3/objects.inv
2424

25-
.. note:: This exemple assume that you have cloned and installed ``pydoctor`` and you are running the ``pydoctor`` build from Unix and the current directory is the root folder of the Python project.
25+
.. note:: This exemple assume that you have cloned and installed ``pydoctor`` and you are running the ``pydoctor`` build from Unix and the current directory is the root folder of the Python project.
2626

27-
.. warning:: The ``--html-viewsource-base`` argument should point to a tag or a commit SHA rather than a branch since line
27+
.. warning:: The ``--html-viewsource-base`` argument should point to a tag or a commit SHA rather than a branch since line
2828
numbers aren't going to match otherwise when commits are added to the branch after the documentation has been published.
2929

30-
Publish your documentation
30+
Publish your documentation
3131
--------------------------
3232

3333
``pydoctor`` output are static HTML pages without no extra server-side support.
@@ -84,8 +84,8 @@ Here is an exemple to automatically generate and publish your documentation with
8484
publish_dir: ./apidocs
8585
commit_message: "Generate pydoctor documentation"
8686

87-
.. note:: As mentionned in the ``actions-gh-pages`` `documentation`__, the first workflow run won't actually publish the documentation to Github pages.
88-
Github pages needs to be enabled afterwards in the repo settings, select ``gh-pages`` branch, then re-run your workflow.
87+
.. note:: As mentionned in the ``actions-gh-pages`` `documentation`__, the first workflow run won't actually publish the documentation to Github pages.
88+
Github pages needs to be enabled afterwards in the repo settings, select ``gh-pages`` branch, then re-run your workflow.
8989

9090
The website we'll be at https://(user).github.io/(repo)/
9191

@@ -99,16 +99,16 @@ Here is an exemple to automatically generate and publish your documentation with
9999
Document part of your package
100100
-----------------------------
101101

102-
Sometimes, only a couple classes or modules are part of your public API, not all classes and modules need to be documented.
102+
Sometimes, only a couple classes or modules are part of your public API, not all classes and modules need to be documented.
103103

104104
You can choose to document only a couple classes or modules with the following cumulative configuration option::
105105

106106
--html-subject=pydoctor.zopeinterface.ZopeInterfaceSystem
107107

108-
This will generate only ``pydoctor.zopeinterface.ZopeInterfaceSystem.html`` and ``objects.inv`` (and CSS and JS files of course).
109-
The ``--add-package`` argument still needs to be passed, ``--html-subject`` will act like a filter.
108+
This will generate only ``pydoctor.zopeinterface.ZopeInterfaceSystem.html`` and ``objects.inv`` (and CSS and JS files of course).
109+
The ``--add-package`` argument still needs to be passed, ``--html-subject`` will act like a filter.
110110

111-
.. warning:: The ``index.html`` and other index files won't be generated, you need to link to the specific HTML page.
111+
.. warning:: The ``index.html`` and other index files won't be generated, you need to link to the specific HTML page.
112112

113113
Sphinx Integration
114114
------------------
@@ -150,7 +150,7 @@ __ https://www.sphinx-doc.org/en/master/usage/extensions/intersphinx.html
150150

151151
Link to elements :py:func:`with custom text <twisted:twisted.web.client.urlunparse>` with::
152152

153-
:py:func:`with custom text <twisted:twisted.web.client.urlunparse>`
153+
:py:func:`with custom text <twisted:twisted.web.client.urlunparse>`
154154

155155
Link to elements with default label :py:class:`twisted:twisted.web.client.HTTPDownloader` with::
156156

@@ -179,7 +179,7 @@ You can subclass the :py:class:`pydoctor:pydoctor.zopeinterface.ZopeInterfaceSys
179179

180180
--system-class=mylib._pydoctor.CustomSystem
181181

182-
System class allows you to dynamically show/hide classes or methods.
182+
System class allows you to dynamically show/hide classes or methods.
183183
This is also used by the Twisted project to handle deprecation.
184184

185185
See the `Twisted custom class documentation <https://twistedmatrix.com/documents/current/api/twisted.python._pydoctor.TwistedSystem.html>`_. Naviguate to the source code for a better overview.
@@ -192,7 +192,7 @@ Use custom HTML templates
192192
Currently, custom HTLM templates needs to be handled with some "monkeypatch" that will selectively use the appropriate templates.
193193

194194
See the `Twisted custom class documentation <https://twistedmatrix.com/documents/current/api/twisted.python._release.APIBuilder.html>`_. Naviguate to the source code for a better overview.
195-
The key thing is to apply a patch to the :py:func:`pydoctor:pydoctor.templatewriter.util.templatefile` function before the build.
195+
The key thing is to apply a patch to the :py:func:`pydoctor:pydoctor.templatewriter.util.templatefile` function before the build.
196196

197197
.. note:: Not fully documented, prone to break
198198

@@ -203,4 +203,4 @@ You can subclass the :py:class:`pydoctor:pydoctor.templatewriter.writer.Template
203203

204204
--html-writer=mylib._pydoctor.CustomTemplateWriter
205205

206-
.. note:: Not fully documented, prone to break
206+
.. note:: Not fully documented, prone to break

pydoctor/driver.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,10 @@ def p(msg):
365365
for fn in sorted(system.docstring_syntax_errors):
366366
p(' '+fn)
367367

368+
if system.warnings:
369+
# Update exit code if the run has produced warnings.
370+
exitcode = 1
371+
368372
if options.makeintersphinx:
369373
if not options.makehtml:
370374
subjects = system.rootobjects
@@ -384,4 +388,5 @@ def p(msg):
384388
import pdb
385389
pdb.post_mortem(sys.exc_info()[2])
386390
raise
391+
387392
return exitcode

pydoctor/sphinx_ext/__init__.py

Whitespace-only changes.

pydoctor/sphinx_ext/help_output.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""
2+
Produce the pydoctor help output to be included in the documentation.
3+
"""
4+
from docutils import nodes
5+
from sphinx.util.docutils import SphinxDirective
6+
7+
from contextlib import redirect_stdout
8+
from io import StringIO
9+
from pydoctor.driver import parse_args
10+
11+
12+
class HelpOutputDirective(SphinxDirective):
13+
14+
# this enables content in the directive
15+
has_content = True
16+
17+
def run(self):
18+
19+
stream = StringIO()
20+
try:
21+
with redirect_stdout(stream):
22+
parse_args(['--help'])
23+
except SystemExit:
24+
pass
25+
26+
text = ['pydoctor --help'] + stream.getvalue().splitlines()[1:]
27+
return [nodes.literal_block(text='\n'.join(text))]
28+
29+
30+
def setup(app):
31+
app.add_directive('help_output', HelpOutputDirective)
32+
33+
return {
34+
'version': '0.1',
35+
'parallel_read_safe': True,
36+
'parallel_write_safe': True,
37+
}
38+
39+

tox.ini

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,31 @@ commands =
6868
--cache-dir="{toxworkdir}/mypy_cache" \
6969
{tty:--pretty:} \
7070
{posargs:pydoctor}
71+
72+
73+
[testenv:apidocs]
74+
description = Build only the API documentation
75+
76+
whitelist_externals =
77+
cat
78+
test
79+
commands =
80+
pydoctor \
81+
--add-package=pydoctor \
82+
--project-name=pydoctor \
83+
--project-url=https://github.com/twisted/pydoctor/ \
84+
--html-viewsource-base=https://github.com/twisted/pydoctor/tree/20.7.2 \
85+
--html-output=build/apidocs \
86+
--project-base-dir="{toxinidir}" \
87+
--docformat=epytext \
88+
--intersphinx=https://docs.python.org/3/objects.inv \
89+
--make-html
90+
91+
92+
[testenv:docs]
93+
description = Build the full documentation
94+
95+
extras = docs
96+
97+
commands =
98+
sphinx-build -aE -b html {toxinidir}/docs/source {toxinidir}/build/docs

0 commit comments

Comments
 (0)