Skip to content

Commit

Permalink
add version check to evaluate if python can run
Browse files Browse the repository at this point in the history
  • Loading branch information
jpopesculian committed Feb 13, 2024
1 parent c526e82 commit df3a2d0
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ jobs:
- run: cargo fmt --all --check
- run: cargo clippy -- -D warnings
- run: cargo build --release
- run: cargo run --release -- --version
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ axum = "0.7"
base32 = "0.4"
base64 = "0.21"
chrono = { version = "0.4", features = ["serde"] }
clap = { version = "4.4", features = ["derive"] }
clap = { version = "4.4", features = ["derive", "cargo"] }
dirs = "5.0"
fs4 = { version = "0.7", features = ["tokio"] }
futures = "0.3"
Expand All @@ -29,6 +29,7 @@ hostname = "0.3"
human-errors = "0.1"
ignore = "0.4.22"
indicatif = "0.17"
lazy_static = "1.4.0"
mime = "0.3.17"
open = "5.0"
pyo3 = { version = "0.20", features = ["auto-initialize", "serde"] }
Expand Down
3 changes: 2 additions & 1 deletion src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ mod python;
mod shell;
mod test;
mod upload;
mod version;

use install::{install, Install};
use login::{login, Login};
Expand All @@ -15,7 +16,7 @@ use upload::{upload, Upload};
use clap::Parser;

#[derive(Parser, Debug)]
#[command(author, version, about)]
#[command(author, version = version::version(), about)]
pub enum Cli {
Install(Install),
Login(Login),
Expand Down
10 changes: 8 additions & 2 deletions src/commands/python.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
use crate::dirs::{init_venv, read_pyproject};
use clap::Args;
use std::path::PathBuf;
use std::{ffi::OsString, path::PathBuf};

#[derive(Args, Debug)]
#[command(author, version, about)]
pub struct Python {
#[arg(short, long, default_value = ".")]
pub project_dir: PathBuf,
#[arg(last = true)]
pub slop: Vec<OsString>,
}

pub async fn python(args: Python) -> crate::error::Result<()> {
let _ = read_pyproject(&args.project_dir).await?;
let env = init_venv(&args.project_dir).await?;
env.python_cmd().spawn()?.wait().await?;
let mut cmd = env.python_cmd();
for arg in args.slop {
cmd.arg(arg);
}
cmd.spawn()?.wait().await?;
Ok(())
}
13 changes: 13 additions & 0 deletions src/commands/version.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use pyo3::Python;

lazy_static::lazy_static! {
static ref VERSION: String = format!(
"{}\nPython {}",
clap::crate_version!(),
Python::with_gil(|py| py.version().to_string())
);
}

pub fn version() -> clap::builder::Str {
VERSION.as_str().into()
}

0 comments on commit df3a2d0

Please sign in to comment.