Skip to content

Commit

Permalink
Storage hidden (#438)
Browse files Browse the repository at this point in the history
* storage as hidden folder

* Missing updates in changelog

* version update

* missing to update 1 path
  • Loading branch information
LuisGuillen03 authored Oct 28, 2024
1 parent 2481743 commit 23ca5d1
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 13 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Changelog

## 2.8.0

- `save()` now stores data under `/.storage`

## 2.7.10

- Ignore __pycache__ folder and hidden files identified with . at the beginning

## 2.7.9

- fix error message when HAL9_TOKEN is missing

## 2.7.8

- Add support to run chainlit applications
Expand Down
2 changes: 1 addition & 1 deletion apps/browser/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
async def take_screenshot(page):
await asyncio.sleep(5)
await page.screenshot({'path': "screenshot.png"})
shutil.copy("screenshot.png", f"storage/screenshot-{int(time.time())}.png")
shutil.copy("screenshot.png", f".storage/screenshot-{int(time.time())}.png")

async def extract_elements(page):
extract_js = open('extract.js', 'r').read()
Expand Down
2 changes: 1 addition & 1 deletion apps/flux/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def flux_image(prompt, filename):
image = Image.open(BytesIO(data))
image.save(filename, format="JPEG")

shutil.copy(filename, f"storage/{filename}")
shutil.copy(filename, f".storage/{filename}")

prompt = input()
flux_image(prompt, "hal9-flux.jpg")
2 changes: 1 addition & 1 deletion apps/hal9/tools/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def create_image(prompt, filename):

response = requests.get(url)

with open('storage/' + filename, 'wb') as file:
with open('.storage/' + filename, 'wb') as file:
file.write(response.content)

return f"Generated a {filename} that {prompt}"
2 changes: 1 addition & 1 deletion python/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
storage/
.storage/
.chainlit
2 changes: 1 addition & 1 deletion python/hal9/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os

def event(name, details):
events_file = 'storage/.events'
events_file = '.storage/.events'

if os.path.exists(events_file):
with open(events_file, 'r') as file:
Expand Down
10 changes: 5 additions & 5 deletions python/hal9/iobind.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def get_hidden(file_path):
return file_path

def load(name, default):
file_path = "storage/" + name
file_path = ".storage/" + name
file_path = find_extension(file_path)
file_path = get_hidden(file_path)

Expand Down Expand Up @@ -73,7 +73,7 @@ def save(name, contents = None, hidden = False, files = None):
name = "." + name

if files is None:
target_path = './storage'
target_path = './.storage'
files = { name: contents }
else:
target_path = tempfile.mkdtemp()
Expand Down Expand Up @@ -111,15 +111,15 @@ def save(name, contents = None, hidden = False, files = None):
else:
raise Exception(f"Don't know how to save {extension} for {contents_type}")

if target_path != './storage':
if target_path != './.storage':
asset_definition = json.dumps({
"name": name,
"files": [str(file) for file in asset_files]
}, indent=2)
Path('./storage/' + name + '.asset').write_text(asset_definition)
Path('./.storage/' + name + '.asset').write_text(asset_definition)

def ready():
with open("storage/.output", 'w') as file:
with open(".storage/.output", 'w') as file:
file.write("")

def input(prompt = "", extract = False, messages = []):
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.7.11"
version = "2.8.0"
description = ""
authors = ["Javier Luraschi <[email protected]>"]
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion website/learn/code/sd.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def flux_image(prompt, filename):

image = Image.open(BytesIO(response.content))
image.save(filename, format="JPEG")
shutil.copy(filename, f"storage/{filename}")
shutil.copy(filename, f".storage/{filename}")

prompt = input()
flux_image(prompt, "hal9-flux.jpg")
Expand Down
2 changes: 1 addition & 1 deletion website/reference/io.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ Saves as `name` the given `contents`. Useful to share binary files with users.
| hidden | <code>Boolean</code> | `True` to hide file from user, defaults to `False`.
| files | <code>Dictionary</code> | A dictionary mapping additional file names to contents to save.

Saves to `name` file the given `contents` under the `storage` subfolder. An appropriate extension for the `name` will be generated based on the type of `contents`.
Saves to `name` file the given `contents` under the `.storage` subfolder. An appropriate extension for the `name` will be generated based on the type of `contents`.

0 comments on commit 23ca5d1

Please sign in to comment.