Skip to content
Open
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
6 changes: 3 additions & 3 deletions reflex/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,15 +377,15 @@ def _add_builtin_plugins(self):
if not any(isinstance(p, plugin) for p in self.plugins):
console.warn(
f"`{plugin_name}` plugin is enabled by default, but not explicitly added to the config. "
"If you want to use it, please add it to the `plugins` list in your config inside of `rxconfig.py`. "
f"If you want to use it, please add it to the `plugins` list in your config inside of `{constants.Config.FILE}`. "
f"To disable this plugin, set `disable_plugins` to `{[plugin_name, *self.disable_plugins]!r}`.",
)
self.plugins.append(plugin())
else:
if any(isinstance(p, plugin) for p in self.plugins):
console.warn(
f"`{plugin_name}` is disabled in the config, but it is still present in the `plugins` list. "
"Please remove it from the `plugins` list in your config inside of `rxconfig.py`.",
f"Please remove it from the `plugins` list in your config inside of `{constants.Config.FILE}`.",
)

for disabled_plugin in self.disable_plugins:
Expand All @@ -399,7 +399,7 @@ def _add_builtin_plugins(self):
):
console.warn(
f"`{disabled_plugin}` is disabled in the config, but it is not a built-in plugin. "
"Please remove it from the `disable_plugins` list in your config inside of `rxconfig.py`.",
f"Please remove it from the `disable_plugins` list in your config inside of `{constants.Config.FILE}`.",
)

@classmethod
Expand Down
44 changes: 38 additions & 6 deletions reflex/constants/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Config constants."""

import os
from pathlib import Path
from types import SimpleNamespace

Expand All @@ -10,14 +11,45 @@
# Alembic migrations
ALEMBIC_CONFIG = "alembic.ini"

# Default config module name.
_DEFAULT_CONFIG_MODULE = "rxconfig"

class Config(SimpleNamespace):
"""Config constants."""

# The name of the reflex config module.
MODULE = "rxconfig"
# The python config file.
FILE = Path(f"{MODULE}{Ext.PY}")
def _get_config_module() -> str:
"""Get the config module name from env or default.

Returns:
The config module name.
"""
return os.environ.get("REFLEX_CONFIG_MODULE", _DEFAULT_CONFIG_MODULE)


def _get_config_file() -> Path:
"""Get the config file path from env or derive from module name.

Returns:
The config file path.
"""
env_file = os.environ.get("REFLEX_CONFIG_FILE")
if env_file:
return Path(env_file)
return Path(f"{_get_config_module()}{Ext.PY}")


class _ConfigMeta(type(SimpleNamespace)):
"""Metaclass for Config that makes MODULE and FILE dynamic class attributes."""

@property
def MODULE(cls) -> str: # noqa: N802
return _get_config_module()

@property
def FILE(cls) -> Path: # noqa: N802
return _get_config_file()


class Config(SimpleNamespace, metaclass=_ConfigMeta):
"""Config constants."""


class Expiration(SimpleNamespace):
Expand Down
4 changes: 2 additions & 2 deletions reflex/utils/exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ def get_reload_paths() -> Sequence[Path]:

while module_path.parent.name and _has_child_file(module_path, "__init__.py"):
if (
_has_child_file(module_path, "rxconfig.py")
_has_child_file(module_path, constants.Config.FILE.name)
and module_path == Path.cwd()
):
init_file = module_path / "__init__.py"
Expand All @@ -436,7 +436,7 @@ def get_reload_paths() -> Sequence[Path]:
init_file.unlink()
break

# go up a level to find dir without `__init__.py` or with `rxconfig.py`
# go up a level to find dir without `__init__.py` or with config file
module_path = module_path.parent

reload_paths = [module_path]
Expand Down
8 changes: 4 additions & 4 deletions reflex/utils/prerequisites.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def _check_app_name(config: Config):
"""
if not config.app_name:
msg = (
"Cannot get the app module because `app_name` is not set in rxconfig! "
f"Cannot get the app module because `app_name` is not set in {constants.Config.FILE}! "
"If this error occurs in a reflex test case, ensure that `get_app` is mocked."
)
raise RuntimeError(msg)
Expand All @@ -161,9 +161,9 @@ def _check_app_name(config: Config):
if module_path is None:
msg = f"Module {config.module} not found. "
if config.app_module_import is not None:
msg += f"Ensure app_module_import='{config.app_module_import}' in rxconfig.py matches your folder structure."
msg += f"Ensure app_module_import='{config.app_module_import}' in {constants.Config.FILE} matches your folder structure."
else:
msg += f"Ensure app_name='{config.app_name}' in rxconfig.py matches your folder structure."
msg += f"Ensure app_name='{config.app_name}' in {constants.Config.FILE} matches your folder structure."
raise ModuleNotFoundError(msg)
config._app_name_is_valid = True

Expand Down Expand Up @@ -234,7 +234,7 @@ def get_and_validate_app(
app_module = get_app(reload=reload)
app = getattr(app_module, constants.CompileVars.APP)
if not isinstance(app, App):
msg = "The app instance in the specified app_module_import in rxconfig must be an instance of rx.App."
msg = f"The app instance in the specified app_module_import in {constants.Config.FILE} must be an instance of rx.App."
raise RuntimeError(msg)

if check_if_schema_up_to_date:
Expand Down
10 changes: 5 additions & 5 deletions reflex/utils/rename.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

def rename_path_up_tree(full_path: str | Path, old_name: str, new_name: str) -> Path:
"""Rename all instances of `old_name` in the path (file and directories) to `new_name`.
The renaming stops when we reach the directory containing `rxconfig.py`.
The renaming stops when we reach the directory containing the config file.

Args:
full_path: The full path to start renaming from.
Expand All @@ -27,8 +27,8 @@ def rename_path_up_tree(full_path: str | Path, old_name: str, new_name: str) ->

while True:
directory, base = current_path.parent, current_path.name
# Stop renaming when we reach the root dir (which contains rxconfig.py)
if current_path.is_dir() and (current_path / "rxconfig.py").exists():
# Stop renaming when we reach the root dir (which contains the config file)
if current_path.is_dir() and (current_path / constants.Config.FILE.name).exists():
new_path = current_path
break

Expand Down Expand Up @@ -62,7 +62,7 @@ def rename_app(new_app_name: str, loglevel: constants.LogLevel):

if not constants.Config.FILE.exists():
console.error(
"No rxconfig.py found. Make sure you are in the root directory of your app."
f"No {constants.Config.FILE} found. Make sure you are in the root directory of your app."
)
raise SystemExit(1)

Expand All @@ -88,7 +88,7 @@ def rename_app(new_app_name: str, loglevel: constants.LogLevel):


def rename_imports_and_app_name(file_path: str | Path, old_name: str, new_name: str):
"""Rename imports the file using string replacement as well as app_name in rxconfig.py.
"""Rename imports the file using string replacement as well as app_name in the config file.

Args:
file_path: The file to process.
Expand Down