Skip to content

Commit 0b2bb9a

Browse files
committed
Improve the docstrings
* Use Google style parameter syntax, not Sphinx/RST style. * Use imperative tense, not present tense, for summary lines.
1 parent 73b6523 commit 0b2bb9a

File tree

9 files changed

+103
-80
lines changed

9 files changed

+103
-80
lines changed

src/appose/__init__.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ def task_listener(event):
236236

237237
def pixi(source: str | Path | None = None) -> PixiBuilder:
238238
"""
239-
Creates a PixiBuilder for Pixi-based environments.
239+
Create a PixiBuilder for Pixi-based environments.
240240
241241
Args:
242242
source: Optional configuration source (file path or URL)
@@ -255,7 +255,7 @@ def pixi(source: str | Path | None = None) -> PixiBuilder:
255255

256256
def mamba(source: str | Path | None = None) -> MambaBuilder:
257257
"""
258-
Creates a MambaBuilder for Micromamba-based environments.
258+
Create a MambaBuilder for Micromamba-based environments.
259259
260260
Args:
261261
source: Optional configuration source (file path or URL)
@@ -274,7 +274,7 @@ def mamba(source: str | Path | None = None) -> MambaBuilder:
274274

275275
def uv(source: str | Path | None = None) -> UvBuilder:
276276
"""
277-
Creates a UvBuilder for uv-based virtual environments.
277+
Create a UvBuilder for uv-based virtual environments.
278278
279279
Args:
280280
source: Optional configuration source (file path or URL)
@@ -293,7 +293,8 @@ def uv(source: str | Path | None = None) -> UvBuilder:
293293

294294
def file(source: str | Path) -> DynamicBuilder:
295295
"""
296-
Creates a DynamicBuilder from a configuration file.
296+
Create a DynamicBuilder from a configuration file.
297+
297298
The builder type will be auto-detected from file content.
298299
299300
Args:
@@ -307,7 +308,8 @@ def file(source: str | Path) -> DynamicBuilder:
307308

308309
def url(source: str) -> DynamicBuilder:
309310
"""
310-
Creates a DynamicBuilder from a URL.
311+
Create a DynamicBuilder from a URL.
312+
311313
The builder type will be auto-detected from content.
312314
313315
Args:
@@ -321,7 +323,8 @@ def url(source: str) -> DynamicBuilder:
321323

322324
def content(content: str) -> DynamicBuilder:
323325
"""
324-
Creates a DynamicBuilder from configuration content.
326+
Create a DynamicBuilder from configuration content.
327+
325328
The builder type will be auto-detected from content syntax.
326329
327330
Args:
@@ -335,7 +338,7 @@ def content(content: str) -> DynamicBuilder:
335338

336339
def wrap(env_dir: str | Path) -> Environment:
337340
"""
338-
Wraps an existing environment directory, auto-detecting its type.
341+
Wrap an existing environment directory, auto-detecting its type.
339342
340343
Args:
341344
env_dir: The directory containing the environment
@@ -362,7 +365,7 @@ def wrap(env_dir: str | Path) -> Environment:
362365

363366
def system(directory: str | Path = Path(".")) -> Environment:
364367
"""
365-
Creates a simple environment using system executables.
368+
Create a simple environment using system executables.
366369
367370
Args:
368371
directory: The working directory (defaults to current directory)
@@ -375,7 +378,7 @@ def system(directory: str | Path = Path(".")) -> Environment:
375378

376379
def custom() -> SimpleBuilder:
377380
"""
378-
Creates a SimpleBuilder for custom environments without package management.
381+
Create a SimpleBuilder for custom environments without package management.
379382
380383
Returns:
381384
A SimpleBuilder instance

src/appose/environment.py

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def __init__(self, base: Path | str, use_system_path: bool = False):
5252

5353
def base(self) -> str:
5454
"""
55-
Returns the base directory of this environment.
55+
Return the base directory of this environment.
5656
5757
Returns:
5858
The absolute path to the base directory
@@ -61,7 +61,7 @@ def base(self) -> str:
6161

