Show status bar on reflex init (#1467)
* Show status bar on reflex init * Fix tests * Fix version * Fix test
This commit is contained in:
parent
068bcd906e
commit
f01eff5b29
@ -86,7 +86,7 @@ def init(
|
||||
prerequisites.initialize_gitignore()
|
||||
|
||||
# Finish initializing the app.
|
||||
console.success(f"Finished Initializing: {app_name}")
|
||||
console.success(f"Initialized {app_name}")
|
||||
|
||||
|
||||
@cli.command()
|
||||
|
@ -11,8 +11,7 @@ from typing import Optional, Union
|
||||
|
||||
from reflex import constants
|
||||
from reflex.config import get_config
|
||||
from reflex.utils import console, path_ops, prerequisites
|
||||
from reflex.utils.processes import new_process, show_progress
|
||||
from reflex.utils import console, path_ops, prerequisites, processes
|
||||
|
||||
|
||||
def update_json_file(file_path: str, update_dict: dict[str, Union[int, str]]):
|
||||
@ -122,11 +121,11 @@ def export(
|
||||
]
|
||||
|
||||
# Start the subprocess with the progress bar.
|
||||
process = new_process(
|
||||
process = processes.new_process(
|
||||
[prerequisites.get_package_manager(), "run", command],
|
||||
cwd=constants.WEB_DIR,
|
||||
)
|
||||
show_progress("Creating Production Build", process, checkpoints)
|
||||
processes.show_progress("Creating Production Build", process, checkpoints)
|
||||
|
||||
# Zip up the app.
|
||||
if zip:
|
||||
@ -192,7 +191,7 @@ def setup_frontend(
|
||||
|
||||
# Disable the Next telemetry.
|
||||
if disable_telemetry:
|
||||
new_process(
|
||||
processes.new_process(
|
||||
[
|
||||
prerequisites.get_package_manager(),
|
||||
"run",
|
||||
|
@ -8,7 +8,6 @@ from pathlib import Path
|
||||
from reflex import constants
|
||||
from reflex.config import get_config
|
||||
from reflex.utils import console, prerequisites, processes
|
||||
from reflex.utils.processes import new_process
|
||||
from reflex.utils.watch import AssetFolderWatch
|
||||
|
||||
|
||||
@ -30,7 +29,7 @@ def run_process_and_launch_url(
|
||||
Args:
|
||||
run_command: The command to run.
|
||||
"""
|
||||
process = new_process(
|
||||
process = processes.new_process(
|
||||
run_command,
|
||||
cwd=constants.WEB_DIR,
|
||||
)
|
||||
@ -95,7 +94,7 @@ def run_backend(
|
||||
port: The app port
|
||||
loglevel: The log level.
|
||||
"""
|
||||
new_process(
|
||||
processes.new_process(
|
||||
[
|
||||
"uvicorn",
|
||||
f"{app_name}:{constants.APP_VAR}.{constants.API_VAR}",
|
||||
@ -155,4 +154,4 @@ def run_backend_prod(
|
||||
"--workers",
|
||||
str(num_workers),
|
||||
]
|
||||
new_process(command, run=True, show_logs=True)
|
||||
processes.new_process(command, run=True, show_logs=True)
|
||||
|
@ -23,8 +23,7 @@ from redis import Redis
|
||||
|
||||
from reflex import constants, model
|
||||
from reflex.config import get_config
|
||||
from reflex.utils import console, path_ops
|
||||
from reflex.utils.processes import new_process, show_logs, show_status
|
||||
from reflex.utils import console, path_ops, processes
|
||||
|
||||
IS_WINDOWS = platform.system() == "Windows"
|
||||
|
||||
@ -37,7 +36,7 @@ def check_node_version() -> bool:
|
||||
"""
|
||||
try:
|
||||
# Run the node -v command and capture the output.
|
||||
result = new_process([constants.NODE_PATH, "-v"], run=True)
|
||||
result = processes.new_process([constants.NODE_PATH, "-v"], run=True)
|
||||
except FileNotFoundError:
|
||||
return False
|
||||
|
||||
@ -59,7 +58,7 @@ def get_bun_version() -> Optional[version.Version]:
|
||||
"""
|
||||
try:
|
||||
# Run the bun -v command and capture the output
|
||||
result = new_process([constants.BUN_PATH, "-v"], run=True)
|
||||
result = processes.new_process([constants.BUN_PATH, "-v"], run=True)
|
||||
return version.parse(result.stdout) # type: ignore
|
||||
except FileNotFoundError:
|
||||
return None
|
||||
@ -277,12 +276,13 @@ def initialize_node():
|
||||
install_node()
|
||||
|
||||
|
||||
def download_and_run(url: str, *args, **env):
|
||||
def download_and_run(url: str, *args, show_status: bool = False, **env):
|
||||
"""Download and run a script.
|
||||
|
||||
Args:
|
||||
url: The url of the script.
|
||||
args: The arguments to pass to the script.
|
||||
show_status: Whether to show the status of the script.
|
||||
env: The environment variables to use.
|
||||
"""
|
||||
# Download the script
|
||||
@ -298,8 +298,9 @@ def download_and_run(url: str, *args, **env):
|
||||
|
||||
# Run the script.
|
||||
env = {**os.environ, **env}
|
||||
process = new_process(["bash", f.name, *args], env=env)
|
||||
show_logs(f"Installing {url}", process)
|
||||
process = processes.new_process(["bash", f.name, *args], env=env)
|
||||
show = processes.show_status if show_status else processes.show_logs
|
||||
show(f"Installing {url}", process)
|
||||
|
||||
|
||||
def install_node():
|
||||
@ -319,11 +320,11 @@ def install_node():
|
||||
# Create the nvm directory and install.
|
||||
path_ops.mkdir(constants.NVM_DIR)
|
||||
env = {**os.environ, "NVM_DIR": constants.NVM_DIR}
|
||||
download_and_run(constants.NVM_INSTALL_URL, **env)
|
||||
download_and_run(constants.NVM_INSTALL_URL, show_status=True, **env)
|
||||
|
||||
# Install node.
|
||||
# We use bash -c as we need to source nvm.sh to use nvm.
|
||||
process = new_process(
|
||||
process = processes.new_process(
|
||||
[
|
||||
"bash",
|
||||
"-c",
|
||||
@ -331,7 +332,7 @@ def install_node():
|
||||
],
|
||||
env=env,
|
||||
)
|
||||
show_logs("Installing node", process)
|
||||
processes.show_status("", process)
|
||||
|
||||
|
||||
def install_bun():
|
||||
@ -366,20 +367,20 @@ def install_bun():
|
||||
def install_frontend_packages():
|
||||
"""Installs the base and custom frontend packages."""
|
||||
# Install the base packages.
|
||||
process = new_process(
|
||||
process = processes.new_process(
|
||||
[get_install_package_manager(), "install", "--loglevel", "silly"],
|
||||
cwd=constants.WEB_DIR,
|
||||
)
|
||||
show_status("Installing base frontend packages", process)
|
||||
processes.show_status("Installing base frontend packages", process)
|
||||
|
||||
# Install the app packages.
|
||||
packages = get_config().frontend_packages
|
||||
if len(packages) > 0:
|
||||
process = new_process(
|
||||
process = processes.new_process(
|
||||
[get_install_package_manager(), "add", *packages],
|
||||
cwd=constants.WEB_DIR,
|
||||
)
|
||||
show_status("Installing custom frontend packages", process)
|
||||
processes.show_status("Installing custom frontend packages", process)
|
||||
|
||||
|
||||
def check_initialized(frontend: bool = True):
|
||||
|
@ -205,7 +205,7 @@ def show_status(message: str, process: subprocess.Popen):
|
||||
"""
|
||||
with console.status(message) as status:
|
||||
for line in stream_logs(message, process):
|
||||
status.update(f"{message}: {line}")
|
||||
status.update(f"{message} {line}")
|
||||
|
||||
|
||||
def show_progress(message: str, process: subprocess.Popen, checkpoints: List[str]):
|
||||
|
@ -536,8 +536,8 @@ def test_node_install_unix(tmp_path, mocker):
|
||||
|
||||
mocker.patch("httpx.get", return_value=Resp())
|
||||
download = mocker.patch("reflex.utils.prerequisites.download_and_run")
|
||||
mocker.patch("reflex.utils.prerequisites.new_process")
|
||||
mocker.patch("reflex.utils.prerequisites.show_logs")
|
||||
mocker.patch("reflex.utils.processes.new_process")
|
||||
mocker.patch("reflex.utils.processes.stream_logs")
|
||||
|
||||
prerequisites.install_node()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user