Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
f63710a
fix(therock): never delete an install folder to rebuild its venv
rominf Oct 6, 2026
e4bf0ad
fix(therock): route every non-empty install folder through the owners…
rominf Oct 6, 2026
18cb606
test(e2e): make the fake uv refuse a non-empty folder and preview the…
rominf Oct 6, 2026
3ff2dd7
test(therock): satisfy items_after_statements in the shape table
rominf Oct 6, 2026
8d8321c
fix(therock): reuse only a real venv; preview no command for a refuse…
rominf Oct 6, 2026
e54540b
test(therock): name clear stops without a shared suffix
rominf Oct 7, 2026
393e5c7
test(therock): pin the order a venv clear removes its entries in
rominf Oct 7, 2026
13338cf
test(therock): gate the Unix-only test imports to Unix
rominf Nov 9, 2026
2940fe4
fix(therock): run nothing from the install folder in a dry run
rominf Nov 9, 2026
fadfb2b
fix(therock): keep folder code and text out of the preview's probes
rominf Nov 9, 2026
2ae9ebd
test(therock): pin reuse at a bin-only stop and test the decision on …
rominf Nov 10, 2026
d80c8c3
test(therock): call cat by absolute path in the fake uv
rominf Nov 10, 2026
3fbbbe6
Merge origin/main into fix/uv-venv-repair-ownership
rominf Nov 12, 2026
fd2f46c
Merge origin/main into fix/uv-venv-repair-ownership
rominf Nov 16, 2026
302697e
fix(therock): keep the preview static under the torch opt-out; accept…
rominf Nov 16, 2026
b808b3b
test(therock): import unix_time_millis for the every-platform venv test
rominf Nov 16, 2026
06c2464
refactor(therock): carry the preview's paths on the resolved stack
rominf Nov 16, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 40 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -641,10 +641,43 @@ version. An upgrade or downgrade keeps the previous install on disk. Only a
same-version reinstall reuses the same root.

`--prefix` changes this. The folder you name is used as-is for every version, so
successive installs into one prefix replace each other in place. If the venv
already there no longer runs its own Python, it is removed outright and rebuilt.
The approval prompt doesn't cover this, because it asks only about changing the
active default runtime, not about what a named prefix loses.
successive installs into one prefix replace each other in place. A venv is
reused when its `pyvenv.cfg` is there and its Python runs, reports the required
wheel tag, and reports the folder as its `sys.prefix`. Otherwise, a folder that
is missing or empty gets a new venv, and a folder with anything in it is used
only if ROCm CLI can show a ROCm CLI install was made there: the
`.rocm-cli-runtime.json` a finished wheel install writes, naming that folder,
or a folder inside `runtimes/wheel` in ROCm CLI's data folder, where it puts
wheel runtimes itself. ROCm CLI then removes only the venv's own files
(`bin`/`Scripts`, `lib`/`Lib`, `lib64`, `include`/`Include`, `CACHEDIR.TAG`,
`pyvenv.cfg`), keeps everything else in the folder, such as ComfyUI's models,
workflows, and outputs under `apps/comfyui`, and prints what it kept and which
check the old venv failed. If that clearing stops part-way, the next install
sees an incomplete venv and clears it again. Any other non-empty folder, or one
in a protected system location, is refused with nothing changed, and the
refusal names what it found; choose an empty folder, or one where a ROCm CLI
install finished, instead.

`--dry-run` runs nothing from the install folder, since the folder can hold any
`bin/python`. It reads the folder's files and reports which of these will
happen, with `command: none` and a `refusal:` line holding the install's
message for a folder the install would refuse. Whether a folder holding both a
Python and `pyvenv.cfg` would be reused depends on running that Python, so the
preview says it cannot tell and shows both outcomes. A previewed `uv venv`
command is followed by an `env:` line naming the `UV_VENV_CLEAR=0` the install
sets for it, rather than a `VAR=value` prefix only POSIX shells accept. The
commands shown install the full torch stack. With
`ROCM_CLI_DISABLE_TORCH_ALIGNMENT` set, a venv the install reuses keeps the
torch it holds, so where the preview cannot tell whether the venv is reused a
`torch_kept:` line says it cannot tell which torch would be kept. If a Python the preview would check (`ROCM_CLI_PYTHON`,
the first on `PATH`, or the saved managed Python) is inside the `--prefix`
folder, it stops and says it did not run it.

