Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
36 changes: 18 additions & 18 deletions reflex/custom_components/custom_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ def _get_default_library_name_parts() -> list[str]:
"""Get the default library name. Based on the current directory name, remove any non-alphanumeric characters.

Raises:
Exit: If the current directory name is not suitable for python projects, and we cannot find a valid library name based off it.
SystemExit: If the current directory name is not suitable for python projects, and we cannot find a valid library name based off it.

Returns:
The parts of default library name.
Expand All @@ -377,13 +377,13 @@ def _get_default_library_name_parts() -> list[str]:
console.error(
f"Based on current directory name {current_dir_name}, the library name is {constants.Reflex.MODULE_NAME}. This package already exists. Please use --library-name to specify a different name."
)
raise click.exceptions.Exit(code=1)
raise SystemExit(1)
if not parts:
# The folder likely has a name not suitable for python paths.
console.error(
f"Could not find a valid library name based on the current directory: got {current_dir_name}."
)
raise click.exceptions.Exit(code=1)
raise SystemExit(1)
return parts


Expand All @@ -408,7 +408,7 @@ def _validate_library_name(library_name: str | None) -> NameVariants:
library_name: The name of the library if picked otherwise None.

Raises:
Exit: If the library name is not suitable for python projects.
SystemExit: If the library name is not suitable for python projects.

Returns:
A tuple containing the various names such as package name, class name, etc., needed for the project.
Expand All @@ -419,7 +419,7 @@ def _validate_library_name(library_name: str | None) -> NameVariants:
console.error(
f"Please use only alphanumeric characters or dashes: got {library_name}"
)
raise click.exceptions.Exit(code=1)
raise SystemExit(1)

# If not specified, use the current directory name to form the module name.
name_parts = (
Expand Down Expand Up @@ -513,13 +513,13 @@ def init(
install: Whether to install package from this local custom component in editable mode.

Raises:
Exit: If the pyproject.toml already exists.
SystemExit: If the pyproject.toml already exists.
"""
from reflex.utils import exec

if CustomComponents.PYPROJECT_TOML.exists():
console.error(f"A {CustomComponents.PYPROJECT_TOML} already exists. Aborting.")
click.exceptions.Exit(code=1)
SystemExit(1)

