Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
64805d3524 | ||
![]() |
4aadbd8fa9 |
@ -1,6 +1,6 @@
|
|||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "reflex"
|
name = "reflex"
|
||||||
version = "0.4.7"
|
version = "0.4.8"
|
||||||
description = "Web apps in pure Python."
|
description = "Web apps in pure Python."
|
||||||
license = "Apache-2.0"
|
license = "Apache-2.0"
|
||||||
authors = [
|
authors = [
|
||||||
|
@ -568,15 +568,17 @@ def update_next_config(export=False, transpile_packages: Optional[List[str]] = N
|
|||||||
export: if the method run during reflex export.
|
export: if the method run during reflex export.
|
||||||
transpile_packages: list of packages to transpile via next.config.js.
|
transpile_packages: list of packages to transpile via next.config.js.
|
||||||
"""
|
"""
|
||||||
next_config_file = os.path.join(constants.Dirs.WEB, constants.Next.CONFIG_FILE)
|
next_config_file = Path(constants.Dirs.WEB, constants.Next.CONFIG_FILE)
|
||||||
|
|
||||||
next_config = _update_next_config(
|
next_config = _update_next_config(
|
||||||
get_config(), export=export, transpile_packages=transpile_packages
|
get_config(), export=export, transpile_packages=transpile_packages
|
||||||
)
|
)
|
||||||
|
|
||||||
with open(next_config_file, "w") as file:
|
# Overwriting the next.config.js triggers a full server reload, so make sure
|
||||||
file.write(next_config)
|
# there is actually a diff.
|
||||||
file.write("\n")
|
orig_next_config = next_config_file.read_text() if next_config_file.exists() else ""
|
||||||
|
if orig_next_config != next_config:
|
||||||
|
next_config_file.write_text(next_config)
|
||||||
|
|
||||||
|
|
||||||
def _update_next_config(
|
def _update_next_config(
|
||||||
|
@ -202,13 +202,19 @@ def run_concurrently(*fns: Union[Callable, Tuple]) -> None:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def stream_logs(message: str, process: subprocess.Popen, progress=None):
|
def stream_logs(
|
||||||
|
message: str,
|
||||||
|
process: subprocess.Popen,
|
||||||
|
progress=None,
|
||||||
|
suppress_errors: bool = False,
|
||||||
|
):
|
||||||
"""Stream the logs for a process.
|
"""Stream the logs for a process.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
message: The message to display.
|
message: The message to display.
|
||||||
process: The process.
|
process: The process.
|
||||||
progress: The ongoing progress bar if one is being used.
|
progress: The ongoing progress bar if one is being used.
|
||||||
|
suppress_errors: If True, do not exit if errors are encountered (for fallback).
|
||||||
|
|
||||||
Yields:
|
Yields:
|
||||||
The lines of the process output.
|
The lines of the process output.
|
||||||
@ -232,7 +238,7 @@ def stream_logs(message: str, process: subprocess.Popen, progress=None):
|
|||||||
# Windows uvicorn bug
|
# Windows uvicorn bug
|
||||||
# https://github.com/reflex-dev/reflex/issues/2335
|
# https://github.com/reflex-dev/reflex/issues/2335
|
||||||
accepted_return_codes = [0, -2, 15] if constants.IS_WINDOWS else [0, -2]
|
accepted_return_codes = [0, -2, 15] if constants.IS_WINDOWS else [0, -2]
|
||||||
if process.returncode not in accepted_return_codes:
|
if process.returncode not in accepted_return_codes and not suppress_errors:
|
||||||
console.error(f"{message} failed with exit code {process.returncode}")
|
console.error(f"{message} failed with exit code {process.returncode}")
|
||||||
for line in logs:
|
for line in logs:
|
||||||
console.error(line, end="")
|
console.error(line, end="")
|
||||||
@ -251,15 +257,16 @@ def show_logs(message: str, process: subprocess.Popen):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def show_status(message: str, process: subprocess.Popen):
|
def show_status(message: str, process: subprocess.Popen, suppress_errors: bool = False):
|
||||||
"""Show the status of a process.
|
"""Show the status of a process.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
message: The initial message to display.
|
message: The initial message to display.
|
||||||
process: The process.
|
process: The process.
|
||||||
|
suppress_errors: If True, do not exit if errors are encountered (for fallback).
|
||||||
"""
|
"""
|
||||||
with console.status(message) as status:
|
with console.status(message) as status:
|
||||||
for line in stream_logs(message, process):
|
for line in stream_logs(message, process, suppress_errors=suppress_errors):
|
||||||
status.update(f"{message} {line}")
|
status.update(f"{message} {line}")
|
||||||
|
|
||||||
|
|
||||||
@ -298,29 +305,22 @@ def run_process_with_fallback(args, *, show_status_message, fallback=None, **kwa
|
|||||||
fallback: The fallback command to run.
|
fallback: The fallback command to run.
|
||||||
kwargs: Kwargs to pass to new_process function.
|
kwargs: Kwargs to pass to new_process function.
|
||||||
"""
|
"""
|
||||||
|
process = new_process(args, **kwargs)
|
||||||
def execute_process(process):
|
if fallback is None:
|
||||||
if not constants.IS_WINDOWS:
|
# No fallback given, or this _is_ the fallback command.
|
||||||
show_status(show_status_message, process)
|
show_status(show_status_message, process)
|
||||||
else:
|
else:
|
||||||
process.wait()
|
# Suppress errors for initial command, because we will try to fallback
|
||||||
|
show_status(show_status_message, process, suppress_errors=True)
|
||||||
if process.returncode != 0:
|
if process.returncode != 0:
|
||||||
error_output = process.stderr if process.stderr else process.stdout
|
|
||||||
error_message = f"Error occurred during subprocess execution: {' '.join(args)}\n{error_output.read() if error_output else ''}"
|
|
||||||
# Only show error in debug mode.
|
|
||||||
if console.is_debug():
|
|
||||||
console.error(error_message)
|
|
||||||
|
|
||||||
# retry with fallback command.
|
# retry with fallback command.
|
||||||
fallback_args = [fallback, *args[1:]] if fallback else None
|
fallback_args = [fallback, *args[1:]]
|
||||||
console.warn(
|
console.warn(
|
||||||
f"There was an error running command: {args}. Falling back to: {fallback_args}."
|
f"There was an error running command: {args}. Falling back to: {fallback_args}."
|
||||||
)
|
)
|
||||||
if fallback_args:
|
run_process_with_fallback(
|
||||||
process = new_process(fallback_args, **kwargs)
|
fallback_args,
|
||||||
execute_process(process)
|
show_status_message=show_status_message,
|
||||||
else:
|
fallback=None,
|
||||||
show_status(show_status_message, process)
|
**kwargs,
|
||||||
|
)
|
||||||
process = new_process(args, **kwargs)
|
|
||||||
execute_process(process)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user