minor format
This commit is contained in:
parent
1b42eea1ed
commit
aa4570175e
@ -1380,7 +1380,9 @@ def create_config_init_app_from_remote_template(app_name: str, template_url: str
|
||||
|
||||
def prompt_templates(templates: dict[str, Template]) -> str:
|
||||
while True:
|
||||
console.print("visit https://reflex.dev/templates for the complete list of templates.")
|
||||
console.print(
|
||||
"visit https://reflex.dev/templates for the complete list of templates."
|
||||
)
|
||||
answer = console.ask("Enter a valid template name", show_choices=False)
|
||||
if not answer in templates:
|
||||
console.error("Invalid template name. Please try again.")
|
||||
@ -1402,7 +1404,9 @@ def use_ai_generation(template: str | None = None) -> str:
|
||||
raise typer.Exit(2)
|
||||
|
||||
|
||||
def initialize_app(app_name: str, template: str | None = None, ai: bool = False) -> str | None:
|
||||
def initialize_app(
|
||||
app_name: str, template: str | None = None, ai: bool = False
|
||||
) -> str | None:
|
||||
"""Initialize the app either from a remote template or a blank app. If the config file exists, it is considered as reinit.
|
||||
|
||||
Args:
|
||||
@ -1431,7 +1435,9 @@ def initialize_app(app_name: str, template: str | None = None, ai: bool = False)
|
||||
templates: dict[str, Template] = {}
|
||||
|
||||
# Don't fetch app templates if the user directly asked for DEFAULT.
|
||||
if template is not None and (template != constants.Templates.DEFAULT or template != constants.Templates.AI):
|
||||
if template is not None and (
|
||||
template != constants.Templates.DEFAULT or template != constants.Templates.AI
|
||||
):
|
||||
try:
|
||||
# Get the available templates
|
||||
templates = fetch_app_templates(constants.Reflex.VERSION)
|
||||
@ -1444,7 +1450,6 @@ def initialize_app(app_name: str, template: str | None = None, ai: bool = False)
|
||||
template = template or constants.Templates.DEFAULT
|
||||
|
||||
if template is None:
|
||||
|
||||
template = prompt_for_template(get_init_cli_options())
|
||||
if template == constants.Templates.AI:
|
||||
generation_hash = use_ai_generation()
|
||||
@ -1453,9 +1458,15 @@ def initialize_app(app_name: str, template: str | None = None, ai: bool = False)
|
||||
# Get the available templates
|
||||
templates = fetch_app_templates(constants.Reflex.VERSION)
|
||||
# default to the blank template if no templates are available
|
||||
template = prompt_templates(templates) if len(templates) > 0 else constants.Templates.DEFAULT
|
||||
template = (
|
||||
prompt_templates(templates)
|
||||
if len(templates) > 0
|
||||
else constants.Templates.DEFAULT
|
||||
)
|
||||
except Exception as e:
|
||||
console.warn("Failed to fetch templates. Falling back to default template.")
|
||||
console.warn(
|
||||
"Failed to fetch templates. Falling back to default template."
|
||||
)
|
||||
console.debug(f"Error while fetching templates: {e}")
|
||||
template = constants.Templates.DEFAULT
|
||||
|
||||
@ -1469,7 +1480,6 @@ def initialize_app(app_name: str, template: str | None = None, ai: bool = False)
|
||||
create_config(app_name)
|
||||
initialize_app_directory(app_name)
|
||||
else:
|
||||
|
||||
# If user selects a template, it needs to exist.
|
||||
if template in templates:
|
||||
template_url = templates[template].code_url
|
||||
@ -1500,7 +1510,9 @@ def initialize_app(app_name: str, template: str | None = None, ai: bool = False)
|
||||
return template
|
||||
|
||||
|
||||
def fetch_and_prompt_for_templates(template: str | None, templates: dict[str, Template]) -> str:
|
||||
def fetch_and_prompt_for_templates(
|
||||
template: str | None, templates: dict[str, Template]
|
||||
) -> str:
|
||||
"""Fetches available templates and prompts the user if template is not specified."""
|
||||
try:
|
||||
templates = fetch_app_templates(constants.Reflex.VERSION)
|
||||
@ -1514,11 +1526,24 @@ def fetch_and_prompt_for_templates(template: str | None, templates: dict[str, Te
|
||||
|
||||
def get_init_cli_options() -> list[Template]:
|
||||
return [
|
||||
Template(name=constants.Templates.DEFAULT, description="A blank Reflex app.", demo_url="", code_url=""),
|
||||
Template(name=constants.Templates.AI, description="Generate a template using AI(Flexgen)", demo_url="https://flexgen.reflex.run",
|
||||
code_url=""),
|
||||
Template(name=constants.Templates.CHOOSE_TEMPLATES, description="Choose an existing template.", demo_url="https://reflex.dev/templates",
|
||||
code_url=""),
|
||||
Template(
|
||||
name=constants.Templates.DEFAULT,
|
||||
description="A blank Reflex app.",
|
||||
demo_url="",
|
||||
code_url="",
|
||||
),
|
||||
Template(
|
||||
name=constants.Templates.AI,
|
||||
description="Generate a template using AI(Flexgen)",
|
||||
demo_url="https://flexgen.reflex.run",
|
||||
code_url="",
|
||||
),
|
||||
Template(
|
||||
name=constants.Templates.CHOOSE_TEMPLATES,
|
||||
description="Choose an existing template.",
|
||||
demo_url="https://reflex.dev/templates",
|
||||
code_url="",
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user