Skip to content

Commit 00ead55

Browse files
committed
libkirk: fix all wrong docstrings
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
1 parent 5ad34e5 commit 00ead55

17 files changed

Lines changed: 408 additions & 255 deletions

libkirk/channels/ltx.py

Lines changed: 43 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
class Request:
2525
"""
26-
LTX request.
26+
LTX client request.
2727
"""
2828

2929
ERROR = 0xFF
@@ -51,14 +51,16 @@ def __init__(self) -> None:
5151
@property
5252
def completed(self) -> bool:
5353
"""
54-
If True the request has been completed.
54+
:return: True if request has been completed. False otherwise.
55+
:rtype: bool
5556
"""
5657
return self._completed
5758

5859
def add_done_coro(self, coro: Callable) -> None:
5960
"""
6061
Add done event to request.
61-
:param coro: called when request is done
62+
63+
:param coro: Called when request is completed.
6264
:type coro: Callable
6365
"""
6466
self._done_coro.append(coro)
@@ -78,14 +80,18 @@ async def _raise_complete(self, *args: Any) -> None:
7880
async def pack(self) -> bytes:
7981
"""
8082
Pack LTX request into bytes.
83+
84+
:return: Request bytes.
85+
:rtype: bytes
8186
"""
8287
raise NotImplementedError()
8388

8489
async def feed(self, message: List[Any]) -> None:
8590
"""
8691
Feed request queue with data and return when the request
8792
has been completed.
88-
:param message: processed msgpack message
93+
94+
:param message: Processed msgpack message.
8995
:type message: list
9096
"""
9197
raise NotImplementedError()
@@ -158,12 +164,12 @@ class env(Request):
158164

159165
def __init__(self, slot_id: int, key: str, value: str) -> None:
160166
"""
161-
:param slot_id: command table ID. Can be None if we want to apply
162-
the same environment variable to all executions
167+
:param slot_id: Command table ID. Can be None if we want to apply
168+
the same environment variable to all executions.
163169
:type slot_id: int
164-
:param key: key of the environment variable
170+
:param key: Key of the environment variable.
165171
:type key: str
166-
:param value: value of the environment variable
172+
:param value: Value of the environment variable.
167173
:type value: str
168174
"""
169175
super().__init__()
@@ -207,10 +213,10 @@ class cwd(Request):
207213

208214
def __init__(self, slot_id: int, path: str) -> None:
209215
"""
210-
:param slot_id: command table ID. Can be None if we want to apply
216+
:param slot_id: Command table ID. Can be None if we want to apply
211217
the same current working directory to all executions
212218
:type slot_id: int
213-
:param path: current working path
219+
:param path: Current working path.
214220
:type path: str
215221
"""
216222
super().__init__()
@@ -256,7 +262,7 @@ class get_file(Request):
256262

257263
def __init__(self, path: str) -> None:
258264
"""
259-
:param path: path of the file to read
265+
:param path: Path of the file to read.
260266
:type path: str
261267
"""
262268
super().__init__()
@@ -471,22 +477,24 @@ class LTX:
471477
"""
472478
This class communicates with LTX by processing given requests.
473479
Typical usage is the following:
474-
```
475-
async with LTX(infile, outfile) as ltx:
476-
# create requests
477-
request1 = Requests.execute("echo 'hello world' > myfile")
478-
request2 = Requests.get_file("myfile")
479-
480-
# set the complete event
481-
request1.add_done_coro(exec_complete_handler)
482-
request2.add_done_coro(get_file_complete_handler)
483-
484-
# send request
485-
ltx.send([request1, request2])
486-
487-
# process events output
488-
...
489-
```
480+
481+
.. code-block:: python
482+
483+
async with LTX(infile, outfile) as ltx:
484+
# create requests
485+
request1 = Requests.execute("echo 'hello world' > myfile")
486+
request2 = Requests.get_file("myfile")
487+
488+
# set the complete event
489+
request1.add_done_coro(exec_complete_handler)
490+
request2.add_done_coro(get_file_complete_handler)
491+
492+
# send request
493+
ltx.send([request1, request2])
494+
495+
# process events output
496+
...
497+
490498
"""
491499