ROCm CLI never runs `uv venv` over a folder that has anything in it without
`--allow-existing`, and sets `UV_VENV_CLEAR=0` for that command, so neither
uv's own handling of an existing folder (older uv deletes an existing venv,
newer uv refuses it) nor a `UV_VENV_CLEAR` exported in your shell can clear the
folder.

#### Which Python `install sdk` uses

Expand Down Expand Up @@ -698,9 +731,9 @@ The `--dry-run` preview downloads no `uv` and creates no `tools` folder. For ROC
10 and newer, `uv pip compile` is what chooses the `torch` and `torchvision`
versions, so the preview runs a `uv` that is already installed and gives the
complete plan. With none installed it can't, and it says so in a
`resolution_note:` line: the package specs, runtime key, install folder, manifest
and `command:` (everything made from those versions) read `not resolved by this
preview`, and a real install fetches `uv` and resolves them.
`resolution_note:` line: the package specs, runtime key, install folder, manifest,
`python_env:`, `command:` and `env:` (everything made from those versions) read
`not resolved by this preview`, and a real install fetches `uv` and resolves them.

A family label such as `--family gfx120X-all` is rejected for those versions
instead of being resolved to a guess, because the ROCm 10 packages publish one
Expand Down
10 changes: 10 additions & 0 deletions apps/rocm/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,11 @@ rocm install sdk --version 10.0.0 --python-version 3.12")]
#[arg(long, default_value = "wheel")]
format: InstallFormat,
/// Full folder path where the ROCm Python environment should be created.
///
/// Use an empty folder or one where a ROCm CLI install finished. In a
/// folder that is not empty, ROCm CLI reuses a working environment, or
/// rebuilds only its venv files if a ROCm CLI install was recorded
/// there; any other non-empty folder is refused with nothing changed.
#[arg(long)]
prefix: Option<std::path::PathBuf>,
/// Exact TheRock package version to install; with none, the channel's
Expand Down Expand Up @@ -888,6 +893,11 @@ rocm install sdk --version 10.0.0 --python-version 3.12")]
/// host with no uv installed, the plan marks the package versions it
/// would need uv to choose, and everything made from them, as not
/// resolved.
///
/// Runs nothing from the install folder: what happens to a Python
/// environment already there is read from its files, and where only
/// running its Python could tell whether it is reused, the plan says
/// so and shows both outcomes.
#[arg(long)]
dry_run: bool,
/// Approve replacing the current active default ROCm runtime (and
Expand Down
47 changes: 29 additions & 18 deletions apps/rocm/src/therock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ mod source;
#[cfg(test)]
mod test_support;
mod update;
mod venv;
mod version;
mod wheel_plan;

