diff --git a/reflex/reflex.py b/reflex/reflex.py index 1901ef94c..9612dc7c9 100644 --- a/reflex/reflex.py +++ b/reflex/reflex.py @@ -65,20 +65,12 @@ def main( pass -@cli.command() -def init( - name: str = typer.Option( - None, metavar="APP_NAME", help="The name of the app to initialize." - ), - template: constants.Templates.Kind = typer.Option( - constants.Templates.Kind.BASE.value, - help="The template to initialize the app with.", - ), - loglevel: constants.LogLevel = typer.Option( - config.loglevel, help="The log level to use." - ), +def _init( + name: str, + template: constants.Templates.Kind, + loglevel: constants.LogLevel, ): - """Initialize a new Reflex app in the current directory.""" + """Initialize a new Reflex app in the given directory.""" # Set the log level. console.set_log_level(loglevel) @@ -114,28 +106,32 @@ def init( @cli.command() -def run( - env: constants.Env = typer.Option( - constants.Env.DEV, help="The environment to run the app in." +def init( + name: str = typer.Option( + None, metavar="APP_NAME", help="The name of the app to initialize." ), - frontend: bool = typer.Option( - False, "--frontend-only", help="Execute only frontend." - ), - backend: bool = typer.Option(False, "--backend-only", help="Execute only backend."), - frontend_port: str = typer.Option( - config.frontend_port, help="Specify a different frontend port." - ), - backend_port: str = typer.Option( - config.backend_port, help="Specify a different backend port." - ), - backend_host: str = typer.Option( - config.backend_host, help="Specify the backend host." + template: constants.Templates.Kind = typer.Option( + constants.Templates.Kind.BASE.value, + help="The template to initialize the app with.", ), loglevel: constants.LogLevel = typer.Option( config.loglevel, help="The log level to use." ), ): - """Run the app in the current directory.""" + """Initialize a new Reflex app in the current directory.""" + _init(name, template, loglevel) + + +def _run( + env: constants.Env, + frontend: bool = True, + backend: bool = True, + frontend_port: str = str(get_config().frontend_port), + backend_port: str = str(get_config().backend_port), + backend_host: str = config.backend_host, + loglevel: constants.LogLevel = config.loglevel, +): + """Run the app in the given directory.""" # Set the log level. console.set_log_level(loglevel) @@ -219,6 +215,32 @@ def run( backend_cmd(backend_host, int(backend_port)) +@cli.command() +def run( + env: constants.Env = typer.Option( + constants.Env.DEV, help="The environment to run the app in." + ), + frontend: bool = typer.Option( + False, "--frontend-only", help="Execute only frontend." + ), + backend: bool = typer.Option(False, "--backend-only", help="Execute only backend."), + frontend_port: str = typer.Option( + config.frontend_port, help="Specify a different frontend port." + ), + backend_port: str = typer.Option( + config.backend_port, help="Specify a different backend port." + ), + backend_host: str = typer.Option( + config.backend_host, help="Specify the backend host." + ), + loglevel: constants.LogLevel = typer.Option( + config.loglevel, help="The log level to use." + ), +): + """Run the app in the current directory.""" + _run(env, frontend, backend, frontend_port, backend_port, backend_host, loglevel) + + @cli.command() def deploy_legacy( dry_run: bool = typer.Option(False, help="Whether to run a dry run."), @@ -677,6 +699,32 @@ def deploy( console.warn(f"For logs: `reflex deployments logs {key}`") +@cli.command() +def demo( + frontend_port: str = typer.Option( + "3001", help="Specify a different frontend port." + ), + backend_port: str = typer.Option("8001", help="Specify a different backend port."), +): + """Run the demo app.""" + with tempfile.TemporaryDirectory() as tmp_dir: + os.chdir(tmp_dir) + _init( + name="reflex_demo", + template=constants.Templates.Kind.BASE, + loglevel=constants.LogLevel.ERROR, + ) + _run( + env=constants.Env.DEV, + frontend=True, + backend=True, + frontend_port=frontend_port, + backend_port=backend_port, + backend_host="localhost", + loglevel=constants.LogLevel.ERROR, + ) + + deployments_cli = typer.Typer() diff --git a/reflex/testing.py b/reflex/testing.py index 814b5673e..dfea88670 100644 --- a/reflex/testing.py +++ b/reflex/testing.py @@ -152,7 +152,7 @@ class AppHarness: "".join(inspect.getsource(self.app_source).splitlines(True)[1:]), ) with chdir(self.app_path): - reflex.reflex.init( + reflex.reflex._init( name=self.app_name, template=reflex.constants.Templates.Kind.BLANK, loglevel=reflex.constants.LogLevel.INFO, diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index e69de29bb..000000000