6262
def bin_paths(self) -> list[str]:
6363
"""
64-
Returns the list of binary directories to search for executables.
64+
Return the list of binary directories to search for executables.
6565
6666
Returns:
6767
List of binary directory paths
@@ -71,7 +71,7 @@ def bin_paths(self) -> list[str]:
7171

7272
def launch_args(self) -> list[str]:
7373
"""
74-
Returns the launch arguments to prepend when starting worker processes.
74+
Return the launch arguments to prepend when starting worker processes.
7575
7676
Returns:
7777
List of launch arguments
@@ -81,7 +81,7 @@ def launch_args(self) -> list[str]:
8181

8282
def env_vars(self) -> dict[str, str]:
8383
"""
84-
Returns environment variables to set when launching worker processes.
84+
Return environment variables to set when launching worker processes.
8585
8686
Returns:
8787
Dictionary of environment variable names to values
@@ -117,9 +117,14 @@ def python(self) -> Service:
117117
Python scripts asynchronously on its linked process running a
118118
`python_worker`.
119119
120-
:return: The newly created service.
121-
:see: groovy() To create a service for Groovy script execution.
122-
:raises IOError: If something goes wrong starting the worker process.
120+
Returns:
121+
The newly created service.
122+
123+
Raises:
124+
IOError: If something goes wrong starting the worker process.
125+
126+
See Also:
127+
groovy(): To create a service for Groovy script execution.
123128
"""
124129
python_exes = [
125130
"python",
@@ -140,24 +145,30 @@ def groovy(
140145
jvm_args: list[str] | None = None,
141146
) -> Service:
142147
"""
143-
Create a Groovy script service. Groovy (https://groovy-lang.org/)
144-
is a script language for the JVM, capable of running Java bytecode
145-
conveniently and succinctly, as well as downloading and importing
146-
dependencies dynamically at runtime using its Grape subsystem
147-
(https://groovy-lang.org/Grape).
148+
Create a Groovy script service.
149+
150+
Groovy (https://groovy-lang.org/) is a script language for the JVM,
151+
capable of running Java bytecode conveniently and succinctly, as well
152+
as downloading and importing dependencies dynamically at runtime using
153+
its Grape subsystem (https://groovy-lang.org/Grape).
148154
149155
This is a *high level* way to create a service, enabling execution of
150156
Groovy scripts asynchronously on its linked process running a
151157
`GroovyWorker`.
152158
153-
:param class_path:
154-
Additional classpath elements to pass to the JVM
155-
via its `-cp` command line option.
156-
:param jvm_args:
157-
Command line arguments to pass to the JVM invocation (e.g. `-Xmx4g`).
158-
:return: The newly created service.
159-
:see: python() To create a service for Python script execution.
160-
:raises IOError: If something goes wrong starting the worker process.
159+
Args:
160+
class_path: Additional classpath elements to pass to the JVM
161+
via its `-cp` command line option.
162+
jvm_args: Command line arguments to pass to the JVM invocation (e.g. `-Xmx4g`).
163+
164+
Returns:
165+
The newly created service.
166+
167+
Raises:
168+
IOError: If something goes wrong starting the worker process.
169+
170+
See Also:
171+
python(): To create a service for Python script execution.
161172
"""
162173
return self.java(
163174
"org.apposed.appose.GroovyWorker", class_path=class_path, jvm_args=jvm_args
@@ -208,14 +219,17 @@ def service(self, exes: list[str], *args) -> Service:
208219
meaning it accepts requests on stdin and produces responses on
209220
stdout, both formatted according to Appose's assumptions.
210221
211-
:param exes:
212-
List of executables to try for launching the worker process.
213-
:param args:
214-
Command line arguments to pass to the worker process
215-
(e.g. ["-v", "--enable-everything"]).
216-
:return: The newly created service.
217-
:see: groovy() To create a service for Groovy script execution.
218-
:see: python() To create a service for Python script execution.
222+
Args:
223+
exes: List of executables to try for launching the worker process.
224+
args: Command line arguments to pass to the worker process
225+
(e.g. ["-v", "--enable-everything"]).
226+
227+
Returns:
228+
The newly created service.
229+
230+
See Also:
231+
groovy(): To create a service for Groovy script execution.
232+
python(): To create a service for Python script execution.
219233
"""
220234
if not exes:
221235
raise ValueError("No executable given")

src/appose/service.py

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,11 @@ def __init__(self, cwd: str | Path, args: list[str]) -> None:
8282

8383
def debug(self, debug_callback: Callable[[Any], Any]) -> None:
8484
"""
85-
Register a callback function to receive messages
86-
describing current service/worker activity.
85+
Register a callback function to receive messages describing current
86+
service/worker activity.
8787
88-
:param debug_callback:
89-
A function that accepts a single string argument.
88+
Args:
89+
debug_callback: A function that accepts a single string argument.
9090
"""
9191
self._debug_callback = debug_callback
9292

@@ -130,31 +130,35 @@ def task(
130130
) -> "Task":
131131
"""
132132
Create a new task, passing the given script to the worker for execution.
133-
:param script:
134-
The script for the worker to execute in its environment.
135-
:param inputs:
136-
Optional list of key/value pairs to feed into the script as inputs.
137-
:param queue:
138-
Optional queue target. Pass "main" to queue to worker's main thread.
133+
134+
Args:
135+
script: The script for the worker to execute in its environment.
136+
inputs: Optional list of key/value pairs to feed into the script as inputs.
137+
queue: Optional queue target. Pass "main" to queue to worker's main thread.
139138
"""
140139
self.start()
141140
return Task(self, script, inputs, queue)
142141

143142
def syntax(self, syntax: str | ScriptSyntax) -> Service:
144143
"""
145-
Declares the script syntax of this service.
144+
Declare the script syntax of this service.
146145
147-
This value determines which {@link ScriptSyntax} implementation is used
146+
This value determines which ScriptSyntax implementation is used
148147
for generating language-specific scripts.
149148
150149
This method is called directly by Environment.python() and
151150
Environment.groovy() when creating services of those types.
152151
It can also be called manually to support custom languages with
153152
registered ScriptSyntax plugins.
154153
155-
:param syntax: The type identifier (e.g., "python", "groovy").
156-
:return: This service object, for chaining method calls.
157-
:raises: ValueError If no syntax plugin is found for the given type.
154+
Args:
155+
syntax: The type identifier (e.g., "python", "groovy").
156+
157+
Returns:
158+
This service object, for chaining method calls.
159+
160+
Raises:
161+
ValueError: If no syntax plugin is found for the given type.
158162
"""
159163
self._syntax = (
160164
syntax if isinstance(syntax, ScriptSyntax) else syntax_from_name(syntax)
@@ -163,7 +167,7 @@ def syntax(self, syntax: str | ScriptSyntax) -> Service:
163167

164168
def get_var(self, name: str) -> Any:
165169
"""
166-
Retrieves a variable's value from the worker process's global scope.
170+
Retrieve a variable's value from the worker process's global scope.
167171
168172
The variable must have been previously exported using task.export()
169173
to be accessible across tasks.
@@ -186,7 +190,7 @@ def get_var(self, name: str) -> Any:
186190

187191
def put_var(self, name: str, value: Any) -> None:
188192
"""
189-
Sets a variable in the worker process's global scope and exports it
193+
Set a variable in the worker process's global scope and export it
190194
for future use across tasks.
191195
192196
Args:
@@ -205,8 +209,8 @@ def put_var(self, name: str, value: Any) -> None:
205209

206210
def call(self, function: str, *args: Any) -> Any:
207211
"""
208-
Calls a function in the worker process with the given arguments and
209-
returns the result.
212+
Call a function in the worker process with the given arguments and
213+
return the result.
210214
211215
The function must be accessible in the worker's global scope (either
212216
built-in or previously defined/imported).
@@ -236,7 +240,7 @@ def call(self, function: str, *args: Any) -> Any:
236240

237241
def proxy(self, var: str, api: type, queue: str | None = None) -> Any:
238242
"""
239-
Creates a proxy object providing strongly typed access to a remote
243+
Create a proxy object providing strongly typed access to a remote
240244
object in this service's worker process.
241245
242246
Method calls on the proxy are transparently forwarded to the remote
@@ -518,7 +522,7 @@ def wait_for(self) -> "Task":
518522

519523
def result(self) -> Any:
520524
"""
521-
Returns the result of this task.
525+
Return the result of this task.
522526
523527
This is a convenience method that returns outputs["result"].
524528
For tasks that return a single value (e.g., from an expression),

src/appose/shm.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,15 @@ def __init__(self, name: str | None = None, create: bool = False, rsize: int = 0
5353
"""
5454
Create a new shared memory block, or attach to an existing one.
5555
56-
:param name:
57-
The unique name for the requested shared memory, specified as a
58-
string. If create is True (i.e. a new shared memory block) and
59-
no name is given, a novel name will be generated.
60-
:param create:
61-
Whether a new shared memory block is created (True)
62-
or an existing one is attached to (False).
63-
:param rsize:
64-
Requested size in bytes. The true allocated size will be at least
65-
this much, but may be rounded up to the next block size multiple,
66-
depending on the running platform.
56+
Args:
57+
name: The unique name for the requested shared memory, specified as a
58+
string. If create is True (i.e. a new shared memory block) and
59+
no name is given, a novel name will be generated.
60+
create: Whether a new shared memory block is created (True)
61+
or an existing one is attached to (False).
62+
rsize: Requested size in bytes. The true allocated size will be at least
63+
this much, but may be rounded up to the next block size multiple,
64+
depending on the running platform.
6765
"""
6866
super().__init__(name=name, create=create, size=rsize)
6967
self.rsize: int = rsize
@@ -149,10 +147,12 @@ class NDArray:
149147
def __init__(self, dtype: str, shape: list[int], shm: SharedMemory | None = None):
150148
"""
151149
Create an NDArray.
152-
:param dtype: The type of the data elements; e.g. int8, uint8, float32, float64.
153-
:param shape: The dimensional extents; e.g. a stack of 7 image planes
154-
with resolution 512x512 would have shape [7, 512, 512].
155-
:param shm: The SharedMemory containing the array data, or None to create it.
150+
151+
Args:
152+
dtype: The type of the data elements; e.g. int8, uint8, float32, float64.
153+
shape: The dimensional extents; e.g. a stack of 7 image planes
154+
with resolution 512x512 would have shape [7, 512, 512].
155+
shm: The SharedMemory containing the array data, or None to create it.
156156
"""
157157
self.dtype: str = dtype
158158
self.shape: list[int] = shape

src/appose/util/environment.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212

1313
def env_vars(*keys: str) -> dict[str, str]:
1414
"""
15-
Retrieves the specified environment variables from the current process.
15+
Retrieve the specified environment variables from the current process.
16+
1617
Only variables that are set will be included in the returned map.
1718
1819
Args:
@@ -32,7 +33,7 @@ def env_vars(*keys: str) -> dict[str, str]:
3233

3334
def system_path() -> list[str]:
3435
"""
35-
Returns the current process's system PATH as a list of directory paths.
36+
Return the current process's system PATH as a list of directory paths.
3637
3738
This splits the PATH environment variable on the platform-specific separator
3839
(colon on Unix-like systems, semicolon on Windows).

src/appose/util/filepath.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
def location(c: type) -> Path | None:
1818
"""
19-
Gets the path to the module file containing the given class/type.
19+
Get the path to the module file containing the given class/type.
2020
2121
Args:
2222
c: The class/type whose file path should be discerned.
@@ -239,7 +239,8 @@ def ensure_directory(file: Path) -> None:
239239

240240
def appose_envs_dir() -> str:
241241
"""
242-
Gets the top-level directory for Appose-managed environments.
242+
Get the top-level directory for Appose-managed environments.
243+
243244
Defaults to ~/.local/share/appose but can be overridden by setting
244245
the APPOSE_ENVS_DIR environment variable.
245246

0 commit comments

Comments
 (0)