From 3bff618ed67e92e3789212457d4b5b344ef0fae2 Mon Sep 17 00:00:00 2001 From: DahnJ Date: Sun, 23 Feb 2025 02:17:42 +0100 Subject: [PATCH] build(cli): CLI as optional dependency --- Cargo.lock | 2 ++ icechunk-python/Cargo.toml | 9 +++++++-- icechunk-python/pyproject.toml | 1 - icechunk-python/src/lib.rs | 18 +++++++++++++++--- icechunk/Cargo.toml | 14 ++++++++++---- icechunk/src/cli/mod.rs | 2 ++ 6 files changed, 36 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 74dbe3b2..8f7e3af1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1560,6 +1560,8 @@ dependencies = [ "bytes", "chrono", "clap", + "dialoguer", + "dirs", "futures", "icechunk", "itertools 0.14.0", diff --git a/icechunk-python/Cargo.toml b/icechunk-python/Cargo.toml index 90f8c579..193f8317 100644 --- a/icechunk-python/Cargo.toml +++ b/icechunk-python/Cargo.toml @@ -38,8 +38,13 @@ async-trait = "0.1.85" typetag = "0.2.19" serde = { version = "1.0.217", features = ["derive", "rc"] } miette = { version = "7.5.0", features = ["fancy"] } -clap = { version = "4.5", features = ["derive"] } -anyhow = "1.0.95" +clap = { version = "4.5", features = ["derive"], optional = true } +anyhow = { version = "1.0.95", optional = true } +dialoguer = { version = "0.11.0", optional = true } +dirs = { version = "6.0.0", optional = true } + +[features] +cli = ["dep:clap", "dep:anyhow", "dep:dialoguer", "dep:dirs", "icechunk/cli"] [lints] workspace = true diff --git a/icechunk-python/pyproject.toml b/icechunk-python/pyproject.toml index 9e72eafb..ded94e02 100644 --- a/icechunk-python/pyproject.toml +++ b/icechunk-python/pyproject.toml @@ -129,6 +129,5 @@ known-first-party = ["dask", "distributed", "icechunk", "xarray", "zarr"] # Disallow all relative imports. ban-relative-imports = "all" - [project.scripts] icechunk = "icechunk._icechunk_python:cli_entrypoint" diff --git a/icechunk-python/src/lib.rs b/icechunk-python/src/lib.rs index 162905d9..85c73de8 100644 --- a/icechunk-python/src/lib.rs +++ b/icechunk-python/src/lib.rs @@ -8,8 +8,6 @@ mod streams; use std::env; -use clap::error::ErrorKind; -use clap::Parser; use config::{ PyAzureCredentials, PyAzureStaticCredentials, PyCachingConfig, PyCompressionAlgorithm, PyCompressionConfig, PyCredentials, PyGcsBearerCredential, @@ -29,13 +27,19 @@ use errors::{ }; use icechunk::{format::format_constants::SpecVersionBin, initialize_tracing}; use pyo3::prelude::*; +use pyo3::wrap_pyfunction; use repository::{PyDiff, PyGCSummary, PyRepository, PySnapshotInfo}; use session::PySession; use store::PyStore; +#[cfg(feature = "cli")] +use clap::error::ErrorKind; +#[cfg(feature = "cli")] +use clap::Parser; +#[cfg(feature = "cli")] use icechunk::cli::interface::{run_cli, IcechunkCLI}; -use pyo3::wrap_pyfunction; +#[cfg(feature = "cli")] #[pyfunction] fn cli_entrypoint(py: Python) -> PyResult<()> { let sys = py.import("sys")?; @@ -64,6 +68,14 @@ fn cli_entrypoint(py: Python) -> PyResult<()> { } } +#[cfg(not(feature = "cli"))] +#[pyfunction] +fn cli_entrypoint(_py: Python) -> PyResult<()> { + Err(PyErr::new::( + "Must install the optional `cli` feature to use the CLI", + )) +} + #[pyfunction] fn initialize_logs() -> PyResult<()> { if env::var("ICECHUNK_NO_LOGS").is_err() { diff --git a/icechunk/Cargo.toml b/icechunk/Cargo.toml index 3f66debc..c6e085bf 100644 --- a/icechunk/Cargo.toml +++ b/icechunk/Cargo.toml @@ -55,10 +55,10 @@ tracing-subscriber = { version = "0.3.19", features = [ tracing = "0.1.41" err-into = "1.0.1" serde_yaml_ng = "0.10.0" -clap = { version = "4.5", features = ["derive"] } -anyhow = "1.0.95" -dialoguer = "0.11.0" -dirs = "6.0.0" +clap = { version = "4.5", features = ["derive"], optional = true } +anyhow = { version = "1.0.95", optional = true } +dialoguer = { version = "0.11.0", optional = true } +dirs = { version = "6.0.0", optional = true } [dev-dependencies] pretty_assertions = "1.4.1" @@ -70,3 +70,9 @@ workspace = true [features] logs = ["dep:tracing-subscriber"] +cli = ["dep:clap", "dep:anyhow", "dep:dialoguer", "dep:dirs"] + +[[bin]] +name = "icechunk" +path = "src/bin/icechunk/main.rs" +required-features = ["cli"] \ No newline at end of file diff --git a/icechunk/src/cli/mod.rs b/icechunk/src/cli/mod.rs index 210df837..06e0ba0f 100644 --- a/icechunk/src/cli/mod.rs +++ b/icechunk/src/cli/mod.rs @@ -1,2 +1,4 @@ +#[cfg(feature = "cli")] pub mod config; +#[cfg(feature = "cli")] pub mod interface;