Skip to content

Commit

Permalink
build(cli): CLI as optional dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
DahnJ committed Feb 23, 2025
1 parent 8f8d89f commit 3bff618
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 10 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

9 changes: 7 additions & 2 deletions icechunk-python/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion icechunk-python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
18 changes: 15 additions & 3 deletions icechunk-python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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")?;
Expand Down Expand Up @@ -64,6 +68,14 @@ fn cli_entrypoint(py: Python) -> PyResult<()> {
}
}

#[cfg(not(feature = "cli"))]
#[pyfunction]
fn cli_entrypoint(_py: Python) -> PyResult<()> {
Err(PyErr::new::<pyo3::exceptions::PyImportError, _>(
"Must install the optional `cli` feature to use the CLI",
))
}

#[pyfunction]
fn initialize_logs() -> PyResult<()> {
if env::var("ICECHUNK_NO_LOGS").is_err() {
Expand Down
14 changes: 10 additions & 4 deletions icechunk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"]
2 changes: 2 additions & 0 deletions icechunk/src/cli/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
#[cfg(feature = "cli")]
pub mod config;
#[cfg(feature = "cli")]
pub mod interface;

0 comments on commit 3bff618

Please sign in to comment.