Skip to content

Commit

Permalink
Cleaned up docstrings in the YAML storage plugin.
Browse files Browse the repository at this point in the history
  • Loading branch information
jesper-friis committed Aug 13, 2023
1 parent 986f13a commit fa9e6c2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions bindings/python/tests/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,18 @@
expected = """\
DLite storage plugin for YAML.
Opens `uri`.
Opens `location`.
Arguments:
uri: A fully resolved URI to the PostgreSQL database.
location: Path to YAML file.
options: Supported options:
- `mode`: Mode for opening. Valid values are:
- `a`: Append to existing file or create new file (default).
- `r`: Open existing file for read-only.
- `w`: Truncate existing file or create new file.
- `soft7`: Whether to save using SOFT7 format.
- `single`: Whether the input is assumed to be in single-entity form.
The default (`"auto"`) will try to infer it automatically.
If "auto" (default) the form will be inferred automatically.
"""
s = dlite.Storage('yaml', 'inst.yaml', options='mode=a')
assert s.help().strip() == expected.strip()
Expand Down
16 changes: 8 additions & 8 deletions storages/python/python-storage-plugins/yaml.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""A simple demonstrage of a DLite storage plugin written in Python."""
"""DLite YAML storage plugin written in Python."""
import os
from typing import TYPE_CHECKING

Expand All @@ -16,31 +16,31 @@ class yaml(dlite.DLiteStorageBase):
"""DLite storage plugin for YAML."""
_pyyaml = pyyaml # Keep a reference to pyyaml to have it during shutdown

def open(self, uri: str, options=None):
"""Opens `uri`.
def open(self, location: str, options=None):
"""Opens `location`.
Arguments:
uri: A fully resolved URI to the PostgreSQL database.
location: Path to YAML file.
options: Supported options:
- `mode`: Mode for opening. Valid values are:
- `a`: Append to existing file or create new file (default).
- `r`: Open existing file for read-only.
- `w`: Truncate existing file or create new file.
- `soft7`: Whether to save using SOFT7 format.
- `single`: Whether the input is assumed to be in single-entity form.
The default (`"auto"`) will try to infer it automatically.
If "auto" (default) the form will be inferred automatically.
"""
self.options = Options(
options, defaults="mode=a;soft7=true;single=auto"
)
self.readable = "r" in self.options.mode
self.writable = "r" != self.options.mode
self.generic = True
self.uri = uri
self.location = location
self.flushed = False # whether buffered data has been written to file
self._data = {} # data buffer
if self.options.mode in ("r", "a", "append"):
with open(uri, "r") as f:
with open(location, "r") as f:
data = pyyaml.safe_load(f)
if data:
self._data = data
Expand All @@ -53,7 +53,7 @@ def open(self, uri: str, options=None):
def flush(self):
"""Flush cached data to storage."""
if self.writable and not self.flushed:
with open(self.uri, "w") as f:
with open(self.location, "w") as f:
self._pyyaml.safe_dump(
self._data,
f,
Expand Down

0 comments on commit fa9e6c2

Please sign in to comment.