Skip to content

Commit

Permalink
go back to using pip on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharsadhwani committed Jun 26, 2024
1 parent dbb607e commit adc478f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 20 deletions.
3 changes: 3 additions & 0 deletions src/yen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ def ensure_python(python_version: str) -> tuple[str, str]:


def create_venv(python_bin_path: str, venv_path: str) -> None:
if platform.system() == "Windows":
subprocess.run([python_bin_path, "-m", "venv", venv_path], check=True)

_ensure_microvenv()
subprocess.run([python_bin_path, MICROVENV_PATH, venv_path], check=True)
venv_python_path = _venv_binary_path("python", venv_path)
Expand Down
49 changes: 29 additions & 20 deletions yen-rs/src/commands/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use miette::IntoDiagnostic;

use crate::{
github::Version,
utils::{_ensure_microvenv, _venv_binary_path, ensure_python},
utils::{_ensure_microvenv, _venv_binary_path, ensure_python, IS_WINDOWS},
MICROVENV_PATH,
};

Expand All @@ -27,14 +27,21 @@ pub async fn create_env(python_bin_path: PathBuf, venv_path: &PathBuf) -> miette
miette::bail!("Error: {} already exists!", venv_path.to_string_lossy());
}

_ensure_microvenv().await?;
let stdout = Command::new(format!("{}", python_bin_path.to_string_lossy()))
.args([
&MICROVENV_PATH.to_string_lossy().into_owned(),
&venv_path.to_string_lossy().into_owned(),
])
.output()
.into_diagnostic()?;
let stdout = if IS_WINDOWS {
Command::new(format!("{}", python_bin_path.to_string_lossy()))
.args(["-m", "venv", &format!("{}", venv_path.to_string_lossy())])
.output()
.into_diagnostic()?
} else {
_ensure_microvenv().await?;
Command::new(format!("{}", python_bin_path.to_string_lossy()))
.args([
&MICROVENV_PATH.to_string_lossy().into_owned(),
&venv_path.to_string_lossy().into_owned(),
])
.output()
.into_diagnostic()?
};

if !stdout.status.success() {
miette::bail!(format!(
Expand All @@ -44,18 +51,20 @@ pub async fn create_env(python_bin_path: PathBuf, venv_path: &PathBuf) -> miette
));
}

let venv_python_path = _venv_binary_path("python", venv_path);
let stdout = Command::new(format!("{}", venv_python_path.to_string_lossy()))
.args(["-m", "ensurepip"])
.output()
.into_diagnostic()?;
if !IS_WINDOWS {
let venv_python_path = _venv_binary_path("python", venv_path);
let stdout = Command::new(format!("{}", venv_python_path.to_string_lossy()))
.args(["-m", "ensurepip"])
.output()
.into_diagnostic()?;

if !stdout.status.success() {
miette::bail!(format!(
"Error: unable to run ensurepip!\nStdout: {}\nStderr: {}",
String::from_utf8_lossy(&stdout.stdout),
String::from_utf8_lossy(&stdout.stderr),
));
if !stdout.status.success() {
miette::bail!(format!(
"Error: unable to run ensurepip!\nStdout: {}\nStderr: {}",
String::from_utf8_lossy(&stdout.stdout),
String::from_utf8_lossy(&stdout.stderr),
));
}
}

Ok(())
Expand Down

0 comments on commit adc478f

Please sign in to comment.