Skip to content

Commit

Permalink
[python] automatically create storage folder
Browse files Browse the repository at this point in the history
  • Loading branch information
javierluraschi committed Nov 26, 2024
1 parent 63fcde6 commit 92e214f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 2.8.1

- Automatically create `.storage` folder when it does not exist

## 2.8.0

- `save()` now stores data under `/.storage`
Expand Down
3 changes: 3 additions & 0 deletions python/hal9/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
import os

def event(name, details):
if not os.path.exists('.storage'):
os.mkdir('.storage')

events_file = '.storage/.events'

if os.path.exists(events_file):
Expand Down
8 changes: 8 additions & 0 deletions python/hal9/iobind.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ def get_hidden(file_path):
return hidden_path
return file_path

def ensure_storage():
if not os.path.exists('.storage'):
os.mkdir('.storage')

def load(name, default):
ensure_storage()

file_path = ".storage/" + name
file_path = find_extension(file_path)
file_path = get_hidden(file_path)
Expand All @@ -66,6 +72,8 @@ def load(name, default):
return contents

def save(name, contents = None, hidden = False, files = None):
ensure_storage()

if not isinstance(name, str):
raise Exception(f"The name parameter in save() must be a string, got {str(type(name))}")

Expand Down
2 changes: 1 addition & 1 deletion python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "hal9"
version = "2.8.0"
version = "2.8.1"
description = ""
authors = ["Javier Luraschi <[email protected]>"]
readme = "README.md"
Expand Down

0 comments on commit 92e214f

Please sign in to comment.