Skip to content

Commit 8c902cc

Browse files
committed
replace click exit with system exit
1 parent 5feefe3 commit 8c902cc

8 files changed

Lines changed: 45 additions & 45 deletions

File tree

reflex/custom_components/custom_components.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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

@@ -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 = (
@@ -519,7 +519,7 @@ def init(
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+
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")
@@ -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")
@@ -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 he
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 he
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 ose
773773
else:
774774
return image_file, file_extension
775775

@@ -795,4 +795,4 @@ def install():
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def initialize_requirements_txt() -> bool:
7373
continue
7474
except Exception as e:
7575
console.error(f"Failed to read {requirements_file_path}.")
76-
raise click.exceptions.Exit(1) from e
76+
raise SystemExit(1) from e
7777
else:
7878
return True
7979

reflex/utils/js_runtimes.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ def download_and_run(url: str, *args, show_status: bool = False, **env):
206206
console.error(
207207
f"Failed to download bun install script. You can install or update bun manually from https://bun.com \n{e}"
208208
)
209-
raise click.exceptions.Exit(1) from None
209+
raise SystemExit(1) from None
210210

211211
# Save the script to a temporary file.
212212
with tempfile.NamedTemporaryFile() as tempfile_file:
@@ -237,7 +237,7 @@ def install_bun():
237237
console.error(
238238
"REFLEX_USE_NPM is set, but Node.js is not installed. Please install Node.js to use npm."
239239
)
240-
raise click.exceptions.Exit(1)
240+
raise SystemExit(1)
241241

242242
bun_path = path_ops.get_bun_path()
243243

@@ -304,7 +304,7 @@ def validate_bun(bun_path: Path | None = None):
304304
console.error(
305305
"Failed to obtain bun version. Make sure the specified bun path in your config is correct."
306306
)
307-
raise click.exceptions.Exit(1)
307+
raise SystemExit(1)
308308
if bun_version < version.parse(constants.Bun.MIN_VERSION):
309309
console.warn(
310310
f"Reflex requires bun version {constants.Bun.MIN_VERSION} or higher to run, but the detected version is "
@@ -326,14 +326,14 @@ def validate_frontend_dependencies(init: bool = True):
326326
try:
327327
get_js_package_executor(raise_on_none=True)
328328
except FileNotFoundError as e:
329-
raise click.exceptions.Exit(1) from e
329+
raise SystemExit(1) from e
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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -452,14 +452,14 @@ def validate_app_name(app_name: str | None = None) -> str:
452452
console.error(
453453
f"The app directory cannot be named [bold]{constants.Reflex.MODULE_NAME}[/bold]."
454454
)
455-
raise click.exceptions.Exit(1)
455+
raise SystemExit(1)
456456

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

464464
return app_name
465465

@@ -505,7 +505,7 @@ def assert_in_reflex_dir():
505505
console.error(
506506
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."
507507
)
508-
raise click.exceptions.Exit(1)
508+
raise SystemExit(1)
509509

510510

511511
def needs_reinit() -> bool:

reflex/utils/processes.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def get_num_workers() -> int:
5050
redis_client.ping()
5151
except RedisError as re:
5252
console.error(f"Unable to connect to Redis: {re}")
53-
raise click.exceptions.Exit(1) from re
53+
raise SystemExit(1) from re
5454
return (os.cpu_count() or 1) * 2 + 1
5555

5656

@@ -146,7 +146,7 @@ def handle_port(service_name: str, port: int, auto_increment: bool) -> int:
146146
f"Unable to bind to any port for {service_name}. "
147147
"Please check your network configuration."
148148
)
149-
raise click.exceptions.Exit(1)
149+
raise SystemExit(1)
150150

151151
console.debug(
152152
f"Checking if {service_name.capitalize()} port: {port} is in use for families: {families}."
@@ -172,7 +172,7 @@ def handle_port(service_name: str, port: int, auto_increment: bool) -> int:
172172
else:
173173
console.error(f"{service_name.capitalize()} port: {port} is already in use.")
174174

175-
raise click.exceptions.Exit(1)
175+
raise SystemExit(1)
176176

177177

178178
@overload
@@ -217,7 +217,7 @@ def new_process(
217217
non_empty_args = list(filter(None, args)) if isinstance(args, list) else [args]
218218
if isinstance(args, list) and len(non_empty_args) != len(args):
219219
console.error(f"Invalid command: {args}")
220-
raise click.exceptions.Exit(1)
220+
raise SystemExit(1)
221221

222222
path_env: str = os.environ.get("PATH", "")
223223

@@ -376,15 +376,15 @@ def stream_logs(
376376
"NPM_CONFIG_REGISTRY environment variable. If TLS is the issue, and you know what "
377377
"you are doing, you can disable it by setting the SSL_NO_VERIFY environment variable."
378378
)
379-
raise click.exceptions.Exit(1)
379+
raise SystemExit(1)
380380
for set_of_logs in (*prior_logs, tuple(logs)):
381381
for line in set_of_logs:
382382
console.error(line, end="")
383383
console.error("\n\n")
384384
if analytics_enabled:
385385
telemetry.send("error", context=message)
386386
console.error("Run with [bold]--loglevel debug [/bold] for the full log.")
387-
raise click.exceptions.Exit(1)
387+
raise SystemExit(1)
388388

389389

390390
def show_logs(message: str, process: subprocess.Popen):

reflex/utils/rename.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,15 @@ def rename_app(new_app_name: str, loglevel: constants.LogLevel):
6666
console.error(
6767
"No rxconfig.py found. Make sure you are in the root directory of your app."
6868
)
69-
raise click.exceptions.Exit(1)
69+
raise SystemExit(1)
7070

7171
sys.path.insert(0, str(Path.cwd()))
7272

7373
config = get_config()
7474
module_path = get_module_path(config.module)
7575
if module_path is None:
7676
console.error(f"Could not find module {config.module}.")
77-
raise click.exceptions.Exit(1)
77+
raise SystemExit(1)
7878

7979
console.info(f"Renaming app directory to {new_app_name}.")
8080
process_directory(

reflex/utils/templates.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ def initialize_app_directory(
6161
console.error(
6262
f"Only {template_name=} should be provided, got {template_code_dir_name=}, {template_dir=}."
6363
)
64-
raise click.exceptions.Exit(1)
64+
raise SystemExit(1)
6565
template_code_dir_name = constants.Templates.Dirs.CODE
6666
template_dir = Path(constants.Templates.Dirs.BASE, "apps", template_name)
6767
else:
6868
if template_code_dir_name is None or template_dir is None:
6969
console.error(
7070
f"For `{template_name}` template, `template_code_dir_name` and `template_dir` should both be provided."
7171
)
72-
raise click.exceptions.Exit(1)
72+
raise SystemExit(1)
7373

7474
console.debug(f"Using {template_name=} {template_dir=} {template_code_dir_name=}.")
7575

@@ -127,7 +127,7 @@ def create_config_init_app_from_remote_template(app_name: str, template_url: str
127127
temp_dir = tempfile.mkdtemp()
128128
except OSError as ose:
129129
console.error(f"Failed to create temp directory for download: {ose}")
130-
raise click.exceptions.Exit(1) from ose
130+
raise SystemExit(1) from ose
131131

132132
# Use httpx GET with redirects to download the zip file.
133133
zip_file_path: Path = Path(temp_dir) / "template.zip"
@@ -138,32 +138,32 @@ def create_config_init_app_from_remote_template(app_name: str, template_url: str
138138
response.raise_for_status()
139139
except httpx.HTTPError as he:
140140
console.error(f"Failed to download the template: {he}")
141-
raise click.exceptions.Exit(1) from he
141+
raise SystemExit(1) from he
142142
try:
143143
zip_file_path.write_bytes(response.content)
144144
console.debug(f"Downloaded the zip to {zip_file_path}")
145145
except OSError as ose:
146146
console.error(f"Unable to write the downloaded zip to disk {ose}")
147-
raise click.exceptions.Exit(1) from ose
147+
raise SystemExit(1) from ose
148148

149149
# Create a temp directory for the zip extraction.
150150
try:
151151
unzip_dir = Path(tempfile.mkdtemp())
152152
except OSError as ose:
153153
console.error(f"Failed to create temp directory for extracting zip: {ose}")
154-
raise click.exceptions.Exit(1) from ose
154+
raise SystemExit(1) from ose
155155

156156
try:
157157
zipfile.ZipFile(zip_file_path).extractall(path=unzip_dir)
158158
# The zip file downloaded from github looks like:
159159
# repo-name-branch/**/*, so we need to remove the top level directory.
160160
except Exception as uze:
161161
console.error(f"Failed to unzip the template: {uze}")
162-
raise click.exceptions.Exit(1) from uze
162+
raise SystemExit(1) from uze
163163

164164
if len(subdirs := list(unzip_dir.iterdir())) != 1:
165165
console.error(f"Expected one directory in the zip, found {subdirs}")
166-
raise click.exceptions.Exit(1)
166+
raise SystemExit(1)
167167

168168
template_dir = unzip_dir / subdirs[0]
169169
console.debug(f"Template folder is located at {template_dir}")
@@ -215,7 +215,7 @@ def validate_and_create_app_using_remote_template(
215215
console.print(
216216
f"Please use `reflex login` to access the '{template}' template."
217217
)
218-
raise click.exceptions.Exit(3)
218+
raise SystemExit(3)
219219

220220
template_url = templates[template].code_url
221221
else:
@@ -226,7 +226,7 @@ def validate_and_create_app_using_remote_template(
226226
template_url = f"https://github.com/{path}/archive/main.zip"
227227
else:
228228
console.error(f"Template `{template}` not found or invalid.")
229-
raise click.exceptions.Exit(1)
229+
raise SystemExit(1)
230230

231231
if template_url is None:
232232
return
@@ -345,17 +345,17 @@ def prompt_for_template_options(templates: list[Template]) -> str:
345345

346346
if not template:
347347
console.error("No template selected.")
348-
raise click.exceptions.Exit(1)
348+
raise SystemExit(1)
349349

350350
try:
351351
template_index = int(template)
352352
except ValueError:
353353
console.error("Invalid template selected.")
354-
raise click.exceptions.Exit(1) from None
354+
raise SystemExit(1) from None
355355

356356
if template_index < 0 or template_index >= len(templates):
357357
console.error("Invalid template selected.")
358-
raise click.exceptions.Exit(1)
358+
raise SystemExit(1)
359359

360360
# Return the template.
361361
return templates[template_index].name
@@ -393,11 +393,11 @@ def initialize_app(app_name: str, template: str | None = None) -> str | None:
393393

394394
if template == constants.Templates.CHOOSE_TEMPLATES:
395395
redir.reflex_templates()
396-
raise click.exceptions.Exit(0)
396+
raise SystemExit(0)
397397

398398
if template == constants.Templates.AI:
399399
redir.reflex_build_redirect()
400-
raise click.exceptions.Exit(0)
400+
raise SystemExit(0)
401401

402402
# If the blank template is selected, create a blank app.
403403
if template == constants.Templates.DEFAULT:

0 commit comments

Comments
 (0)