[ENG-4444] move states out of .web (#4689)

* move states out of .web

* create file parents if they don't exist
This commit is contained in:
Khaleel Al-Adhami 2025-01-24 12:38:14 -08:00 committed by GitHub
parent abc9038580
commit 709c6dedf2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 30 additions and 5 deletions

1
.gitignore vendored
View File

@ -4,6 +4,7 @@ assets/external/*
dist/* dist/*
examples/ examples/
.web .web
.states
.idea .idea
.vscode .vscode
.coverage .coverage

View File

@ -490,6 +490,9 @@ class EnvironmentVariables:
# The working directory for the next.js commands. # The working directory for the next.js commands.
REFLEX_WEB_WORKDIR: EnvVar[Path] = env_var(Path(constants.Dirs.WEB)) 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 # Path to the alembic config file
ALEMBIC_CONFIG: EnvVar[ExistingPath] = env_var(Path(constants.ALEMBIC_CONFIG)) ALEMBIC_CONFIG: EnvVar[ExistingPath] = env_var(Path(constants.ALEMBIC_CONFIG))

View File

@ -52,7 +52,7 @@ class Dirs(SimpleNamespace):
# The name of the postcss config file. # The name of the postcss config file.
POSTCSS_JS = "postcss.config.js" POSTCSS_JS = "postcss.config.js"
# The name of the states directory. # The name of the states directory.
STATES = "states" STATES = ".states"
class Reflex(SimpleNamespace): class Reflex(SimpleNamespace):

View File

@ -39,7 +39,14 @@ class GitIgnore(SimpleNamespace):
# The gitignore file. # The gitignore file.
FILE = Path(".gitignore") FILE = Path(".gitignore")
# Files to 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): class RequirementsTxt(SimpleNamespace):

View File

@ -3046,7 +3046,7 @@ def is_serializable(value: Any) -> bool:
def reset_disk_state_manager(): def reset_disk_state_manager():
"""Reset the 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(): if states_directory.exists():
for path in states_directory.iterdir(): for path in states_directory.iterdir():
path.unlink() path.unlink()
@ -3094,7 +3094,7 @@ class StateManagerDisk(StateManager):
Returns: Returns:
The states directory. The states directory.
""" """
return prerequisites.get_web_dir() / constants.Dirs.STATES return prerequisites.get_states_dir()
def _purge_expired_states(self): def _purge_expired_states(self):
"""Purge expired states from the disk.""" """Purge expired states from the disk."""

View File

@ -307,7 +307,7 @@ def run_granian_backend(host, port, loglevel: LogLevel):
log_level=LogLevels(loglevel.value), log_level=LogLevels(loglevel.value),
reload=True, reload=True,
reload_paths=get_reload_dirs(), reload_paths=get_reload_dirs(),
reload_ignore_dirs=[".web"], reload_ignore_dirs=[".web", ".states"],
).serve() ).serve()
except ImportError: except ImportError:
console.error( console.error(

View File

@ -196,6 +196,9 @@ def update_json_file(file_path: str | Path, update_dict: dict[str, int | str]):
""" """
fp = Path(file_path) 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. # Create the file if it doesn't exist.
fp.touch(exist_ok=True) fp.touch(exist_ok=True)

View File

@ -87,6 +87,17 @@ def get_web_dir() -> Path:
return environment.REFLEX_WEB_WORKDIR.get() 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): def check_latest_package_version(package_name: str):
"""Check if the latest version of the package is installed. """Check if the latest version of the package is installed.