Expand All @@ -43,8 +44,7 @@ pub(crate) use self::probe::{
use self::process::{extract_tarball_and_discard_archive, progress_line, run_uv_progress_command};
pub(crate) use self::python::NEXT_MANAGED_PYTHON_VERSION;
use self::python::{
ensure_uv_venv, managed_python_version, python_for_install, python_requirement,
python_requirement_for_version,
managed_python_version, python_for_install, python_requirement, python_requirement_for_version,
};
use self::resolve::{
AggregateDeviceTarget, PipRuntimePlan, canonical_auto_select_needs_next_python,
Expand All @@ -62,6 +62,7 @@ pub(crate) use self::update::{
RuntimeUpdatePlan, maybe_refresh_startup_update_check, recorded_python_version,
render_update_json, render_update_report, runtime_update_check, runtime_update_plan,
};
use self::venv::ensure_uv_venv;
pub(crate) use self::version::runtime_version_display;
use self::version::{
parse_host_version, parse_version_for_ordering, runtime_version_build_date, version_relation,
Expand Down Expand Up @@ -414,7 +415,7 @@ fn install_wheel_runtime(
// configuration. It asks what a real install would do instead and prints
// that. A real install resolves, and so prepares, exactly as it always did.
// It also prints the line naming the interpreter, once the decision is made.
let python = python_for_install(paths, python_requirement, dry_run)?;
let python = python_for_install(paths, python_requirement, dry_run, prefix.as_deref())?;
let wheel_compatibility = python.wheel_compatibility()?;
progress_line(format!(
"Checking TheRock {} packages for this AMD GPU...",
Expand Down Expand Up @@ -493,13 +494,20 @@ fn install_wheel_runtime(
&resolution.latest_version,
);
// Under the alignment opt-out an environment that already holds torch keeps it:
// the install then asks `uv` for the ROCm packages alone. Decided here, from the
// environment the install will run in, so the preview and the install name the
// same requirements.
// the install then asks `uv` for the ROCm packages alone. Only running the
// environment's Python can tell which torch it holds, and a preview runs nothing
// from the install folder, so a preview shows the full command and, where the
// venv may be reused, says it cannot tell; a real install asks here and again
// once the environment is prepared.
let planned_env_python = venv_python_path(&install_root);
let planned_kept = kept_torch::kept_torch_stack(rocm_core::torch_alignment_disabled(), || {
kept_torch::installed_torch_stack(&planned_env_python)
});
let torch_alignment_disabled = rocm_core::torch_alignment_disabled();
let planned_kept = if dry_run {
None
} else {
kept_torch::kept_torch_stack(torch_alignment_disabled, || {
kept_torch::installed_torch_stack(&planned_env_python)
})
};
let plan = WheelPlan {
channel,
version_selector,
Expand All @@ -516,14 +524,15 @@ fn install_wheel_runtime(
torchaudio_pin: resolution.torchaudio_pin.as_ref(),
no_wheel_warning: no_wheel_warning.as_deref(),
stack: PlanStack::Resolved(ResolvedStack {
paths,
compatibility_key: &resolution.package_versions.compatibility_key,
install_root: &install_root,
runtime_key: &runtime_key,
package_specs: &wheel_composition.package_specs,
// A real install decides again once the environment is prepared (it may
// be recreated and lose its torch), and writes the one `torch_kept:` line
// then; a preview cannot know, so it prints the plan's.
kept_torch: if dry_run { planned_kept.as_ref() } else { None },
// A real install writes its one `torch_kept:` line once the environment
// is prepared (it may be recreated and lose its torch); a preview says
// what it could not tell.
torch_alignment_disabled,
manifest_path: &manifest_path,
}),
};
Expand Down Expand Up @@ -1069,11 +1078,13 @@ fn runtime_key(
}

fn managed_runtime_root(paths: &AppPaths, format: &str, runtime_key: &str) -> PathBuf {
paths
.data_dir
.join("runtimes")
.join(format)
.join(runtime_key)
managed_format_root(paths, format).join(runtime_key)
}

/// The folder every managed runtime of `format` is created in, one per
/// runtime key.
fn managed_format_root(paths: &AppPaths, format: &str) -> PathBuf {
paths.data_dir.join("runtimes").join(format)
}

/// Where to build a runtime, resolved to its real location on disk first.
Expand Down
10 changes: 6 additions & 4 deletions apps/rocm/src/therock/consent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,10 +411,12 @@ pub(super) fn refuse_non_interactive_message(relation: &str) -> String {
///
/// `--prefix` is the exception and the prompt does not claim otherwise:
/// `resolved_install_root` uses the given folder verbatim for every version, so
/// a second install into one prefix does replace the first in place (and
/// `ensure_uv_venv` will `remove_dir_all` it outright if the existing venv's
/// python no longer answers `--version`). The gate is unchanged either way —
/// what is being consented to is the change of active default, not a deletion.
/// a second install into one prefix does replace the first in place (and if
/// the existing venv's python no longer answers `--version`, `ensure_uv_venv`
/// rebuilds the venv's own files, and only when ROCm CLI can show it created
/// that venv; see `clear_owned_venv_for_rebuild`). The gate is unchanged either
/// way — what is being consented to is the change of active default, not a
/// deletion.
pub(super) fn confirm_overwrite_existing_sdk(
channel: TheRockChannel,
family: &str,
Expand Down
13 changes: 13 additions & 0 deletions apps/rocm/src/therock/kept_torch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,19 @@ pub(super) fn plan_line(kept: &KeptTorch) -> String {
)
}

/// The `torch_kept:` line a preview prints under the opt-out when the folder's
/// venv may be reused: the install would then keep the torch that venv holds,
/// and only running its Python could say which. A preview runs nothing from the
/// install folder, so the line says it cannot tell. Every other preview plan
/// creates or rebuilds the venv, or refuses the folder, so nothing is kept there
/// and no line is printed.
pub(super) fn preview_line(env_python: &Path) -> String {
format!(
" torch_kept: cannot tell; ROCM_CLI_DISABLE_TORCH_ALIGNMENT is set, so if the venv whose Python is {} is reused and holds torch, the install keeps that torch and hands uv only the ROCm packages, without the torch, torchvision and torchaudio requirements the commands shown include; this preview runs nothing from the install folder, so it does not know which torch that venv holds",
env_python.display()
)
}

/// The one `torch_kept:` line a real install prints, once the environment is
/// prepared: the plan's line when the torch is kept, an explanation when the
/// environment was recreated and the torch the plan counted on is gone.
Expand Down
47 changes: 38 additions & 9 deletions apps/rocm/src/therock/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,25 +85,37 @@ fn emit_progress_line(message: &str) {
PROGRESS_LINE_SINK.with(|sink| sink.borrow_mut().push(message.to_owned()));
}

fn capture_command_output(program: &Path, args: &[&str]) -> Result<Output> {
fn capture_command_output(program: &Path, args: &[&str], cwd: Option<&Path>) -> Result<Output> {
if runtime_is_windows() {
return capture_command_output_with_temp_files(program, args);
return capture_command_output_with_temp_files(program, args, cwd);
}
Command::new(program)
.args(args)
let mut command = Command::new(program);
command.args(args);
if let Some(cwd) = cwd {
command.current_dir(cwd);
}
command
.output()
.with_context(|| format!("failed to launch {}", program.display()))
}

fn capture_command_output_with_temp_files(program: &Path, args: &[&str]) -> Result<Output> {
fn capture_command_output_with_temp_files(
program: &Path,
args: &[&str],
cwd: Option<&Path>,
) -> Result<Output> {
let temp_dir = windows_temp_dir("rocm-cli-command")?;
let stdout_path = temp_dir.join("stdout.txt");
let stderr_path = temp_dir.join("stderr.txt");
let stdout_file = fs::File::create(&stdout_path)
.with_context(|| format!("failed to create {}", stdout_path.display()))?;
let stderr_file = fs::File::create(&stderr_path)
.with_context(|| format!("failed to create {}", stderr_path.display()))?;
let status = Command::new(program)
let mut command = Command::new(program);
if let Some(cwd) = cwd {
command.current_dir(cwd);
}
let status = command
.args(args)
.stdin(Stdio::null())
.stdout(Stdio::from(stdout_file))
Expand Down Expand Up @@ -170,7 +182,7 @@ pub(super) fn capture_python_stdout(
context_text: &str,
) -> Result<String> {
if !runtime_is_windows() {
let output = capture_command_output(python_executable, &["-c", script])?;
let output = capture_command_output(python_executable, &["-c", script], None)?;
if !output.status.success() {
bail!(
"{context_text}: {}",
Expand Down Expand Up @@ -235,8 +247,25 @@ fn windows_child_path(path: &Path) -> String {
}

pub(super) fn run_command(program: &Path, args: &[&str], context_text: &str) -> Result<()> {
run_command_in(program, args, None, context_text)
}

/// [`run_command`], started in `cwd` when one is given. `python -m` puts the
/// working directory first on `sys.path`, so a module run that way from a
/// folder someone else controls can import that folder's code instead of the
/// standard library's; a caller that runs one starts it in a folder it made.
pub(super) fn run_command_in(
program: &Path,
args: &[&str],
cwd: Option<&Path>,
context_text: &str,
) -> Result<()> {
if runtime_is_windows() {
let status = Command::new(program)
let mut command = Command::new(program);
if let Some(cwd) = cwd {
command.current_dir(cwd);
}
let status = command
.args(args)
.stdin(Stdio::null())
.stdout(Stdio::null())
Expand All @@ -249,7 +278,7 @@ pub(super) fn run_command(program: &Path, args: &[&str], context_text: &str) ->
bail!("{context_text}: command exited with status {status}");
}

let output = capture_command_output(program, args)?;
let output = capture_command_output(program, args, cwd)?;
if output.status.success() {
return Ok(());
}
Expand Down
Loading
Loading