Skip to content

Commit d88cf6e

Browse files
authored
remove frontend arg from needs_reinit (#5214)
1 parent 5acd50e commit d88cf6e

File tree

3 files changed

+24
-19
lines changed

3 files changed

+24
-19
lines changed

reflex/reflex.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,10 @@ def _run(
151151
if not frontend and backend:
152152
_skip_compile()
153153

154+
prerequisites.assert_in_reflex_dir()
155+
154156
# Check that the app is initialized.
155-
if prerequisites.needs_reinit(frontend=frontend):
157+
if frontend and prerequisites.needs_reinit():
156158
_init(name=config.app_name)
157159

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

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

406-
frontend_only, backend_only = prerequisites.check_running_mode(
408+
should_frontend_run, should_backend_run = prerequisites.check_running_mode(
407409
frontend_only, backend_only
408410
)
409411

410412
config = get_config()
411413

412-
if prerequisites.needs_reinit(frontend=frontend_only or not backend_only):
414+
prerequisites.assert_in_reflex_dir()
415+
416+
if should_frontend_run and prerequisites.needs_reinit():
413417
_init(name=config.app_name)
414418

415419
export_utils.export(
416420
zipping=zip,
417-
frontend=frontend_only,
418-
backend=backend_only,
421+
frontend=should_frontend_run,
422+
backend=should_backend_run,
419423
zip_dest_dir=zip_dest_dir,
420424
upload_db_file=upload_db_file,
421425
env=constants.Env.DEV if env == constants.Env.DEV else constants.Env.PROD,
@@ -631,8 +635,10 @@ def deploy(
631635
if interactive:
632636
dependency.check_requirements()
633637

638+
prerequisites.assert_in_reflex_dir()
639+
634640
# Check if we are set up.
635-
if prerequisites.needs_reinit(frontend=True):
641+
if prerequisites.needs_reinit():
636642
_init(name=config.app_name)
637643
prerequisites.check_latest_package_version(constants.ReflexHostingCLI.MODULE_NAME)
638644

reflex/testing.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,9 @@ def _start_frontend(self):
937937

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

940-
if reflex.utils.prerequisites.needs_reinit(frontend=True):
940+
reflex.utils.prerequisites.assert_in_reflex_dir()
941+
942+
if reflex.utils.prerequisites.needs_reinit():
941943
reflex.reflex._init(name=get_config().app_name)
942944

943945
export(

reflex/utils/prerequisites.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,28 +1370,25 @@ def check_running_mode(frontend: bool, backend: bool) -> tuple[bool, bool]:
13701370
return frontend, backend
13711371

13721372

1373-
def needs_reinit(frontend: bool = True) -> bool:
1374-
"""Check if an app needs to be reinitialized.
1375-
1376-
Args:
1377-
frontend: Whether to check if the frontend is initialized.
1378-
1379-
Returns:
1380-
Whether the app needs to be reinitialized.
1373+
def assert_in_reflex_dir():
1374+
"""Assert that the current working directory is the reflex directory.
13811375
13821376
Raises:
1383-
Exit: If the app is not initialized.
1377+
Exit: If the current working directory is not the reflex directory.
13841378
"""
13851379
if not constants.Config.FILE.exists():
13861380
console.error(
13871381
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."
13881382
)
13891383
raise click.exceptions.Exit(1)
13901384

1391-
# Don't need to reinit if not running in frontend mode.
1392-
if not frontend:
1393-
return False
13941385

1386+
def needs_reinit() -> bool:
1387+
"""Check if an app needs to be reinitialized.
1388+
1389+
Returns:
1390+
Whether the app needs to be reinitialized.
1391+
"""
13951392
# Make sure the .reflex directory exists.
13961393
if not environment.REFLEX_DIR.get().exists():
13971394
return True

0 commit comments

Comments
 (0)