Skip to content

Commit a8e571d

Browse files
adhami3310tartansandal
authored andcommitted
replace click exit with system exit (#5841)
* replace click exit with system exit * more * from None * huhh
1 parent f33e27f commit a8e571d

File tree

9 files changed

+73
-82
lines changed

9 files changed

+73
-82
lines changed

reflex/custom_components/custom_components.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ def _get_default_library_name_parts() -> list[str]:
359359
"""Get the default library name. Based on the current directory name, remove any non-alphanumeric characters.
360360
361361
Raises:
362-
Exit: If the current directory name is not suitable for python projects, and we cannot find a valid library name based off it.
362+
SystemExit: If the current directory name is not suitable for python projects, and we cannot find a valid library name based off it.
363363
364364
Returns:
365365
The parts of default library name.
@@ -377,13 +377,13 @@ def _get_default_library_name_parts() -> list[str]:
377377
console.error(
378378
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."
379379
)
380-
raise click.exceptions.Exit(code=1)
380+
raise SystemExit(1)
381381
if not parts:
382382
# The folder likely has a name not suitable for python paths.
383383
console.error(
384384
f"Could not find a valid library name based on the current directory: got {current_dir_name}."
385385
)
386-
raise click.exceptions.Exit(code=1)
386+
raise SystemExit(1)
387387
return parts
388388

389389

@@ -408,7 +408,7 @@ def _validate_library_name(library_name: str | None) -> NameVariants:
408408
library_name: The name of the library if picked otherwise None.
409409
410410
Raises:
411-
Exit: If the library name is not suitable for python projects.
411+
SystemExit: If the library name is not suitable for python projects.
412412
413413
Returns:
414414
A tuple containing the various names such as package name, class name, etc., needed for the project.
@@ -419,7 +419,7 @@ def _validate_library_name(library_name: str | None) -> NameVariants:
419419
console.error(
420420
f"Please use only alphanumeric characters or dashes: got {library_name}"
421421
)
422-
raise click.exceptions.Exit(code=1)
422+
raise SystemExit(1)
423423

424424
# If not specified, use the current directory name to form the module name.
425425
name_parts = (
@@ -513,13 +513,13 @@ def init(
513513
install: Whether to install package from this local custom component in editable mode.
514514
515515
Raises:
516-
Exit: If the pyproject.toml already exists.
516+
SystemExit: If the pyproject.toml already exists.
517517
"""
518518
from reflex.utils import exec
519519

520520
if CustomComponents.PYPROJECT_TOML.exists():
521521
console.error(f"A {CustomComponents.PYPROJECT_TOML} already exists. Aborting.")
522-
click.exceptions.Exit(code=1)
522+
raise SystemExit(1)
523523

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

549549
console.print("[bold]Custom component initialized successfully!")
550550
console.rule("[bold]Project Summary")
@@ -627,7 +627,7 @@ def _run_build():
627627
"""Run the build command.
628628
629629
Raises:
630-
Exit: If the build fails.
630+
SystemExit: If the build fails.
631631
"""
632632
console.print("Building custom component...")
633633

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

642642

643643
@custom_components_cli.command(name="build")
@@ -651,7 +651,7 @@ def _collect_details_for_gallery():
651651
"""Helper to collect details on the custom component to be included in the gallery.
652652
653653
Raises:
654-
Exit: If pyproject.toml file is ill-formed or the request to the backend services fails.
654+
SystemExit: If pyproject.toml file is ill-formed or the request to the backend services fails.
655655
"""
656656
import httpx
657657
from reflex_cli.utils import hosting
@@ -664,7 +664,7 @@ def _collect_details_for_gallery():
664664
console.error(
665665
"Unable to authenticate with Reflex backend services. Make sure you are logged in."
666666
)
667-
raise click.exceptions.Exit(code=1)
667+
raise SystemExit(1)
668668

669669
console.rule("[bold]Custom Component Information")
670670
params = {}
@@ -694,11 +694,11 @@ def _collect_details_for_gallery():
694694
console.error(
695695
f"{package_name} is owned by another user. Unable to update the information for it."
696696
)
697-
raise click.exceptions.Exit(code=1)
697+
raise SystemExit(1)
698698
response.raise_for_status()
699699
except httpx.HTTPError as he:
700700
console.error(f"Unable to complete request due to {he}.")
701-
raise click.exceptions.Exit(code=1) from he
701+
raise SystemExit(1) from None
702702

703703
files = []
704704
if (image_file_and_extension := _get_file_from_prompt_in_loop()) is not None:
@@ -733,7 +733,7 @@ def _collect_details_for_gallery():
733733

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

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

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

@@ -790,9 +790,9 @@ def install():
790790
"""Install package from this local custom component in editable mode.
791791
792792
Raises:
793-
Exit: If unable to install the current directory in editable mode.
793+
SystemExit: If unable to install the current directory in editable mode.
794794
"""
795795
if _pip_install_on_demand(package_name=".", install_args=["-e"]):
796796
console.info("Package installed successfully!")
797797
else:
798-
raise click.exceptions.Exit(code=1)
798+
raise SystemExit(1)

reflex/reflex.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ def run(
333333
"""Run the app in the current directory."""
334334
if frontend_only and backend_only:
335335
console.error("Cannot use both --frontend-only and --backend-only options.")
336-
raise click.exceptions.Exit(1)
336+
raise SystemExit(1)
337337

338338
config = get_config()
339339

reflex/utils/frontend_skeleton.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import re
66
from pathlib import Path
77

8-
import click
9-
108
from reflex import constants
119
from reflex.compiler import templates
1210
from reflex.config import Config, get_config
@@ -54,7 +52,7 @@ def initialize_requirements_txt() -> bool:
5452
True if the user has to update the requirements.txt file.
5553
5654
Raises:
57-
Exit: If the requirements.txt file cannot be read or written to.
55+
SystemExit: If the requirements.txt file cannot be read or written to.
5856
"""
5957
requirements_file_path = Path(constants.RequirementsTxt.FILE)
6058
if (
@@ -72,8 +70,8 @@ def initialize_requirements_txt() -> bool:
7270
except UnicodeDecodeError:
7371
continue
7472
except Exception as e:
75-
console.error(f"Failed to read {requirements_file_path}.")
76-
raise click.exceptions.Exit(1) from e
73+
console.error(f"Failed to read {requirements_file_path} due to {e}.")
74+
raise SystemExit(1) from None
7775
else:
7876
return True
7977

reflex/utils/js_runtimes.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from collections.abc import Sequence
77
from pathlib import Path
88

9-
import click
109
from packaging import version
1110

1211
from reflex import constants
@@ -193,7 +192,7 @@ def download_and_run(url: str, *args, show_status: bool = False, **env):
193192
env: The environment variables to use.
194193
195194
Raises:
196-
Exit: If the script fails to download.
195+
SystemExit: If the script fails to download.
197196
"""
198197
import httpx
199198

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

211210
# Save the script to a temporary file.
212211
with tempfile.NamedTemporaryFile() as tempfile_file:
@@ -226,7 +225,7 @@ def install_bun():
226225
227226
Raises:
228227
SystemPackageMissingError: If "unzip" is missing.
229-
Exit: If REFLEX_USE_NPM is set but Node.js is not installed.
228+
SystemExit: If REFLEX_USE_NPM is set but Node.js is not installed.
230229
"""
231230
if npm_escape_hatch():
232231
if get_node_version() is not None:
@@ -237,7 +236,7 @@ def install_bun():
237236
console.error(
238237
"REFLEX_USE_NPM is set, but Node.js is not installed. Please install Node.js to use npm."
239238
)
240-
raise click.exceptions.Exit(1)
239+
raise SystemExit(1)
241240

242241
bun_path = path_ops.get_bun_path()
243242

@@ -290,7 +289,7 @@ def validate_bun(bun_path: Path | None = None):
290289
bun_path: The path to the bun executable. If None, the default bun path is used.
291290
292291
Raises:
293-
Exit: If custom specified bun does not exist or does not meet requirements.
292+
SystemExit: If custom specified bun does not exist or does not meet requirements.
294293
"""
295294
bun_path = bun_path or path_ops.get_bun_path()
296295

@@ -304,7 +303,7 @@ def validate_bun(bun_path: Path | None = None):
304303
console.error(
305304
"Failed to obtain bun version. Make sure the specified bun path in your config is correct."
306305
)
307-
raise click.exceptions.Exit(1)
306+
raise SystemExit(1)
308307
if bun_version < version.parse(constants.Bun.MIN_VERSION):
309308
console.warn(
310309
f"Reflex requires bun version {constants.Bun.MIN_VERSION} or higher to run, but the detected version is "
@@ -320,20 +319,21 @@ def validate_frontend_dependencies(init: bool = True):
320319
init: whether running `reflex init`
321320
322321
Raises:
323-
Exit: If the package manager is invalid.
322+
SystemExit: If the package manager is invalid.
324323
"""
325324
if not init:
326325
try:
327326
get_js_package_executor(raise_on_none=True)
328327
except FileNotFoundError as e:
329-
raise click.exceptions.Exit(1) from e
328+
console.error(f"Failed to find a valid package manager due to {e}.")
329+
raise SystemExit(1) from None
330330

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

338338

339339
def remove_existing_bun_installation():

reflex/utils/prerequisites.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from types import ModuleType
1616
from typing import NamedTuple
1717

18-
import click
1918
from alembic.util.exc import CommandError
2019
from packaging import version
2120
from redis import Redis as RedisSync
@@ -444,22 +443,22 @@ def validate_app_name(app_name: str | None = None) -> str:
444443
The app name after validation.
445444
446445
Raises:
447-
Exit: if the app directory name is reflex or if the name is not standard for a python package name.
446+
SystemExit: if the app directory name is reflex or if the name is not standard for a python package name.
448447
"""
449448
app_name = app_name if app_name else Path.cwd().name.replace("-", "_")
450449
# Make sure the app is not named "reflex".
451450
if app_name.lower() == constants.Reflex.MODULE_NAME:
452451
console.error(
453452
f"The app directory cannot be named [bold]{constants.Reflex.MODULE_NAME}[/bold]."
454453
)
455-
raise click.exceptions.Exit(1)
454+
raise SystemExit(1)
456455

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

464463
return app_name
465464

@@ -499,13 +498,13 @@ def assert_in_reflex_dir():
499498
"""Assert that the current working directory is the reflex directory.
500499
501500
Raises:
502-
Exit: If the current working directory is not the reflex directory.
501+
SystemExit: If the current working directory is not the reflex directory.
503502
"""
504503
if not constants.Config.FILE.exists():
505504
console.error(
506505
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."
507506
)
508-
raise click.exceptions.Exit(1)
507+
raise SystemExit(1)
509508

510509

511510
def needs_reinit() -> bool:

0 commit comments

Comments
 (0)