Skip to content

Commit

Permalink
fix workflow; update
Browse files Browse the repository at this point in the history
  • Loading branch information
anemele committed Oct 1, 2024
1 parent 2e112c0 commit 0639515
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 35 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml → .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
include:
- label: x86_64-pc-windows-msvc-portable
target: x86_64-pc-windows-msvc
bins: --bin pvm
bins: --bin pyvm
os: windows
features:
rustflags:
Expand All @@ -43,7 +43,7 @@ jobs:
with:
name: ${{matrix.label}}
path: |
target/${{matrix.target}}/release/pvm.exe
target/${{matrix.target}}/release/pyvm.exe
test:
runs-on: ${{ matrix.os }}-latest
Expand Down Expand Up @@ -93,7 +93,7 @@ jobs:
run: |
mkdir public
cd target/x86_64-pc-windows-msvc-portable
zip -r ../../public/pvm-${{ env.VERSION }}-x86_64-pc-windows-msvc-portable.zip .
zip -r ../../public/pyvm-${{ env.VERSION }}-x86_64-pc-windows-msvc-portable.zip .
cd ../..
- uses: actions/upload-artifact@v3
with:
Expand Down
8 changes: 3 additions & 5 deletions src/cmd_add.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use anyhow::anyhow;

use crate::get_venv_path;
use std::process::{Command, Stdio};

Expand All @@ -9,7 +7,7 @@ pub fn exec(name: &str, version: Option<String>, force: bool) -> anyhow::Result<
let path = get_venv_path()?.join(name);

if path.is_file() || (path.is_dir() && !force) {
return Err(anyhow!("Env with the same name `{name}` exists."));
anyhow::bail!("Env with the same name `{name}` exists.");
}

let mut cmd = &mut Command::new(VENV_EXE);
Expand All @@ -26,10 +24,10 @@ pub fn exec(name: &str, version: Option<String>, force: bool) -> anyhow::Result<
.stderr(Stdio::inherit())
.output()
{
return Err(anyhow!(
anyhow::bail!(
"Failed to create env `{name}`: {e}\nMaybe `{}` is not in PATH?",
VENV_EXE
));
);
};

#[cfg(target_family = "windows")]
Expand Down
12 changes: 2 additions & 10 deletions src/cmd_export.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use anyhow::anyhow;

use crate::consts::PY_BIN_DIR;
use crate::get_venv_path;
use crate::manifest::{Env, EnvManifest};
Expand All @@ -19,7 +17,7 @@ pub fn exec(output: Option<String>) -> anyhow::Result<()> {
let s = export_library()?;
let outpath = output.unwrap_or(export_filename());
if fs::write(&outpath, s).is_err() {
return Err(anyhow!("failed to write manifest."));
anyhow::bail!("failed to write manifest.");
}

println!("manifest has been written at {}", outpath);
Expand All @@ -29,13 +27,7 @@ pub fn exec(output: Option<String>) -> anyhow::Result<()> {
fn export_library() -> anyhow::Result<String> {
let venv_path = get_venv_path()?;

let sep = if cfg!(windows) {
"\r\n"
} else if cfg!(darwin) {
"\r"
} else {
"\n"
};
let sep = if cfg!(windows) { "\r\n" } else { "\n" };

let mut pipe = vec![];
for path in read_dir(&venv_path)? {
Expand Down
10 changes: 4 additions & 6 deletions src/cmd_remove.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
use anyhow::anyhow;

use crate::get_venv_path;
use crate::utils::is_valid_env;
use std::fs;

pub fn exec(name: &str) -> anyhow::Result<()> {
let path = get_venv_path()?.join(name);
if !path.exists() {
return Err(anyhow!("No env `{name}` exists."));
anyhow::bail!("No env `{name}` exists.");
}

if path.is_file() {
return Err(anyhow!("File with the same name `{name}` exists."));
anyhow::bail!("File with the same name `{name}` exists.");
}

if !is_valid_env(&path) {
return Err(anyhow!("Invalid env `{name}`"));
anyhow::bail!("Invalid env `{name}`");
}

if fs::remove_dir_all(path).is_err() {
return Err(anyhow!("Failed to remove `{name}`"));
anyhow::bail!("Failed to remove `{name}`");
}

println!("Removed env `{name}`");
Expand Down
8 changes: 3 additions & 5 deletions src/cmd_use.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
use anyhow::anyhow;

use crate::get_venv_path;
use crate::utils::is_valid_env;

pub fn exec(name: &str) -> anyhow::Result<()> {
let path = get_venv_path()?.join(name);

if !path.exists() {
return Err(anyhow!("No env `{name}` exists."));
anyhow::bail!("No env `{name}` exists.");
}

if !is_valid_env(&path) {
return Err(anyhow!("Invalid env `{name}`"));
anyhow::bail!("Invalid env `{name}`");
}

#[cfg(target_family = "windows")]
Expand All @@ -24,7 +22,7 @@ pub fn exec(name: &str) -> anyhow::Result<()> {
.arg(path.join("Scripts/activate.bat"))
.status()
{
return Err(anyhow!("Failed to activate env `{name}`:\n{e}"));
anyhow::bail!("Failed to activate env `{name}`:\n{e}");
}
}

Expand Down
8 changes: 2 additions & 6 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::consts::PYTHON_VENV_PATH;
use crate::consts::PY_BIN_DIR;
use crate::consts::PY_VENV_CFG;
use anyhow::anyhow;
use std::path::{Path, PathBuf};

pub fn is_valid_env(path: impl AsRef<Path>) -> bool {
Expand All @@ -11,9 +10,6 @@ pub fn is_valid_env(path: impl AsRef<Path>) -> bool {
}

pub(super) fn get_venv_path() -> anyhow::Result<PathBuf> {
if let Some(home) = homedir::get_my_home()? {
Ok(home.join(PYTHON_VENV_PATH))
} else {
Err(anyhow!("failed to get HOME dir"))
}
let home = homedir::get_my_home()?.ok_or(anyhow::anyhow!("failed to get HOME dir"))?;
Ok(home.join(PYTHON_VENV_PATH))
}

0 comments on commit 0639515

Please sign in to comment.