Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to read files from Starlark #1045

Merged
merged 6 commits into from
Apr 24, 2024
Merged

Add the ability to read files from Starlark #1045

merged 6 commits into from
Apr 24, 2024

Conversation

rohansingh
Copy link
Member

@rohansingh rohansingh commented Apr 18, 2024

Starlark scripts can now load arbitrary files from their bundle and read them using a Python-like open() and read() API. A readall() convenience function is also provided.

The examples have been updated to use this functionality where relevant. For example:

load("icon.png", icon = "file")

BTC_ICON = icon.readall()

Supporting changes:

  1. The pixlet render command can now accept an entire directory containing multiple Starlark files and static resources.

  2. The pixlet private bundle command can now accept an entire directory. It will load the applet contained in the directory, and bundle any files that the applet itself loads. Not that "private" is a misnomer, this command is used by both private and community apps.

  3. App manifests no longer contain a fileName attribute, since an app may contain multiple files. packageName has been removed as well, since it is no longer used for anything.

@rohansingh rohansingh force-pushed the rohan/bundle branch 2 times, most recently from 34c290f to ac842a5 Compare April 18, 2024 17:47
@rohansingh rohansingh changed the title runtime: Add the ability to read files from Starlark Add the ability to read files from Starlark Apr 18, 2024
@rohansingh rohansingh requested a review from matslina April 18, 2024 18:00
Starlark scripts can now load arbitrary files from their bundle and read
them using a Python-like `open()` and `read()` API. A `readall()`
convenience function is also provided.

The examples have been updated to use this functionality where relevant.
For example:

```
load("icon.png", icon = "file")

BTC_ICON = icon.readall()
```

The `pixlet render` command can now accept an entire directory
containing multiple Starlark files and static resources.
Remove the `open()` and `read()` functions, so the only way to read a
file is `readall()`.

If there is demand for the other methods, we can add them back later.
@jmanske
Copy link

jmanske commented Apr 24, 2024

Holy smokes @rohansingh

When is this going live? Could be game changer for apps that need to render a lot of images.

@rohansingh
Copy link
Member Author

@jmanske Ideally this week. Agreed, it will be great for images and other assets. The primary motivation is to be able to include audio files for Tidbyt Gen 2.

@rohansingh
Copy link
Member Author

Offline review from @matslina:

  • Simplify API to only have readall(), since seeking isn't necessary
  • Implement serve and bundle.

Deferred for future PR's:

  • Have stuff like render.Image could accept a file object, so it’s easy for devs to not do redundant calls to readall. Thinking of apps that load 100 assets, but only show 2 per run depending on config.
  • Figure out how the file object will be used in the case of app audio, where we probably don’t want the pixlet app to readall the data on every run. Should files have some internal attribute asset_id set to myapp/icon.mp3 or equivalent, that then gets passed on to firmware?
  • Figure out how built-in audio files are referenced. Would user load("tidbyt/skip_forward.mp3", meeting_starts_audio = "file")?

`fs.FS` always uses slash-separated paths, even on Windows. So we should
be manipulating those paths with `path`, not `filepath`.
It appears that `nlepage/go-tarfs` correctly supports Windows by [using
`path` instead of `filepath`][1].

[1]: nlepage/go-tarfs#7
@rohansingh rohansingh merged commit fe59c71 into main Apr 24, 2024
7 checks passed
@rohansingh rohansingh deleted the rohan/bundle branch April 24, 2024 10:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants