Skip to content

Commit

Permalink
[ENG-4444] move states out of .web (#4689)
Browse files Browse the repository at this point in the history
* move states out of .web

* create file parents if they don't exist
  • Loading branch information
adhami3310 authored Jan 24, 2025
1 parent abc9038 commit 709c6de
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ assets/external/*
dist/*
examples/
.web
.states
.idea
.vscode
.coverage
Expand Down
3 changes: 3 additions & 0 deletions reflex/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,9 @@ class EnvironmentVariables:
# The working directory for the next.js commands.
REFLEX_WEB_WORKDIR: EnvVar[Path] = env_var(Path(constants.Dirs.WEB))

# The working directory for the states directory.
REFLEX_STATES_WORKDIR: EnvVar[Path] = env_var(Path(constants.Dirs.STATES))

# Path to the alembic config file
ALEMBIC_CONFIG: EnvVar[ExistingPath] = env_var(Path(constants.ALEMBIC_CONFIG))

Expand Down
2 changes: 1 addition & 1 deletion reflex/constants/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Dirs(SimpleNamespace):
# The name of the postcss config file.
POSTCSS_JS = "postcss.config.js"
# The name of the states directory.
STATES = "states"
STATES = ".states"


class Reflex(SimpleNamespace):
Expand Down
9 changes: 8 additions & 1 deletion reflex/constants/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,14 @@ class GitIgnore(SimpleNamespace):
# The gitignore file.
FILE = Path(".gitignore")
# Files to gitignore.
DEFAULTS = {Dirs.WEB, "*.db", "__pycache__/", "*.py[cod]", "assets/external/"}
DEFAULTS = {
Dirs.WEB,
Dirs.STATES,
"*.db",
"__pycache__/",
"*.py[cod]",
"assets/external/",
}


class RequirementsTxt(SimpleNamespace):
Expand Down
4 changes: 2 additions & 2 deletions reflex/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -3046,7 +3046,7 @@ def is_serializable(value: Any) -> bool:

def reset_disk_state_manager():
"""Reset the disk state manager."""
states_directory = prerequisites.get_web_dir() / constants.Dirs.STATES
states_directory = prerequisites.get_states_dir()
if states_directory.exists():
for path in states_directory.iterdir():
path.unlink()
Expand Down Expand Up @@ -3094,7 +3094,7 @@ def states_directory(self) -> Path:
Returns:
The states directory.
"""
return prerequisites.get_web_dir() / constants.Dirs.STATES
return prerequisites.get_states_dir()

def _purge_expired_states(self):
"""Purge expired states from the disk."""
Expand Down
2 changes: 1 addition & 1 deletion reflex/utils/exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def run_granian_backend(host, port, loglevel: LogLevel):
log_level=LogLevels(loglevel.value),
reload=True,
reload_paths=get_reload_dirs(),
reload_ignore_dirs=[".web"],
reload_ignore_dirs=[".web", ".states"],
).serve()
except ImportError:
console.error(
Expand Down
3 changes: 3 additions & 0 deletions reflex/utils/path_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ def update_json_file(file_path: str | Path, update_dict: dict[str, int | str]):
"""
fp = Path(file_path)

# Create the parent directory if it doesn't exist.
fp.parent.mkdir(parents=True, exist_ok=True)

# Create the file if it doesn't exist.
fp.touch(exist_ok=True)

Expand Down
11 changes: 11 additions & 0 deletions reflex/utils/prerequisites.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,17 @@ def get_web_dir() -> Path:
return environment.REFLEX_WEB_WORKDIR.get()


def get_states_dir() -> Path:
"""Get the working directory for the states.
Can be overridden with REFLEX_STATES_WORKDIR.
Returns:
The working directory.
"""
return environment.REFLEX_STATES_WORKDIR.get()


def check_latest_package_version(package_name: str):
"""Check if the latest version of the package is installed.
Expand Down

0 comments on commit 709c6de

Please sign in to comment.