From df3a2d0b62a63df084e4e753729235ec968abeff Mon Sep 17 00:00:00 2001 From: Julian Popescu Date: Tue, 13 Feb 2024 15:18:39 +0100 Subject: [PATCH] add version check to evaluate if python can run --- .github/workflows/build.yaml | 1 + Cargo.lock | 1 + Cargo.toml | 3 ++- src/commands/mod.rs | 3 ++- src/commands/python.rs | 10 ++++++++-- src/commands/version.rs | 13 +++++++++++++ 6 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 src/commands/version.rs diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 3e6e719..f892159 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -20,3 +20,4 @@ jobs: - run: cargo fmt --all --check - run: cargo clippy -- -D warnings - run: cargo build --release + - run: cargo run --release -- --version diff --git a/Cargo.lock b/Cargo.lock index d1a4c84..63e7c76 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -109,6 +109,7 @@ dependencies = [ "human-errors", "ignore", "indicatif", + "lazy_static", "mime", "open", "pyo3", diff --git a/Cargo.toml b/Cargo.toml index 64f0574..95ea260 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" @@ -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"] } diff --git a/src/commands/mod.rs b/src/commands/mod.rs index ac981b1..5756c52 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -4,6 +4,7 @@ mod python; mod shell; mod test; mod upload; +mod version; use install::{install, Install}; use login::{login, Login}; @@ -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), diff --git a/src/commands/python.rs b/src/commands/python.rs index 5e9bace..c013a53 100644 --- a/src/commands/python.rs +++ b/src/commands/python.rs @@ -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, } 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(()) } diff --git a/src/commands/version.rs b/src/commands/version.rs new file mode 100644 index 0000000..1527477 --- /dev/null +++ b/src/commands/version.rs @@ -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() +}