Skip to content

Commit

Permalink
Update self-venv on rye update (astral-sh#863)
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko authored Mar 10, 2024
1 parent e497653 commit 810aa94
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ _Unreleased_

- Trap panics and silence bad pipe errors. #862

- Updating `rye` will now also ensure that the self-venv is updated. Previously
this was deferred until the next `sync`. #863

## 0.28.0

Released on 2024-03-07
Expand Down
41 changes: 41 additions & 0 deletions rye/src/cli/rye.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,13 +273,54 @@ fn update(args: UpdateCommand) -> Result<(), Error> {
Please stop running Python interpreters and retry the update.",
)?;

echo!("Validate updated installation");
validate_updated_exe(&current_exe)
.context("unable to perform validation of updated installation")?;

echo!("Updated!");
echo!();
Command::new(current_exe).arg("--version").status()?;

Ok(())
}

fn validate_updated_exe(rye: &Path) -> Result<(), Error> {
let folder = tempfile::tempdir()?;

// first create a dummy project via the new rye version
if !Command::new(rye)
.arg("init")
.arg("--name=test-project")
.arg("-q")
.arg(".")
.current_dir(folder.path())
.status()?
.success()
{
bail!("failed to initialize test project");
}

// then try to run the python shim in the context of that project.
// this as a by product should update outdated internals and perform
// a python only sync in all versions of rye known currently.
if !Command::new(
get_app_dir()
.join("shims")
.join("python")
.with_extension(EXE_EXTENSION),
)
.arg("-c")
.arg("")
.current_dir(folder.path())
.status()?
.success()
{
bail!("failed to run python shim in test project");
}

Ok(())
}

fn update_exe_and_shims(new_exe: &Path) -> Result<(), Error> {
let app_dir = get_app_dir().canonicalize()?;
let current_exe = env::current_exe()?.canonicalize()?;
Expand Down

0 comments on commit 810aa94

Please sign in to comment.