Skip to content

Commit dd35ff7

Browse files
authored
Merge pull request #48 from bcdev/use_google_docstrings
Ensure Google-style docstrings
2 parents 8edef6d + 16cb394 commit dd35ff7

File tree

5 files changed

+46
-38
lines changed

5 files changed

+46
-38
lines changed

zappend/api.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ def zappend(
5050
5151
Args:
5252
slices: An iterable that yields slice objects. A slice object is
53-
either a ``str``, ``xarray.Dataset``, ``SliceSource`` or a factory
54-
function that returns a slice object. If ``str`` is used,
53+
either a `str`, `xarray.Dataset`, `SliceSource` or a factory
54+
function that returns a slice object. If `str` is used,
5555
it is interpreted as local dataset path or dataset URI.
5656
If a URI is used, protocol-specific parameters apply, given by
57-
configuration parameter ``slice_storage_options``.
57+
configuration parameter `slice_storage_options`.
5858
config: Processor configuration.
59-
May be a file path or URI, a ``dict``, ``None``, or a sequence of
59+
May be a file path or URI, a `dict`, `None`, or a sequence of
6060
the aforementioned. If a sequence is used, subsequent configurations
6161
are incremental to the previous ones.
6262
kwargs: Additional configuration parameters.

zappend/fsutil/transaction.py

+32-24
Original file line numberDiff line numberDiff line change
@@ -28,47 +28,55 @@
2828

2929

3030
class Transaction:
31-
"""
32-
A filesystem transaction.
31+
"""A filesystem transaction.
3332
3433
Its main motivation is implementing transactional Zarr dataset
3534
modifications, because this does not exist for Zarr yet (2024-01), see
3635
https://github.com/zarr-developers/zarr-python/issues/247.
3736
38-
The ``Transaction`` class is used to observe changes to a given target
39-
directory *target_dir*.
37+
The `Transaction` class is used to observe changes to a given target
38+
directory `target_dir`.
4039
4140
Changes must be explicitly registered using a "rollback callback"
4241
function that is provided as the result of using the
43-
transaction instance as a context manager:::
42+
transaction instance as a context manager:
4443
44+
```python
4545
with Transaction(target_dir, temp_dir) as rollback_cb:
4646
# emit rollback actions here
47+
```
4748
4849
The following actions are supported:
4950
50-
* ``rollback_cb("delete_dir", path)`` if a directory has been created.
51-
* ``rollback_cb("delete_file", path)`` if a file has been created.
52-
* ``rollback_cb("replace_file", path, original_data)`` if a directory has
51+
* `rollback_cb("delete_dir", path)` if a directory has been created.
52+
* `rollback_cb("delete_file", path)` if a file has been created.
53+
* `rollback_cb("replace_file", path, original_data)` if a directory has
5354
been changed.
5455
55-
Reported paths must be relative to *target_dir*. The empty path ``""``
56-
refers to *target_dir* itself.
56+
Reported paths must be relative to `target_dir`. The empty path `""`
57+
refers to `target_dir` itself.
5758
5859
When entering the context, a lock file will be created which prevents
59-
other transactions to modify *target_dir*. The lock file will be placed
60+
other transactions to modify `target_dir`. The lock file will be placed
6061
next to *target_dir* and its name is the filename of *target_dir* with a
61-
``.lock`` extension. The lock file will be removed on context exit.
62-
63-
:param target_dir: The target directory that is subject to this
64-
transaction. All paths emitted to the rollback callback must be
65-
relative to *target_dir*. The directory may or may not exist yet.
66-
:param temp_dir: Temporary directory in which a unique subdirectory
67-
will be created that will be used to collect
68-
rollback data during the transaction. The directory must exist.
69-
:param disable_rollback: Disable rollback entirely.
70-
No rollback data will be written, however a lock file will still
71-
be created for the duration of the transaction.
62+
`.lock` extension. The lock file will be removed on context exit.
63+
64+
Args:
65+
target_dir: The target directory that is subject to this
66+
transaction. All paths emitted to the rollback callback must be
67+
relative to *target_dir*. The directory may or may not exist yet.
68+
temp_dir: Temporary directory in which a unique subdirectory
69+
will be created that will be used to collect
70+
rollback data during the transaction. The directory must exist.
71+
disable_rollback: Disable rollback entirely.
72+
No rollback data will be written, however a lock file will still
73+
be created for the duration of the transaction.
74+
Raises:
75+
OSError: If the target is locked or the lock could not be removed.
76+
TypeError: If the returned callback is not used appropriately.
77+
ValueError: If instances of this class are not used as a context
78+
manager, or if the returned callback is not used appropriately,
79+
and in some other cases.
7280
"""
7381

7482
def __init__(
@@ -109,7 +117,7 @@ def __enter__(self):
109117

110118
lock_file = self._lock_file
111119
if lock_file.exists():
112-
raise IOError(f"Target is locked: {lock_file.uri}")
120+
raise OSError(f"Target is locked: {lock_file.uri}")
113121
lock_file.write(self._rollback_dir.uri)
114122

115123
if not self._disable_rollback:
@@ -209,5 +217,5 @@ def _add_rollback_action(
209217
def _assert_entered_ctx(self):
210218
if not self._entered_ctx:
211219
raise ValueError(
212-
"Transaction instance" " must be used with the 'with' statement"
220+
"Transaction instance must be used with the 'with' statement"
213221
)

zappend/metadata.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def to_dict(self):
7979
class VariableMetadata:
8080
"""Metadata for a dataset variable.
8181
82-
Arguments:
82+
Args:
8383
dims: The names of the variable's dimensions.
8484
shape: The sizes of the variable's dimensions. This is a derived value,
8585
because the dimension size are given by the variable's dataset.
@@ -119,7 +119,7 @@ def __init__(
119119
):
120120
"""Dataset metadata including metadata for variables.
121121
122-
Arguments:
122+
Args:
123123
sizes: A mapping from dimension name to dimension size.
124124
variables: A mapping from variable name to variable metadata.
125125
attrs: Arbitrary metadata attributes.
@@ -142,7 +142,7 @@ def assert_compatible_slice(
142142
"""Assert a given slice dataset's metadata is compatible with this
143143
(target) dataset's metadata.
144144
145-
Arguments:
145+
Args:
146146
slice_metadata: The slice dataset metadata.
147147
append_dim: The name of the append dimension.
148148
@@ -191,7 +191,7 @@ def from_dataset(cls, dataset: xr.Dataset, config: dict[str, Any] | None = None)
191191
Encoding information found in dataset variables is normalized to valid
192192
Zarr encoding.
193193
194-
Arguments:
194+
Args:
195195
dataset: A dataset
196196
config: Optional processor configuration
197197

zappend/processor.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Processor:
2727
2828
Args:
2929
config: Processor configuration.
30-
May be a file path or URI, a ``dict``, ``None``, or a sequence of
30+
May be a file path or URI, a `dict`, `None`, or a sequence of
3131
the aforementioned. If a sequence is used, subsequent configurations
3232
are incremental to the previous ones.
3333
kwargs: Additional configuration parameters.
@@ -44,7 +44,7 @@ def __init__(self, config: ConfigLike = None, **kwargs):
4444

4545
def process_slices(self, slices: Iterable[SliceObj]):
4646
"""Process the given *slices*.
47-
Passes each slice in *slices* to the ``process_slice()`` method.
47+
Passes each slice in *slices* to the `process_slice()` method.
4848
4949
Args:
5050
slices: Slice objects.
@@ -57,11 +57,11 @@ def process_slice(self, slice_obj: SliceObj, slice_index: int = 0):
5757
"""Process a single slice object *slice_obj*.
5858
5959
A slice object is
60-
either a ``str``, ``xarray.Dataset``, ``SliceSource`` or a factory
61-
function that returns a slice object. If ``str`` is used,
60+
either a `str`, `xarray.Dataset`, `SliceSource`` or a factory
61+
function that returns a slice object. If `str` is used,
6262
it is interpreted as local dataset path or dataset URI.
6363
If a URI is used, protocol-specific parameters apply, given by
64-
configuration parameter ``slice_storage_options``.
64+
configuration parameter `slice_storage_options`.
6565
6666
If there is no target yet, just config and slice:
6767

zappend/profiler.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def __init__(self, profiling_config: dict[str, Any] | str | bool | None):
1818
Intended to be used as context manager.
1919
For internal use only; this class does not belong to the API.
2020
21-
Arguments:
21+
Args:
2222
profiling_config: The validated(!) "profiling" setting from
2323
the configuration.
2424
"""

0 commit comments

Comments
 (0)