Преглед на файлове

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

* move states out of .web

* create file parents if they don't exist
Khaleel Al-Adhami преди 3 месеца
родител
ревизия
709c6dedf2
променени са 8 файла, в които са добавени 30 реда и са изтрити 5 реда
  1. 1 0
      .gitignore
  2. 3 0
      reflex/config.py
  3. 1 1
      reflex/constants/base.py
  4. 8 1
      reflex/constants/config.py
  5. 2 2
      reflex/state.py
  6. 1 1
      reflex/utils/exec.py
  7. 3 0
      reflex/utils/path_ops.py
  8. 11 0
      reflex/utils/prerequisites.py

+ 1 - 0
.gitignore

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

+ 3 - 0
reflex/config.py

@@ -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))
 

+ 1 - 1
reflex/constants/base.py

@@ -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):

+ 8 - 1
reflex/constants/config.py

@@ -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):

+ 2 - 2
reflex/state.py

@@ -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()
@@ -3094,7 +3094,7 @@ class StateManagerDisk(StateManager):
         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."""

+ 1 - 1
reflex/utils/exec.py

@@ -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(

+ 3 - 0
reflex/utils/path_ops.py

@@ -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)
 

+ 11 - 0
reflex/utils/prerequisites.py

@@ -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.