492500
BUFFSIZE = 1 << 21
@@ -575,7 +583,8 @@ async def send(self, requests: List[Request]) -> None:
575583
"""
576584
Send requests to LTX service. The order is preserved during
577585
requests execution.
578-
:param requests: list of requests to send
586+
587+
:param requests: List of requests to send.
579588
:type requests: list
580589
"""
581590
if not requests:
@@ -599,6 +608,12 @@ async def gather(self, requests: List[Request]) -> Dict[Request, Any]:
599608
Gather multiple requests and wait for the response, then return all
600609
rquests' replies inside a dictionary that maps requests with their
601610
reply.
611+
612+
:param requests: List of requests to process.
613+
:type requests: list(Request)
614+
:return: Dictionary containing Request as keys and data from completed
615+
requests as values.
616+
:rtype: dict
602617
"""
603618
req_len = len(requests)
604619
replies = {}

libkirk/com.py

Lines changed: 49 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@
1818

1919
class IOBuffer:
2020
"""
21-
IO stdout buffer. The API is similar to ``IO`` types.
21+
IO stdout buffer. The API is similar to IO types.
2222
"""
2323

2424
async def write(self, data: str) -> None:
2525
"""
26-
Write ``data`` inside the buffer.
26+
Write data inside the buffer.
27+
28+
:param data: Data to write.
29+
:type data: str
2730
"""
2831
raise NotImplementedError()
2932

@@ -38,22 +41,24 @@ class ComChannel(Plugin):
3841
@property
3942
def parallel_execution(self) -> bool:
4043
"""
41-
If True, communication supports commands parallel execution.
44+
:return: If True, communication supports commands parallel execution.
45+
:rtype: bool
4246
"""
4347
raise NotImplementedError()
4448

4549
@property
4650
async def active(self) -> bool:
4751
"""
48-
Return True if communication is active. False otherwise.
52+
:return: Return True if communication is active. False otherwise.
53+
:rtype: bool
4954
"""
5055
raise NotImplementedError()
5156

5257
async def communicate(self, iobuffer: Optional[IOBuffer] = None) -> None:
5358
"""
5459
Start communication.
5560
56-
:param iobuffer: buffer used to write stdout
61+
:param iobuffer: Buffer used to write stdout.
5762
:type iobuffer: IOBuffer
5863
"""
5964
raise NotImplementedError()
@@ -62,15 +67,17 @@ async def stop(self, iobuffer: Optional[IOBuffer] = None) -> None:
6267
"""
6368
Stop communication.
6469
65-
:param iobuffer: buffer used to write stdout
70+
:param iobuffer: Buffer used to write stdout.
6671
:type iobuffer: IOBuffer
6772
"""
6873
raise NotImplementedError()
6974

7075
async def ping(self) -> float:
7176
"""
7277
Send a ping request and verify how much reply takes in seconds.
73-
:returns: float
78+
79+
:return: Time between ping and pong.
80+
:rtype: float
7481
"""
7582
raise NotImplementedError()
7683

@@ -84,48 +91,52 @@ async def run_command(
8491
"""
8592
Run a command.
8693
87-
:param command: command to execute
94+
:param command: Command to execute.
8895
:type command: str
89-
:param cwd: current working directory
96+
:param cwd: Current working directory.
9097
:type cwd: str
91-
:param env: environment variables
98+
:param env: Environment variables.
9299
:type env: dict
93-
:param iobuffer: buffer used to write stdout
100+
:param iobuffer: Buffer used to write stdout.
94101
:type iobuffer: IOBuffer
95-
:returns: dictionary containing command execution information
102+
:return: Dictionary containing information about the executed command.
103+
104+
.. code-block:: python
96105
97-
{
98-
"command": <str>,
99-
"returncode": <int>,
100-
"stdout": <str>,
101-
"exec_time": <float>,
102-
}
106+
{
107+
"command": <str>,
108+
"returncode": <int>,
109+
"stdout": <str>,
110+
"exec_time": <float>,
111+
}
103112
104-
If None is returned, then callback failed.
113+
If None is returned, then callback has failed.
114+
:rtype: dict
105115
"""
106116
raise NotImplementedError()
107117

108118
async def fetch_file(self, target_path: str) -> bytes:
109119
"""
110120
Fetch file and return its content.
111121
112-
:param target_path: path of the file to download from target
122+
:param target_path: Path of the file to download from target.
113123
:type target_path: str
114-
:returns: bytes contained in target_path
124+
:return: Data contained in target_path.
125+
:rtype: bytes
115126
"""
116127
raise NotImplementedError()
117128

118129
async def ensure_communicate(
119130
self, iobuffer: Optional[IOBuffer] = None, retries: int = 10
120131
) -> None:
121132
"""
122-
Ensure that ``communicate`` is completed, retrying as many times we
123-
want in case of ``KirkException`` error. After each error, the
133+
Ensure that communicate is completed, retrying as many times we
134+
want in case of KirkException error. After each error, the
124135
communication is stopped and a new communication is performed.
125136
126-
:param iobuffer: buffer used to write stdout
137+
:param iobuffer: Buffer used to write stdout.
127138
:type iobuffer: IOBuffer
128-
:param retries: number of times we retry to communicate
139+
:param retries: Number of times we retry to communicate.
129140
:type retries: int
130141
"""
131142
retries = max(retries, 1)
@@ -144,11 +155,13 @@ async def ensure_communicate(
144155
def discover(path: str, extend: bool = True) -> None:
145156
"""
146157
Discover all ComChannel implementations inside `path`.
147-
:param path: directory where searching for channel implementations
158+
159+
:param path: Directory where searching for channel implementations.
148160
:type path: str
149-
:param extend: if True, it will add new discovered channels on top of the
161+
:param extend: If True, it will add new discovered channels on top of the
150162
ones already found. If False, previous discovered channels will be
151163
cleared.
164+
:rtype: bool
152165
"""
153166
global _COM
154167

@@ -161,7 +174,8 @@ def discover(path: str, extend: bool = True) -> None:
161174

162175
def get_channels() -> List[ComChannel]:
163176
"""
164-
:return: list of loaded ComChannel implementations.
177+
:return: List of loaded ComChannel implementations.
178+
:rtype: list(ComChannel)
165179
"""
166180
global _COM
167181
# pyrefly: ignore[bad-return]
@@ -170,14 +184,16 @@ def get_channels() -> List[ComChannel]:
170184

171185
def clone_channel(name: str, new_name: str) -> Plugin:
172186
"""
173-
Clone a channel implementation named ``name`` and rename it with
174-
``new_name``. The new plugin will be registered with the other
187+
Clone a channel implementation named name and rename it with
188+
new_name. The new plugin will be registered with the other
175189
plugins.
176-
:param name: plugin name
190+
191+
:param name: Plugin name.
177192
:type name: str
178-
:param new_name: new cloned plugin name
193+
:param new_name: New cloned plugin name.
179194
:type new_name: str
180-
:return: new plugin object
195+
:return: New plugin object.
196+
:rtype: Plugin
181197
"""
182198
global _COM
183199

0 commit comments

Comments
 (0)