Separate docstrings into command/documentation parts.

This commit is contained in:
Florian Bruhin 2014-07-16 20:09:41 +02:00
parent a2c9e099f0
commit f7304298ab
8 changed files with 49 additions and 4 deletions

View File

@ -346,6 +346,11 @@ http://legacy.python.org/dev/peps/pep-0008/[PEP8] and the https://google-stylegu
http://legacy.python.org/dev/peps/pep-0257/[PEP257] and the google guidelines. http://legacy.python.org/dev/peps/pep-0257/[PEP257] and the google guidelines.
* Class docstrings have additional _Attributes:_, _Class attributes:_ and * Class docstrings have additional _Attributes:_, _Class attributes:_ and
_Signals:_ sections, method/function docstrings have an _Emit:_ section. _Signals:_ sections, method/function docstrings have an _Emit:_ section.
* In docstrings of command handlers (registered via `@cmdutils.register`), the
description should be split into two parts by using `//` - the first part is
the description of the command like it will appear in the documentation, the
second part is "internal" documentation only relevant to people reading the
sourcecode.
+ +
Example for a class docstring: Example for a class docstring:
+ +
@ -368,6 +373,12 @@ Example for a method/function docstring:
---- ----
"""Do something special. """Do something special.
This will do something.
//
It is based on http://example.com/.
Args: Args:
foo: ... foo: ...

View File

@ -616,6 +616,8 @@ class Application(QApplication):
def debug_pyeval(self, s): def debug_pyeval(self, s):
"""Evaluate a python string and display the results as a webpage. """Evaluate a python string and display the results as a webpage.
//
We have this here rather in utils.debug so the context of eval makes We have this here rather in utils.debug so the context of eval makes
more sense and because we don't want to import much stuff in the utils. more sense and because we don't want to import much stuff in the utils.

View File

@ -619,6 +619,8 @@ class CommandDispatcher:
The command will be run in a shell, so you can use shell features like The command will be run in a shell, so you can use shell features like
redirections. redirections.
//
We use subprocess rather than Qt's QProcess here because of it's We use subprocess rather than Qt's QProcess here because of it's
shell=True argument and because we really don't care about the process shell=True argument and because we really don't care about the process
anymore as soon as it's spawned. anymore as soon as it's spawned.
@ -706,6 +708,8 @@ class CommandDispatcher:
def open_editor(self): def open_editor(self):
"""Open an external editor with the current form field. """Open an external editor with the current form field.
//
We use QProcess rather than subprocess here because it makes it a lot We use QProcess rather than subprocess here because it makes it a lot
easier to execute some code as soon as the process has been finished easier to execute some code as soon as the process has been finished
and do everything async. and do everything async.

View File

@ -287,6 +287,8 @@ class ConfigManager(QObject):
def get_wrapper(self, sectname, optname): def get_wrapper(self, sectname, optname):
"""Get the value from a section/option. """Get the value from a section/option.
//
Wrapper for the get-command to output the value in the status bar. Wrapper for the get-command to output the value in the status bar.
""" """
try: try:
@ -331,6 +333,8 @@ class ConfigManager(QObject):
def set_wrapper(self, sectname, optname, value): def set_wrapper(self, sectname, optname, value):
"""Set an option. """Set an option.
//
Wrapper for self.set() to output exceptions in the status bar. Wrapper for self.set() to output exceptions in the status bar.
""" """
try: try:
@ -344,6 +348,8 @@ class ConfigManager(QObject):
def set_temp_wrapper(self, sectname, optname, value): def set_temp_wrapper(self, sectname, optname, value):
"""Set a temporary option. """Set a temporary option.
//
Wrapper for self.set() to output exceptions in the status bar. Wrapper for self.set() to output exceptions in the status bar.
""" """
try: try:

View File

@ -34,7 +34,9 @@ import qutebrowser.commands.utils as cmdutils
@cmdutils.register(debug=True, name='debug-set-trace') @cmdutils.register(debug=True, name='debug-set-trace')
def set_trace(): def set_trace():
"""Set a tracepoint in the Python debugger that works with Qt. """Break into the debugger in the shell.
//
Based on http://stackoverflow.com/a/1745965/2085149 Based on http://stackoverflow.com/a/1745965/2085149
""" """

View File

@ -148,7 +148,12 @@ class MainWindow(QWidget):
@cmdutils.register(instance='mainwindow', name=['quit', 'q'], nargs=0) @cmdutils.register(instance='mainwindow', name=['quit', 'q'], nargs=0)
def close(self): def close(self):
"""Extend close() so we can register it as a command.""" """Quit qutebrowser.
//
Extend close() so we can register it as a command.
"""
super().close() super().close()
def resizeEvent(self, e): def resizeEvent(self, e):

View File

@ -171,7 +171,9 @@ class Prompter:
@cmdutils.register(instance='mainwindow.status.prompt.prompter', hide=True, @cmdutils.register(instance='mainwindow.status.prompt.prompter', hide=True,
modes=['prompt']) modes=['prompt'])
def prompt_accept(self): def prompt_accept(self):
"""Accept the prompt. """Accept the current prompt.
//
This executes the next action depending on the question mode, e.g. asks This executes the next action depending on the question mode, e.g. asks
for the password or leaves the mode. for the password or leaves the mode.

View File

@ -41,7 +41,8 @@ def parse_docstring(func):
Return: Return:
A (short_desc, long_desc, arg_descs) tuple. A (short_desc, long_desc, arg_descs) tuple.
""" """
State = enum('short', 'desc', 'arg_start', 'arg_inside') State = enum('short', 'desc', 'desc_hidden', 'arg_start', 'arg_inside',
'misc')
doc = inspect.getdoc(func) doc = inspect.getdoc(func)
lines = doc.splitlines() lines = doc.splitlines()
@ -61,8 +62,20 @@ def parse_docstring(func):
elif cur_state == State.desc: elif cur_state == State.desc:
if line.startswith('Args:'): if line.startswith('Args:'):
cur_state = State.arg_start cur_state = State.arg_start
elif line.startswith('Emit:') or line.startswith('Raise:'):
cur_state = State.misc
elif line.strip() == '//':
cur_state = State.desc_hidden
elif line.strip(): elif line.strip():
long_desc.append(line.strip()) long_desc.append(line.strip())
elif cur_state == State.misc:
if line.startswith('Args:'):
cur_state = State.arg_start
else:
pass
elif cur_state == State.desc_hidden:
if line.startswith('Args:'):
cur_state = State.arg_start
elif cur_state == State.arg_start: elif cur_state == State.arg_start:
cur_arg_name, argdesc = line.split(':', maxsplit=1) cur_arg_name, argdesc = line.split(':', maxsplit=1)
cur_arg_name = cur_arg_name.strip() cur_arg_name = cur_arg_name.strip()