diff --git a/apps/rocm/src/comfyui.rs b/apps/rocm/src/comfyui.rs index 639f5cdaa7..6bb6fd59ea 100644 --- a/apps/rocm/src/comfyui.rs +++ b/apps/rocm/src/comfyui.rs @@ -2,32 +2,30 @@ // // SPDX-License-Identifier: MIT -use crate::cli_progress::AnimatedSpinner; -use crate::freeform_planner::format_structured_tool_call; -use crate::runtimes_cmd::runtime_usability_status; use crate::therock; use anyhow::{Context, Result, bail}; -use flate2::read::GzDecoder; -use rocm_core::browser::{Opener, SystemOpener}; +use process::{comfyui_run_state_cli_label, endpoint_is_reachable, evaluate_running_state}; use rocm_core::{ - AppPaths, RocmCliConfig, download_file_to_path_with_progress, ensure_uv_binary, - format_http_base_url, powershell_quote, runtime_is_linux, runtime_is_windows, - runtime_path_for_windows_child, runtime_path_list_join, runtime_path_list_split, - runtime_paths_equivalent, unix_time_millis, uv_command_env, uv_pip_install_base, + AppPaths, RocmCliConfig, format_http_base_url, runtime_is_windows, + runtime_path_for_windows_child, unix_time_millis, }; +use runtime_env::apply_runtime_environment; use serde::{Deserialize, Serialize}; -use std::ffi::OsString; use std::fmt::Write as FmtWrite; use std::fs; -use std::io::{self, IsTerminal, Read, Write as IoWrite}; -use std::net::{TcpStream, ToSocketAddrs}; +use std::io; use std::path::{Path, PathBuf}; use std::process::{Command, ExitStatus, Stdio}; -use std::thread; -use std::time::{Duration, SystemTime}; +use std::time::SystemTime; +mod install; +mod process; +mod runtime_env; mod source_swap; +pub(crate) use install::install; +pub(crate) use process::{start, stop}; + const APP_ID: &str = "comfyui"; const APP_NAME: &str = "ComfyUI"; const COMFYUI_SOURCE_ARCHIVE_URL: &str = @@ -370,390 +368,6 @@ fn render_logs_with_options( Ok(output) } -pub(crate) fn install( - paths: &AppPaths, - config: &RocmCliConfig, - options: ComfyUiInstallOptions, -) -> Result { - paths.ensure()?; - let runtime = select_runtime(paths, config, options.runtime_id.as_deref())?; - let app_root = runtime_app_root(&runtime.manifest); - let source_path = source_path_from_app_root(&app_root); - let log_path = install_log_path_from_app_root(&app_root); - let requirements_path = source_path.join("requirements.txt"); - let models_folder = models_folder_for_source(&source_path); - let runtime_env = runtime_environment_from_runtime(&runtime.manifest, &runtime.python); - - let mut output = String::new(); - writeln!(output, "{APP_NAME}")?; - writeln!(output, " action: install")?; - writeln!( - output, - " ROCm runtime: {}", - therock::runtime_version_display(&runtime.manifest.version) - )?; - writeln!(output, " folder: {}", source_path.display())?; - writeln!(output, " models path: {}", models_folder.display())?; - - // A reinstall that was interrupted part-way through replacing the code is - // finished by the next install, with or without `--reinstall`, rather than - // left as a half-replaced tree that would be reused as it is. - let finishes_interrupted = source_swap::swap_interrupted(&source_path); - let replaces_existing = source_path.exists() && (options.reinstall || finishes_interrupted); - if options.dry_run { - writeln!(output, " mode: dry-run")?; - if replaces_existing { - if finishes_interrupted { - writeln!( - output, - " note: a previous reinstall was interrupted; installing finishes it" - )?; - } - writeln!( - output, - " reinstall: replaces the ComfyUI code in {}", - source_path.display() - )?; - // The real run checks the same thing and refuses. - let mut warnings = Vec::new(); - if let Some(state) = running_from(paths, &source_path, &mut warnings) { - writeln!( - output, - " note: {}; a reinstall is refused until then", - running_advice(&source_path, &state) - )?; - } - for warning in warnings { - writeln!(output, " note: {warning}")?; - } - // The same list the real run reports as `kept:` — read from the - // interrupted run's marker when there is one. - let keeps = source_swap::planned_kept(&source_path); - if !keeps.is_empty() { - writeln!(output, " keeps: {}", keeps.join(", "))?; - } - // Which entries those are is only known once the new release is - // unpacked. `source_swap`'s - // `swap_replaces_release_code_and_leaves_everything_else_in_place`, - // `user_entry_named_like_new_release_code_is_set_aside` and - // `install_from_before_the_record_removes_only_what_the_new_release_ships` - // prove these lines; comfyui-05 and comfyui-10 the lines the real - // run prints. - if source_swap::has_release_record(&source_path) { - writeln!( - output, - " leaves in place: everything else in that folder that the installed release \ - did not ship" - )?; - writeln!( - output, - " sets aside: anything of yours named like code the new release adds, \ - renamed to {}