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

Fix Streamlit in docs #881

Merged
merged 1 commit into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/snowflake/cli/api/commands/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,11 +389,18 @@ def _callback(project_path: Optional[str]):
cli_context_manager.set_project_root(project_root)
return project_definition

if project_name == "native_app":
project_name_help = "Snowflake Native App"
elif project_name == "streamlit":
project_name_help = "Streamlit app"
else:
project_name_help = project_name.replace("_", " ").capitalize()

return typer.Option(
None,
"-p",
"--project",
help=f"Path where the {'Snowflake Native App' if project_name == 'native_app' else project_name.replace('_', ' ').capitalize()} project resides. "
help=f"Path where the {project_name_help} project resides. "
f"Defaults to current working directory.",
callback=_callback,
show_default=False,
Expand Down
16 changes: 13 additions & 3 deletions src/snowflake/cli/api/commands/project_initialisation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

from typing import Optional

from snowflake.cli.api.commands.snow_typer import SnowTyper
from snowflake.cli.api.constants import TEMPLATES_PATH
from snowflake.cli.api.output.types import CommandResult, MessageResult
Expand All @@ -13,21 +15,29 @@ def _create_project_template(template_name: str, project_directory: str):
)


def add_init_command(app: SnowTyper, project_type: str, template: str):
def add_init_command(
app: SnowTyper, project_type: str, template: str, help_message: Optional[str] = None
):
@app.command()
def init(
project_name: str = Argument(
f"example_{project_type.lower()}",
help=f"Name of the {project_type} project you want to create.",
help=help_message
if help_message is not None
else f"Name of the {project_type} project you want to create.",
),
**options,
) -> CommandResult:
_create_project_template(template, project_directory=project_name)
return MessageResult(f"Initialized the new project in {project_name}/")

project_type_doc = (
project_type if project_type.lower() != "streamlit" else "Streamlit app"
)

init.__doc__ = (
f"Initializes this directory with a sample set "
f"of files for creating a {project_type} project."
f"of files for creating a {project_type_doc} project."
)

