Textualize / textual-serve

Serve Textual apps locally
MIT License
186 stars 8 forks source link

Make it easier to serve an app installed with `uv`, `pipx`, etc. #20

Closed MG-MW closed 2 months ago

MG-MW commented 2 months ago

I'm usually not in an environment, where I have a proper terminal available. It would be nice, if I could open textual apps, installed via uv, pipx, rye, etc. on localhost and port forward via SSH to my local browser easily.

Right now I can do something like this:

uv run --with "harlequin[odbc, postgres]" --with "duckdb<1.1" --with "textual-serve" -- \
    python -c "from textual_serve.server import Server; Server('python -m harlequin',port=12345).serve()"

The command gets even longer if I want to provide arguments to the textual app. I could work around this by write a few bash functions, but it would be nice, if there was a way to maybe do something like

uv run --with "harlequin[odbc, postgres]" --with "duckdb<1.1" --with "textual-serve" -- \
   textual-serve --port=12345 --cmd 'harlequin path/to/my/duck.db'

or

uv run --with "harlequin[odbc, postgres]" --with "duckdb<1.1" --with "textual-serve" -- \
   textual-serve --port=12345 -- \
   harlequin path/to/my/duck.db
willmcgugan commented 2 months ago

If you install textual-dev you can use textual serve. Does that help?

MG-MW commented 2 months ago

Oh, thanks! That's it exactly.

I can now just use an alias like this

alias harlequin_local='uvx --quiet --from textual-dev --with "harlequin[odbc, postgres]" --with "duckdb<1.1" -- \
   textual serve --port=12345 --command \
   harlequin'

and run it like this

harlequin_local path/to/my/duck.db

I cannot install it as a tool, but uv is fast enough, so it doesn't really matter.