# Show system info.
exec.output_system_info()
Expand All @@ -544,7 +544,7 @@ def init(
if _pip_install_on_demand(package_name=".", install_args=["-e"]):
console.info(f"Package {package_name} installed!")
else:
raise click.exceptions.Exit(code=1)
raise SystemExit(1)

console.print("[bold]Custom component initialized successfully!")
console.rule("[bold]Project Summary")
Expand Down Expand Up @@ -627,7 +627,7 @@ def _run_build():
"""Run the build command.

Raises:
Exit: If the build fails.
SystemExit: If the build fails.
"""
console.print("Building custom component...")

Expand All @@ -637,7 +637,7 @@ def _run_build():
if _run_commands_in_subprocess(cmds):
console.info("Custom component built successfully!")
else:
raise click.exceptions.Exit(code=1)
raise SystemExit(1)


@custom_components_cli.command(name="build")
Expand All @@ -651,7 +651,7 @@ def _collect_details_for_gallery():
"""Helper to collect details on the custom component to be included in the gallery.

Raises:
Exit: If pyproject.toml file is ill-formed or the request to the backend services fails.
SystemExit: If pyproject.toml file is ill-formed or the request to the backend services fails.
"""
import httpx
from reflex_cli.utils import hosting
Expand All @@ -664,7 +664,7 @@ def _collect_details_for_gallery():
console.error(
"Unable to authenticate with Reflex backend services. Make sure you are logged in."
)
raise click.exceptions.Exit(code=1)
raise SystemExit(1)

console.rule("[bold]Custom Component Information")
params = {}
Expand Down Expand Up @@ -694,11 +694,11 @@ def _collect_details_for_gallery():
console.error(
f"{package_name} is owned by another user. Unable to update the information for it."
)
raise click.exceptions.Exit(code=1)
raise SystemExit(1)
response.raise_for_status()
except httpx.HTTPError as he:
console.error(f"Unable to complete request due to {he}.")
raise click.exceptions.Exit(code=1) from he
raise SystemExit(1) from he

files = []
if (image_file_and_extension := _get_file_from_prompt_in_loop()) is not None:
Expand Down Expand Up @@ -733,7 +733,7 @@ def _collect_details_for_gallery():

except httpx.HTTPError as he:
console.error(f"Unable to complete request due to {he}.")
raise click.exceptions.Exit(code=1) from he
raise SystemExit(1) from he

console.info("Custom component information successfully shared!")

Expand Down Expand Up @@ -769,7 +769,7 @@ def _get_file_from_prompt_in_loop() -> tuple[bytes, str] | None:
image_file = image_file_path.read_bytes()
except OSError as ose:
console.error(f"Unable to read the {file_extension} file due to {ose}")
raise click.exceptions.Exit(code=1) from ose
raise SystemExit(1) from ose
else:
return image_file, file_extension

Expand All @@ -790,9 +790,9 @@ def install():
"""Install package from this local custom component in editable mode.

Raises:
Exit: If unable to install the current directory in editable mode.
SystemExit: If unable to install the current directory in editable mode.
"""
if _pip_install_on_demand(package_name=".", install_args=["-e"]):
console.info("Package installed successfully!")
else:
raise click.exceptions.Exit(code=1)
raise SystemExit(1)
2 changes: 1 addition & 1 deletion reflex/reflex.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ def run(
"""Run the app in the current directory."""
if frontend_only and backend_only:
console.error("Cannot use both --frontend-only and --backend-only options.")
raise click.exceptions.Exit(1)
raise SystemExit(1)

config = get_config()

Expand Down
6 changes: 2 additions & 4 deletions reflex/utils/frontend_skeleton.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import re
from pathlib import Path

import click

from reflex import constants
from reflex.compiler import templates
from reflex.config import Config, get_config
Expand Down Expand Up @@ -54,7 +52,7 @@ def initialize_requirements_txt() -> bool:
True if the user has to update the requirements.txt file.

Raises:
Exit: If the requirements.txt file cannot be read or written to.
SystemExit: If the requirements.txt file cannot be read or written to.
"""
requirements_file_path = Path(constants.RequirementsTxt.FILE)
if (
Expand All @@ -73,7 +71,7 @@ def initialize_requirements_txt() -> bool:
continue
except Exception as e:
console.error(f"Failed to read {requirements_file_path}.")
raise click.exceptions.Exit(1) from e
raise SystemExit(1) from e
else:
return True

Expand Down
19 changes: 9 additions & 10 deletions reflex/utils/js_runtimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from collections.abc import Sequence
from pathlib import Path

import click
from packaging import version

from reflex import constants
Expand Down Expand Up @@ -193,7 +192,7 @@ def download_and_run(url: str, *args, show_status: bool = False, **env):
env: The environment variables to use.

Raises:
Exit: If the script fails to download.
SystemExit: If the script fails to download.
"""
import httpx

Expand All @@ -206,7 +205,7 @@ def download_and_run(url: str, *args, show_status: bool = False, **env):
console.error(
f"Failed to download bun install script. You can install or update bun manually from https://bun.com \n{e}"
)
raise click.exceptions.Exit(1) from None
raise SystemExit(1) from None

# Save the script to a temporary file.
with tempfile.NamedTemporaryFile() as tempfile_file:
Expand All @@ -226,7 +225,7 @@ def install_bun():

Raises:
SystemPackageMissingError: If "unzip" is missing.
Exit: If REFLEX_USE_NPM is set but Node.js is not installed.
SystemExit: If REFLEX_USE_NPM is set but Node.js is not installed.
"""
if npm_escape_hatch():
if get_node_version() is not None:
Expand All @@ -237,7 +236,7 @@ def install_bun():
console.error(
"REFLEX_USE_NPM is set, but Node.js is not installed. Please install Node.js to use npm."
)
raise click.exceptions.Exit(1)
raise SystemExit(1)

bun_path = path_ops.get_bun_path()

Expand Down Expand Up @@ -290,7 +289,7 @@ def validate_bun(bun_path: Path | None = None):
bun_path: The path to the bun executable. If None, the default bun path is used.

Raises:
Exit: If custom specified bun does not exist or does not meet requirements.
SystemExit: If custom specified bun does not exist or does not meet requirements.
"""
bun_path = bun_path or path_ops.get_bun_path()

Expand All @@ -304,7 +303,7 @@ def validate_bun(bun_path: Path | None = None):
console.error(
"Failed to obtain bun version. Make sure the specified bun path in your config is correct."
)
raise click.exceptions.Exit(1)
raise SystemExit(1)
if bun_version < version.parse(constants.Bun.MIN_VERSION):
console.warn(
f"Reflex requires bun version {constants.Bun.MIN_VERSION} or higher to run, but the detected version is "
Expand All @@ -320,20 +319,20 @@ def validate_frontend_dependencies(init: bool = True):
init: whether running `reflex init`

Raises:
Exit: If the package manager is invalid.
SystemExit: If the package manager is invalid.
"""
if not init:
try:
get_js_package_executor(raise_on_none=True)
except FileNotFoundError as e:
raise click.exceptions.Exit(1) from e
raise SystemExit(1) from e

if prefer_npm_over_bun() and not check_node_version():
node_version = get_node_version()
console.error(
f"Reflex requires node version {constants.Node.MIN_VERSION} or higher to run, but the detected version is {node_version}",
)
raise click.exceptions.Exit(1)
raise SystemExit(1)


def remove_existing_bun_installation():
Expand Down
11 changes: 5 additions & 6 deletions reflex/utils/prerequisites.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from types import ModuleType
from typing import NamedTuple

import click
from alembic.util.exc import CommandError
from packaging import version
from redis import Redis as RedisSync
Expand Down Expand Up @@ -444,22 +443,22 @@ def validate_app_name(app_name: str | None = None) -> str:
The app name after validation.

Raises:
Exit: if the app directory name is reflex or if the name is not standard for a python package name.
SystemExit: if the app directory name is reflex or if the name is not standard for a python package name.
"""
app_name = app_name if app_name else Path.cwd().name.replace("-", "_")
# Make sure the app is not named "reflex".
if app_name.lower() == constants.Reflex.MODULE_NAME:
console.error(
f"The app directory cannot be named [bold]{constants.Reflex.MODULE_NAME}[/bold]."
)
raise click.exceptions.Exit(1)
raise SystemExit(1)

# Make sure the app name is standard for a python package name.
if not re.match(r"^[a-zA-Z][a-zA-Z0-9_]*$", app_name):
console.error(
"The app directory name must start with a letter and can contain letters, numbers, and underscores."
)
raise click.exceptions.Exit(1)
raise SystemExit(1)

return app_name

Expand Down Expand Up @@ -499,13 +498,13 @@ def assert_in_reflex_dir():
"""Assert that the current working directory is the reflex directory.

Raises:
Exit: If the current working directory is not the reflex directory.
SystemExit: If the current working directory is not the reflex directory.
"""
if not constants.Config.FILE.exists():
console.error(
f"[cyan]{constants.Config.FILE}[/cyan] not found. Move to the root folder of your project, or run [bold]{constants.Reflex.MODULE_NAME} init[/bold] to start a new project."
)
raise click.exceptions.Exit(1)
raise SystemExit(1)


def needs_reinit() -> bool:
Expand Down
Loading
Loading