diff options
| -rw-r--r-- | .gitignore | 3 | ||||
| -rw-r--r-- | README.md | 17 | ||||
| -rw-r--r-- | pyproject.toml | 5 | ||||
| -rw-r--r-- | tests/test_stash.py | 9 | ||||
| -rw-r--r-- | ymlstash/__init__.py | 3 | ||||
| -rw-r--r-- | ymlstash/stash.py | 6 |
6 files changed, 43 insertions, 0 deletions
@@ -1 +1,4 @@ +__pycache__/ +.pytest_cache/ + poetry.lock @@ -5,9 +5,26 @@ A simple ORM-like utility for operating on local YAML files via Python dataclass Define a dataclass: ```python +from dataclasses import dataclass + @dataclass class User: name: str age: int active: bool ``` + +Instantiate a new object: + +```python +user = User(name="yuval", age=42, active=True) +``` + +Save it to file: + +```python +from ymlstash import YmlStash + +stash = YmlStash("path/to/db") +stash.save(user) +``` diff --git a/pyproject.toml b/pyproject.toml index 39965ac..ed4e580 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,7 +10,12 @@ license = "MIT" python = "^3.8" pyyaml = "^6.0.1" +[tool.poetry.group.dev.dependencies] +pytest = "^8.2.0" [build-system] requires = ["poetry-core"] build-backend = "poetry.core.masonry.api" + +[tool.pytest.ini_options] +testpaths = ["tests"] diff --git a/tests/test_stash.py b/tests/test_stash.py new file mode 100644 index 0000000..b87c882 --- /dev/null +++ b/tests/test_stash.py @@ -0,0 +1,9 @@ +from pathlib import Path +from ymlstash import YmlStash + + +def test_stash_path(): + stash = YmlStash("foo") + assert stash.path == Path("foo") + stash = YmlStash(Path("foo")) + assert stash.path == Path("foo") diff --git a/ymlstash/__init__.py b/ymlstash/__init__.py index e69de29..337b0b1 100644 --- a/ymlstash/__init__.py +++ b/ymlstash/__init__.py @@ -0,0 +1,3 @@ +from .stash import YmlStash + +__all__ = [YmlStash] diff --git a/ymlstash/stash.py b/ymlstash/stash.py new file mode 100644 index 0000000..f2839ef --- /dev/null +++ b/ymlstash/stash.py @@ -0,0 +1,6 @@ +from pathlib import Path + + +class YmlStash: + def __init__(self, path): + self.path = Path(path) |