return init
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Streamlit(UpdatableModel):
title="Snowflake warehouse to host the app", default="streamlit"
)
main_file: Optional[str] = Field(
title="Entrypoint file of the streamlit app", default="streamlit_app.py"
title="Entrypoint file of the Streamlit app", default="streamlit_app.py"
)
env_file: Optional[str] = Field(
title="File defining additional configurations for the app, such as external dependencies",
Expand Down
40 changes: 25 additions & 15 deletions src/snowflake/cli/plugins/streamlit/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,38 @@

app = SnowTyper(
name="streamlit",
help="Manages Streamlit in Snowflake.",
help="Manages a Streamlit app in Snowflake.",
)
log = logging.getLogger(__name__)


StageNameOption: str = typer.Option(
"streamlit",
"--stage",
help="Stage name where Streamlit files will be uploaded.",
help="Name of the stage where you want to upload Streamlit app files.",
)

OpenOption = typer.Option(
False,
"--open",
help="Whether to open the Streamlit app in a browser.",
is_flag=True,
)


add_init_command(app, project_type="Streamlit", template="default_streamlit")
add_init_command(
app,
project_type="Streamlit",
template="default_streamlit",
help_message="Name of the Streamlit app project directory you want to create. Defaults to `example_streamlit`.",
)


@app.command("share", requires_connection=True)
def streamlit_share(
name: str = typer.Argument(..., help="Name of streamlit to share."),
name: str = typer.Argument(..., help="Name of the Streamlit app to share."),
to_role: str = typer.Argument(
..., help="Role that streamlit should be shared with."
..., help="Role with which to share the Streamlit app."
),
**options,
) -> CommandResult:
Expand Down Expand Up @@ -71,16 +83,16 @@ def _check_file_exists_if_not_default(ctx: click.Context, value):
@with_project_definition("streamlit")
@with_experimental_behaviour()
def streamlit_deploy(
replace: bool = ReplaceOption(help="Replace the Streamlit if it already exists."),
open_: bool = typer.Option(
False, "--open", help="Whether to open Streamlit in a browser.", is_flag=True
replace: bool = ReplaceOption(
help="Replace the Streamlit app if it already exists."
),
open_: bool = OpenOption,
**options,
) -> CommandResult:
"""
Deploys a Streamlit dashboard defined in project definition file (snowflake.yml). By default, the command will
upload environment.yml and pages/ folder if present. If stage name is not specified then 'streamlit' stage
will be used. If stage does not exist it will be created by this command.
Deploys a Streamlit app defined in the project definition file (snowflake.yml). By default, the command uploads
environment.yml and any other pages or folders, if present. If you don’t specify a stage name, the `streamlit`
stage is used. If the specified stage does not exist, the command creates it.
"""
streamlit: Streamlit = cli_context.project_definition
if not streamlit:
Expand Down Expand Up @@ -119,12 +131,10 @@ def streamlit_deploy(
@app.command("get-url", requires_connection=True)
def get_url(
name: str = typer.Argument(..., help="Name of the Streamlit app."),
open_: bool = typer.Option(
False, "--open", help="Whether to open Streamlit in a browser.", is_flag=True
),
open_: bool = OpenOption,
**options,
):
"""Returns url to provided streamlit app"""
"""Returns a URL to the specified Streamlit app"""
url = StreamlitManager().get_url(streamlit_name=name)
if open_:
typer.launch(url)
Expand Down
51 changes: 26 additions & 25 deletions tests/__snapshots__/test_help_messages.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
│ spcs Manages Snowpark Container Services compute pools, services, │
│ image registries, and image repositories. │
│ sql Executes Snowflake query. │
│ streamlit Manages Streamlit in Snowflake.
│ streamlit Manages a Streamlit app in Snowflake. │
╰──────────────────────────────────────────────────────────────────────────────╯


Expand Down Expand Up @@ -3943,17 +3943,17 @@

Usage: default streamlit deploy [OPTIONS]

Deploys a Streamlit dashboard defined in project definition file
(snowflake.yml). By default, the command will upload environment.yml and
pages/ folder if present. If stage name is not specified then 'streamlit'
stage will be used. If stage does not exist it will be created by this
command.
Deploys a Streamlit app defined in the project definition file
(snowflake.yml). By default, the command uploads environment.yml and any other
pages or folders, if present. If you don’t specify a stage name, the
`streamlit` stage is used. If the specified stage does not exist, the command
creates it.

╭─ Options ────────────────────────────────────────────────────────────────────╮
│ --replace Replace the Streamlit if it already exists.
│ --open Whether to open Streamlit in a browser.
│ --project -p TEXT Path where the Streamlit project resides. Defaults
│ to current working directory.
│ --replace Replace the Streamlit app if it already exists. │
│ --open Whether to open the Streamlit app in a browser. │
│ --project -p TEXT Path where the Streamlit app project resides.
Defaults to current working directory. │
│ --help -h Show this message and exit. │
╰──────────────────────────────────────────────────────────────────────────────╯
╭─ Connection configuration ───────────────────────────────────────────────────╮
Expand Down Expand Up @@ -4011,13 +4011,13 @@

Usage: default streamlit get-url [OPTIONS] NAME

Returns url to provided streamlit app
Returns a URL to the specified Streamlit app

╭─ Arguments ──────────────────────────────────────────────────────────────────╮
│ * name TEXT Name of the Streamlit app. [default: None] [required] │
╰──────────────────────────────────────────────────────────────────────────────╯
╭─ Options ────────────────────────────────────────────────────────────────────╮
│ --open Whether to open Streamlit in a browser.
│ --open Whether to open the Streamlit app in a browser. │
│ --help -h Show this message and exit. │
╰──────────────────────────────────────────────────────────────────────────────╯
╭─ Connection configuration ───────────────────────────────────────────────────╮
Expand Down Expand Up @@ -4076,11 +4076,12 @@
Usage: default streamlit init [OPTIONS] [PROJECT_NAME]

Initializes this directory with a sample set of files for creating a Streamlit
project.
app project.

╭─ Arguments ──────────────────────────────────────────────────────────────────╮
│ project_name [PROJECT_NAME] Name of the Streamlit project you want │
│ to create. │
│ project_name [PROJECT_NAME] Name of the Streamlit app project │
│ directory you want to create. Defaults │
│ to `example_streamlit`. │
│ [default: example_streamlit] │
╰──────────────────────────────────────────────────────────────────────────────╯
╭─ Options ────────────────────────────────────────────────────────────────────╮
Expand Down Expand Up @@ -4108,9 +4109,9 @@
Shares a Streamlit app with another role.

╭─ Arguments ──────────────────────────────────────────────────────────────────╮
│ * name TEXT Name of streamlit to share. [default: None]
│ * name TEXT Name of the Streamlit app to share. [default: None] │
│ [required] │
│ * to_role TEXT Role that streamlit should be shared with.
│ * to_role TEXT Role with which to share the Streamlit app.
│ [default: None] │
│ [required] │
╰──────────────────────────────────────────────────────────────────────────────╯
Expand Down Expand Up @@ -4172,20 +4173,20 @@

Usage: default streamlit [OPTIONS] COMMAND [ARGS]...

Manages Streamlit in Snowflake.
Manages a Streamlit app in Snowflake.

╭─ Options ────────────────────────────────────────────────────────────────────╮
│ --help -h Show this message and exit. │
╰──────────────────────────────────────────────────────────────────────────────╯
╭─ Commands ───────────────────────────────────────────────────────────────────╮
│ deploy Deploys a Streamlit dashboard defined in project definition file │
│ (snowflake.yml). By default, the command will upload
environment.yml and pages/ folder if present. If stage name is not
specified then 'streamlit' stage will be used. If stage does not
exist it will be created by this command.
│ get-url Returns url to provided streamlit app
│ deploy Deploys a Streamlit app defined in the project definition file
│ (snowflake.yml). By default, the command uploads environment.yml
│ and any other pages or folders, if present. If you don’t specify a
stage name, the `streamlit` stage is used. If the specified stage
does not exist, the command creates it.
│ get-url Returns a URL to the specified Streamlit app
│ init Initializes this directory with a sample set of files for creating │
│ a Streamlit project.
│ a Streamlit app project. │
│ share Shares a Streamlit app with another role. │
╰──────────────────────────────────────────────────────────────────────────────╯

Expand Down
2 changes: 1 addition & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def test_global(runner):
[
("object", "Manages Snowflake objects"),
("snowpark", "Manages procedures and functions."),
("streamlit", " Manages Streamlit in Snowflake."),
("streamlit", " Manages a Streamlit app in Snowflake."),
],
)
def test_namespace(namespace, expected, runner):
Expand Down
Loading
Loading