widgetti / solara

A Pure Python, React-style Framework for Scaling Your Jupyter and Web Apps
https://solara.dev
MIT License
1.9k stars 141 forks source link

feature request: solara app as cli app #647

Closed Jhsmit closed 6 months ago

Jhsmit commented 6 months ago

I've developed a python package which includes a solara web application. I would like my users to be able to do the following:

pip install mypackage
mypackage run --config confile_file.yaml

Which would then launch the solara web app with the specified config file.

On the python side it would be something like this:

import click
import solara
from mypackage import Page, cfg

@click.command()
@click.option('--config', help='path to config file to use')
def run(config):
    cfg.load(config)
    solara.run_app(Page)

At the moment what is do is solara run path/to/mypackage/app.py --config config.yaml and then catch the argument in app.py but 1) users who install mypackage won't have direct access to the correct path since it'll be somewhere in site-packages 2) I cannot provide any --help for the config option 3) there can be conficts between solara and mypackage options

maartenbreddels commented 6 months ago

What about the following?

Similar to https://github.com/widgetti/solara/blob/defe64c22216b01b930b7a05744c807f5b7f6e7c/solara/__main__.py#L726 you split everything before and after --.

Everything before -- you pass to yourself, and everything after it, you pass to solara. This way you can do

$ mypackage run --config config_file.yaml -- port 8777

Does that help you?

Jhsmit commented 6 months ago

Yes, then how would i start solara from my entry point? something like this?

import subprocess

def run(config, *args):
   subprocess.run("solara", "run", "path/to/app.py", *args)
maartenbreddels commented 6 months ago

You can do it in the same process, you can call it like we do here: https://github.com/widgetti/solara/blob/defe64c22216b01b930b7a05744c807f5b7f6e7c/solara/__main__.py#L730

maartenbreddels commented 6 months ago

Could you add (perma) links here to your code once you implemented this, I think more people would want this!

Jhsmit commented 6 months ago

yes, if I remember when i make it public. hopefully soon

Jhsmit commented 2 months ago

I've now implemented this here

You can run with dont-fret serve --config config_file.yaml and it also accepts any solara option such as dont-fret serve --config config_file.yaml --port 8881