Skip to content
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
18 changes: 12 additions & 6 deletions reflex/reflex.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,10 @@ def _run(
if not frontend and backend:
_skip_compile()

prerequisites.assert_in_reflex_dir()

# Check that the app is initialized.
if prerequisites.needs_reinit(frontend=frontend):
if frontend and prerequisites.needs_reinit():
_init(name=config.app_name)

# Delete the states folder if it exists.
Expand Down Expand Up @@ -403,19 +405,21 @@ def export(

environment.REFLEX_COMPILE_CONTEXT.set(constants.CompileContext.EXPORT)

frontend_only, backend_only = prerequisites.check_running_mode(
should_frontend_run, should_backend_run = prerequisites.check_running_mode(
frontend_only, backend_only
)

config = get_config()

if prerequisites.needs_reinit(frontend=frontend_only or not backend_only):
prerequisites.assert_in_reflex_dir()

if should_frontend_run and prerequisites.needs_reinit():
_init(name=config.app_name)

export_utils.export(
zipping=zip,
frontend=frontend_only,
backend=backend_only,
frontend=should_frontend_run,
backend=should_backend_run,
zip_dest_dir=zip_dest_dir,
upload_db_file=upload_db_file,
env=constants.Env.DEV if env == constants.Env.DEV else constants.Env.PROD,
Expand Down Expand Up @@ -631,8 +635,10 @@ def deploy(
if interactive:
dependency.check_requirements()

prerequisites.assert_in_reflex_dir()

# Check if we are set up.
if prerequisites.needs_reinit(frontend=True):
if prerequisites.needs_reinit():
_init(name=config.app_name)
prerequisites.check_latest_package_version(constants.ReflexHostingCLI.MODULE_NAME)

Expand Down
4 changes: 3 additions & 1 deletion reflex/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,9 @@ def _start_frontend(self):

get_config().loglevel = reflex.constants.LogLevel.INFO

if reflex.utils.prerequisites.needs_reinit(frontend=True):
reflex.utils.prerequisites.assert_in_reflex_dir()

if reflex.utils.prerequisites.needs_reinit():
reflex.reflex._init(name=get_config().app_name)

export(
Expand Down
21 changes: 9 additions & 12 deletions reflex/utils/prerequisites.py
Original file line number Diff line number Diff line change
Expand Up @@ -1370,28 +1370,25 @@ def check_running_mode(frontend: bool, backend: bool) -> tuple[bool, bool]:
return frontend, backend


def needs_reinit(frontend: bool = True) -> bool:
"""Check if an app needs to be reinitialized.

Args:
frontend: Whether to check if the frontend is initialized.

Returns:
Whether the app needs to be reinitialized.
def assert_in_reflex_dir():
"""Assert that the current working directory is the reflex directory.

Raises:
Exit: If the app is not initialized.
Exit: If the current working directory is not the reflex directory.
"""
if not constants.Config.FILE.exists():
console.error(
f"[cyan]{constants.Config.FILE}[/cyan] not found. Move to the root folder of your project, or run [bold]{constants.Reflex.MODULE_NAME} init[/bold] to start a new project."
)
raise click.exceptions.Exit(1)

# Don't need to reinit if not running in frontend mode.
if not frontend:
return False

def needs_reinit() -> bool:
"""Check if an app needs to be reinitialized.

Returns:
Whether the app needs to be reinitialized.
"""
# Make sure the .reflex directory exists.
if not environment.REFLEX_DIR.get().exists():
return True
Expand Down
Loading