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

Stop double compiles in dev mode #1990

Merged
merged 2 commits into from
Oct 19, 2023
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
22 changes: 21 additions & 1 deletion reflex/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,10 +583,30 @@ def _app_root(self, app_wrappers):
parent = child
return root

def _should_compile(self) -> bool:
"""Check if the app should be compiled.

Returns:
Whether the app should be compiled.
"""
# Check the environment variable.
if os.environ.get(constants.SKIP_COMPILE_ENV_VAR) == "yes":
return False
Comment on lines +593 to +594
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we just get rid of this? i don't think it was being used anywhere else

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is used in other places in reflex.py. For example we call _skip_compile() in db_init and migrate. Agreed we should have only one way to do this though as this could be a bit messy to have two methods.


# Check the nocompile file.
if os.path.exists(constants.NOCOMPILE_FILE):
# Delete the nocompile file
os.remove(constants.NOCOMPILE_FILE)
return False

# By default, compile the app.
return True

def compile(self):
"""Compile the app and output it to the pages folder."""
if os.environ.get(constants.SKIP_COMPILE_ENV_VAR) == "yes":
if not self._should_compile():
return

# Create a progress bar.
progress = Progress(
*Progress.get_default_columns()[:-1],
Expand Down
2 changes: 2 additions & 0 deletions reflex/constants/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
Templates,
)
from .compiler import (
NOCOMPILE_FILE,
SETTER_PREFIX,
CompileVars,
ComponentName,
Expand Down Expand Up @@ -70,6 +71,7 @@
LogLevel,
Next,
Node,
NOCOMPILE_FILE,
PackageJson,
PageNames,
Page404,
Expand Down
3 changes: 3 additions & 0 deletions reflex/constants/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
# The prefix used to create setters for state vars.
SETTER_PREFIX = "set_"

# The file used to specify no compilation.
NOCOMPILE_FILE = ".web/nocompile"


class Ext(SimpleNamespace):
"""Extension used in Reflex."""
Expand Down
7 changes: 7 additions & 0 deletions reflex/utils/exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,13 @@ def run_backend(
"""
config = get_config()
app_module = f"{config.app_name}.{config.app_name}:{constants.CompileVars.APP}"

# Create a .nocompile file to skip compile for backend.
if os.path.exists(constants.Dirs.WEB):
with open(constants.NOCOMPILE_FILE, "w"):
pass

# Run the backend in development mode.
uvicorn.run(
app=f"{app_module}.{constants.CompileVars.API}",
host=host,
Expand Down
Loading