Skip to content

Commit

Permalink
Merge pull request #8 from investigativedata/develop
Browse files Browse the repository at this point in the history
💥 set -> put (v0.0.3)
  • Loading branch information
simonwoerpel committed Feb 2, 2024
2 parents d6166f4 + e68bad2 commit 13455f3
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.0.2
current_version = 0.0.3
commit = True
tag = True
message = 🔖 Bump version: {current_version} → {new_version}
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ smart_write(".local/data", data)
### command line

```bash
anystore --store .cache set foo "bar"
anystore --store .cache put foo "bar"

anystore --store .cache get foo
# "bar"
Expand All @@ -65,7 +65,7 @@ store = Store(uri="s3://mybucket/data", backend_config={"client_kwargs":{
}})

store.get("/2023/1.txt")
store.set("/2023/2.txt", my_data)
store.put("/2023/2.txt", my_data)
```

## Decorate your functions
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.2
0.0.3
2 changes: 1 addition & 1 deletion anystore/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
]


__version__ = "0.0.2"
__version__ = "0.0.3"
8 changes: 4 additions & 4 deletions anystore/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ def cli_get(
smart_write(o, value, mode=mode)


@cli.command("set")
def cli_set(
@cli.command("put")
def cli_put(
key: str,
value: Annotated[
Optional[str],
Expand All @@ -69,12 +69,12 @@ def cli_set(
i: Annotated[str, typer.Option("-i")] = "-",
):
"""
Set content for a `key` to a store
Put content for a `key` to a store
"""
with ErrorHandler():
S = get_store(uri=state["uri"], use_pickle=state["pickle"])
value = value or smart_read(i)
S.set(key, value)
S.put(key, value)


@cli.command("io")
Expand Down
2 changes: 1 addition & 1 deletion anystore/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def _inner(*args, **kwargs):
return store.get(key)
except DoesNotExist:
res = func(*args, **kwargs)
store.set(key, res)
store.put(key, res)
return res

return _inner
Expand Down
2 changes: 1 addition & 1 deletion anystore/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def get(
raise DoesNotExist(f"Key does not exist: `{key}`")
return None

def set(
def put(
self, key: Uri, value: Any, serialization_mode: Mode | None = None, **kwargs
):
serialization_mode = serialization_mode or self.serialization_mode
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "anystore"
version = "0.0.2"
version = "0.0.3"
description = "Store and cache things anywhere"
authors = ["Simon Wörpel <simon.woerpel@pm.me>"]
license = "GPL-3.0"
Expand Down
4 changes: 2 additions & 2 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ def test_cli(tmp_path, fixtures_path):
res = runner.invoke(cli, "--help")
assert res.exit_code == 0

res = runner.invoke(cli, ["--store", str(tmp_path), "set", "foo", "bar"])
res = runner.invoke(cli, ["--store", str(tmp_path), "put", "foo", "bar"])
assert res.exit_code == 0
res = runner.invoke(cli, ["--store", str(tmp_path), "get", "foo"])
assert res.exit_code == 0
assert res.stdout == "bar"

res = runner.invoke(cli, ["--store", "s3://foo/bar", "set", "foo", "bar"])
res = runner.invoke(cli, ["--store", "s3://foo/bar", "put", "foo", "bar"])
assert res.exit_code == 1

res = runner.invoke(cli, ["io", "-i", str(fixtures_path / "lorem.txt")])
Expand Down
8 changes: 4 additions & 4 deletions tests/test_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ def test_store(tmp_path, fixtures_path):
# store and retrieve
store = Store(uri=tmp_path)
key = "test"
store.set(key, "foo")
store.put(key, "foo")
assert store.get(key) == b"foo"
assert store.get(key, mode="r") == "foo"
store.set(key, False)
store.put(key, False)
assert store.get(key) is False

store = Store(uri="s3://anystore")
key = "test"
store.set(key, "foo")
store.put(key, "foo")
assert store.get(key) == b"foo"
store.set(key, False)
store.put(key, False)
assert store.get(key) is False

# don't pickle "external" data
Expand Down

0 comments on commit 13455f3

Please sign in to comment.