Skip to content

Commit 0c10799

Browse files
authored
Docs update for 0.8.0 - part 1 (#196)
* Start API Reference page Documentation of keep.running, keep.presenting and dbus related things. * Switch from napoleon to numpydoc. This looks nicer for few reasons. (1) The napoleon adds bullet points to parameter lists. These are unwanted. (2) Napoleon adds an en dash between parameter type and description, which is unwanted. (3) Napoleon makes description start from the same line as the parameter name and type. This is also unwanted. * Update Sphinx~=5.0 -> ~=7.0 * Update myst_parser~=1.0.0 -> ~=2.0.0 * Add bunch of cross-links.
1 parent b674e27 commit 0c10799

File tree

7 files changed

+146
-79
lines changed

7 files changed

+146
-79
lines changed

docs/source/api-reference.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# API Reference
2+
3+
```{eval-rst}
4+
5+
.. autosummary::
6+
7+
wakepy.keep.running
8+
wakepy.keep.presenting
9+
wakepy.DbusAdapter
10+
11+
Wakepy Modes
12+
-------------
13+
.. autofunction:: wakepy.keep.running
14+
.. autofunction:: wakepy.keep.presenting
15+
16+
DBus Adapter
17+
-------------
18+
Dbus adapters are an advanced concept of wakepy. They would be used in such a case where wants to use other D-Bus python library than the default (which is `jeepney <https://jeepney.readthedocs.io/>`_).
19+
20+
.. autoclass:: wakepy.DbusAdapter
21+
:members:
22+
23+
.. autoclass:: wakepy.core.DbusMethodCall
24+
:members:
25+
26+
.. autoclass:: wakepy.core.DbusMethod
27+
:members:
28+
:exclude-members: count, index
29+
30+
31+
```

docs/source/conf.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@
2222
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
2323
# ones.
2424
extensions = [
25+
# Markdown (MyST) format support for Sphinx
2526
"myst_parser",
26-
# TODO: Check also autodoc2
27-
# https://myst-parser.readthedocs.io/en/latest/syntax/code_and_apis.html#sphinx-autodoc2
28-
"sphinx.ext.autodoc",
29-
"sphinx.ext.napoleon",
27+
# Adds support for NumPy style docstrings for autodoc
28+
"numpydoc",
3029
# Sphinx Design adds some sphinx directives for UI components
3130
# See: https://sphinx-design.readthedocs.io/
3231
"sphinx_design",
3332
# Add copy button to code blocks
3433
# See: https://sphinx-copybutton.readthedocs.io/
3534
"sphinx_copybutton",
35+
"sphinx.ext.autosummary",
3636
]
3737

3838
# Needed by sphinx_design
@@ -61,15 +61,9 @@
6161
# Ref2: https://jupyterbook.org/en/stable/content/figures.html#numbered-references
6262
numfig = True
6363

64-
65-
# Add a border around Examples. Might or might not look good, depending on the
66-
# used theme.
67-
# See: https://www.sphinx-doc.org/en/master/usage/extensions/napoleon.html#confval-napoleon_use_admonition_for_examples
68-
napoleon_use_admonition_for_examples = True
69-
napoleon_google_docstring = False
70-
7164
# Add any paths that contain templates here, relative to this directory.
7265
templates_path = ["_templates"]
66+
html_static_path = ["_static"]
7367

7468
# List of patterns, relative to source directory, that match files and
7569
# directories to ignore when looking for source files.
@@ -95,3 +89,8 @@
9589
"pygment_light_style": "friendly",
9690
"pygment_dark_style": "lightbulb",
9791
}
92+
93+
# Whether to create a Sphinx table of contents for the lists of class methods
94+
# and attributes. If a table of contents is made, Sphinx expects each entry to
95+
# have a separate page. True by default.
96+
numpydoc_class_members_toctree = False

docs/source/index.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,9 @@ The table above only considers the *automatic* actions (go to sleep, start scree
7878
:numbered: -1
7979
:titlesonly:
8080
81-
quickstart
8281
modes
8382
methods-reference
84-
83+
api-reference
8584
cli-api
8685
```
8786

docs/source/modes.md

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,8 @@ with keep.running() as m:
3131
(keep-running-mode)=
3232
## keep.running
3333

34-
35-
**Does keep.running prevent manually putting system to sleep?** All the methods, if not otherwise specified, only prevent the *automatic, idle timer timeout based* sleeping, so it is still possible to put system to sleep by selecting Suspend/Sleep from a menu, closing the laptop lid or pressing a power key, for example. One exception is systemd mask method on Linux, which prevents suspend altogether.
36-
37-
**Can I lock my computer after entered `keep.running` mode?**: Yes, and you probably should, if you're not near your computer. The programs will continue execution regardless of the lock.
34+
While `keep.running` mode is activated, the system may not automatically go to sleep (or
35+
suspend) meaning that programs will continue running and can use CPU.
3836

3937

4038
| Platform | DE | Method |
@@ -43,13 +41,35 @@ with keep.running() as m:
4341
| MacOS | * | [caffeinate](#keep-running-macos-caffeinate) |
4442
| Windows | * | [SetThreadExecutionState](#keep-running-windows-stes) |
4543

44+
45+
Does keep.running prevent manually putting system to sleep?
46+
: Only the automatical, idle timer timeout based sleep / suspend is prevented; Will not
47+
prevent user manually entering sleep from a menu, by closing a laptop lid or by pressing
48+
a power button, for example.
49+
50+
Can I lock my computer after entered `keep.running` mode?
51+
: Yes, and you probably should, if you're not near your computer. The program will
52+
continue execution regardless of the lock.
53+
54+
What about automatical lockscreen / screensaver?
55+
: The system may still automatically log out user, enable lockscreen or turn off the
56+
display. Automatic lock screen is not guaranteed, but it is not prevented in any way.
57+
58+
What happens id the process holding the lock dies?
59+
: The lock is automatically removed. There are no methods in keep.running mode which for
60+
example would perform system-wide configuration changes or anything which would need
61+
manual reversal.
62+
63+
64+
4665
(keep-presenting-mode)=
4766
## keep.presenting
4867

68+
While `keep.presenting` mode is activated, the system may not automatically go to sleep (or
69+
suspend) meaning that programs will continue running and can use CPU. In addition to
70+
that, automatic start of screensaver & screenlock are prevented, meaning that you can
71+
show content in the `keep.presenting` mode.
4972

50-
**Does keep.presenting prevent manually putting system to sleep?** All the methods, if not otherwise specified, only prevent the *automatic, idle timer timeout based* sleeping and screensaver/screenlock, so it is still possible to put system to sleep by selecting Suspend/Sleep from a menu, closing the laptop lid or pressing a power key, for example. It is also possible to manually start the screenlock/screensaver while presenting mode is on.
51-
52-
**Is my computer locked automatically in `keep.presenting` mode?**: No. Entering a screenlock automatically would stop presenting the content.
5373

5474
| Platform | DE | Method |
5575
| -------- | --------------- | --------------------------------------------------------------------------- |
@@ -58,6 +78,21 @@ with keep.running() as m:
5878
| MacOS | * | [caffeinate](#keep-presenting-macos-caffeinate) |
5979
| Windows | * | [SetThreadExecutionState](#keep-presenting-windows-stes) |
6080

81+
Does keep.presenting prevent manually putting system to sleep?
82+
: Only the automatical, idle timer timeout based sleep / suspend is prevented; Will not
83+
prevent user manually entering sleep from a menu, by closing a laptop lid or by pressing
84+
a power button, for example.
85+
86+
Can I still manually start lockscreen / screensaver?
87+
: Yes. Only the idle timer based screensaver / lockscreen is prevented. Note that
88+
manually entering screensaver does not deactivate the mode.
89+
90+
91+
What happens id the process holding the lock dies?
92+
: The lock is automatically removed. There are no methods in keep.presenting mode which for
93+
example would perform system-wide configuration changes or anything which would need
94+
manual reversal.
95+
6196

6297
## General questions
6398
**What if the process holding the lock dies?**: The lock is automatically removed.

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ classifiers = [
3232

3333
[project.optional-dependencies]
3434
doc = [
35-
"sphinx~=5.0",
36-
"sphinx_design~=0.4.1",
35+
"sphinx~=7.0",
36+
"sphinx_design>0.4.1",
3737
"sphinx-copybutton~=0.5.2",
38-
"myst-parser~=1.0.0",
38+
"myst-parser~=2.0.0",
3939
"sphinx-book-theme~=1.1.0",
4040
]
4141
dev = [

wakepy/core/dbus.py

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -79,23 +79,23 @@ class DbusMethod(NamedTuple):
7979
signature: str | None
8080
"""The signature for the method input parameters.
8181
82-
The types are: (Conventional name, ASCII type-code, meaning)
82+
The types are: (Conventional name, ASCII type-code, meaning)::
8383
84-
BYTE y (121) Unsigned 8-bit integer
85-
BOOLEAN b (98) Boolean value: 0 is false, 1 is true
86-
INT16 n (110) Signed 16-bit integer
87-
UINT16 q (113) Unsigned 16-bit integer
88-
INT32 i (105) Signed 32-bit integer
89-
UINT32 u (117) Unsigned 32-bit integer
90-
INT64 x (120) Signed 64-bit integer
91-
UINT64 t (116) Unsigned 64-bit integer
92-
DOUBLE d (100) IEEE 754 double-precision floating point
93-
UNIX_FD h (104) Unsigned 32-bit integer representing an index into an
94-
out-of-band array of file descriptors, transferred via some
95-
platform-specific mechanism
96-
STRING s (115) String
84+
BYTE y (121) Unsigned 8-bit integer
85+
BOOLEAN b (98) Boolean value: 0 is false, 1 is true
86+
INT16 n (110) Signed 16-bit integer
87+
UINT16 q (113) Unsigned 16-bit integer
88+
INT32 i (105) Signed 32-bit integer
89+
UINT32 u (117) Unsigned 32-bit integer
90+
INT64 x (120) Signed 64-bit integer
91+
UINT64 t (116) Unsigned 64-bit integer
92+
DOUBLE d (100) IEEE 754 double-precision floating point
93+
UNIX_FD h (104) Unsigned 32-bit integer representing an index into an
94+
out-of-band array of file descriptors, transferred via some
95+
platform-specific mechanism
96+
STRING s (115) String
9797
98-
Ref: https://dbus.freedesktop.org/doc/dbus-specification.html
98+
Ref: `dbus-specification <https://dbus.freedesktop.org/doc/dbus-specification.html>`_
9999
"""
100100
params: Optional[tuple[str, ...]] = None
101101
"""The names of the input arguments defined by the `signature`.
@@ -165,11 +165,18 @@ def of(
165165
)
166166

167167
def completely_defined(self) -> bool:
168+
"""Check if the DbusMethod is completely defined."""
168169
return all(
169170
x is not None for x in (self.service, self.path, self.interface, self.bus)
170171
)
171172

172173
def to_call(self, args: CallArguments = None) -> DbusMethodCall:
174+
"""Convert to :class:`~wakepy.core.DbusMethodCall`.
175+
176+
Parameters
177+
----------
178+
args:
179+
The arguments to the D-Bus Method call."""
173180
return DbusMethodCall(self, args)
174181

175182

@@ -188,7 +195,7 @@ class DbusMethodCall:
188195
"""
189196

190197
args: Tuple[Any, ...]
191-
"""The method args (positional). This is used"""
198+
"""The method args (positional)."""
192199

193200
def __init__(self, method: DbusMethod, args: CallArguments = None):
194201
"""Converts the `args` argument is converted into a tuple and makes it
@@ -201,9 +208,9 @@ def __init__(self, method: DbusMethod, args: CallArguments = None):
201208
self.args = self._args_as_tuple(args, method)
202209

203210
def get_kwargs(self) -> dict[str, Any] | None:
204-
"""Get a keyword-argument representation (dict) of the self.args. If
205-
the DbusMethod (self.method) does not have params defined, returns
206-
None."""
211+
"""Get a keyword-argument representation (dict) of the
212+
:attr:`~wakepy.core.DbusMethodCall.args`. If the DbusMethod
213+
(self.method) does not have params defined, returns None."""
207214
if self.method.params is None:
208215
return None
209216
assert isinstance(self.method.params, tuple)
@@ -262,18 +269,24 @@ class DbusAdapter:
262269
subclass is usually an implementation for a DbusAdapter using single
263270
python (dbus-)library.
264271
265-
When subclassing, implement the .process(call) method. The call
266-
(DbusMethodCall) tells which bus to use (session/system/custom addr), and
267-
therefore the connection must be created within the .process() call (this
268-
can of course be cached).
272+
When subclassing, implement the :func:`~wakepy.DbusAdapter.process`
273+
method.
269274
270275
The __init__() should not take any arguments, and it may raise any subtype
271276
of Exception, which simply means that the DbusAdapter may not be used. The
272277
Exception will be omitted if using the high-level API of wakepy.
273278
"""
274279

275280
def process(self, call: DbusMethodCall):
276-
...
281+
"""Processes a :class:`~wakepy.core.DbusMethodCall`.
282+
283+
Parameters
284+
----------
285+
call: DbusMethodCall
286+
Represents a D-Bus method call with its arguments. As it tells which
287+
bus to use (session / system / custom addr), the connection must be
288+
created within the :func:`~wakepy.DbusAdapter.process` call (this may
289+
of course be cached)."""
277290

278291

279292
def get_dbus_adapter(

wakepy/modes/keep.py

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,7 @@ def running(
2323
) -> Mode:
2424
"""Create a wakepy mode (a context manager) for keeping programs running.
2525
26-
Properties
27-
----------
28-
1) The system may not go to sleep meaning that programs will continue
29-
running and can use CPU.
30-
2) Does prevent only the automatical, idle timer timeout based sleep /
31-
suspend; Will not prevent user manually entering sleep from a menu, by
32-
closing a laptop lid or by pressing a power button, for example.
33-
3) System may still automatically log out user, enable lockscreen
34-
or turn off the display.
35-
4) If the process holding the lock dies, the lock is automatically removed.
36-
There are no methods in keep.running mode which for example would
37-
perform system-wide configuration changes or anything which would need
38-
manual reversal.
39-
40-
Usage
41-
-----
42-
43-
```
44-
with keep.running() as k:
45-
# do something that takes a long time.
46-
```
26+
:ref:`Documentation of keep.running mode. <keep-running-mode>`
4727
4828
Parameters
4929
----------
@@ -73,22 +53,29 @@ def running(
7353
and may occur only once in the priority order, and cannot be part of a
7454
set. If asterisk is not part of the `methods_priority`, it will be
7555
added as the last element automatically.
76-
on_fail:
56+
on_fail: str | callable
7757
Determines what to do in case mode activation fails. Valid options are:
7858
"error", "warn", "pass" and a callable. If the option is "error",
7959
raises wakepy.ActivationError. Is selected "warn", issues warning. If
8060
"pass", does nothing. If `on_fail` is a callable, it must take one
8161
positional argument: result, which is an instance of ActivationResult.
8262
The ActivationResult contains more detailed information about the
8363
activation process.
84-
dbus_adapter:
85-
Optional argument which can be used to define a customer DBus adapter.
64+
dbus_adapter: class or sequence of classes
65+
Optional argument which can be used to define a custom DBus adapter.
66+
If given, should be a subclass of :class:`~wakepy.DbusAdapter`, or a
67+
list of such.
8668
8769
Returns
8870
-------
8971
keep_running_mode: Mode
9072
The context manager for keeping a system running.
9173
74+
75+
Examples
76+
--------
77+
>>> with keep.running() as k:
78+
>>> # do something that takes a long time.
9279
"""
9380
return create_mode(
9481
modename=ModeName.KEEP_RUNNING,
@@ -110,12 +97,7 @@ def presenting(
11097
"""Create a wakepy mode (a context manager) for keeping a system running
11198
and showing content.
11299
113-
Usage:
114-
115-
```
116-
with keep.presenting() as k:
117-
# do something that takes a long time.
118-
```
100+
:ref:`Documentation of keep.presenting mode. <keep-presenting-mode>`
119101
120102
Parameters
121103
----------
@@ -153,13 +135,21 @@ def presenting(
153135
positional argument: result, which is an instance of ActivationResult.
154136
The ActivationResult contains more detailed information about the
155137
activation process.
156-
dbus_adapter:
157-
Optional argument which can be used to define a customer DBus adapter.
138+
dbus_adapter: class or sequence of classes
139+
Optional argument which can be used to define a custom DBus adapter.
140+
If given, should be a subclass of :class:`~wakepy.DbusAdapter`, or a
141+
list of such.
158142
159143
Returns
160144
-------
161145
keep_presenting_mode: Mode
162146
The context manager for keeping a system presenting content.
147+
148+
Examples
149+
--------
150+
>>> with keep.presenting() as k:
151+
>>> # do something that takes a long time.
152+
163153
"""
164154
return create_mode(
165155
modename=ModeName.KEEP_PRESENTING,

0 commit comments

Comments
 (0)