Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ vortex-cuda-macros = { path = "./vortex-cuda/macros" }
vortex-duckdb = { path = "./vortex-duckdb", default-features = false }
vortex-test-e2e = { path = "./vortex-test/e2e", default-features = false }
vortex-test-e2e-cuda = { path = "./vortex-test/e2e-cuda", default-features = false }
vortex-tui = { path = "./vortex-tui" }

[workspace.dependencies.getrandom_v03]
features = ["wasm_js"]
Expand Down
1 change: 1 addition & 0 deletions vortex-python/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ tokio = { workspace = true, features = ["fs", "rt-multi-thread"] }
tracing = { workspace = true, features = ["std", "log"] }
url = { workspace = true }
vortex = { workspace = true, features = ["object_store", "tokio"] }
vortex-tui = { workspace = true }

[dev-dependencies]
vortex-array = { workspace = true, features = ["_test-harness"] }
3 changes: 3 additions & 0 deletions vortex-python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ classifiers = [
"Topic :: Scientific/Engineering",
]

[project.scripts]
vx = "vortex.cli:main"

[project.optional-dependencies]
polars = ["polars>=1.31.0"]
pandas = ["pandas>=2.2.0"]
Expand Down
4 changes: 4 additions & 0 deletions vortex-python/python/vortex/_lib/cli.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright the Vortex contributors

def launch(args: list[str]) -> None: ...
10 changes: 10 additions & 0 deletions vortex-python/python/vortex/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright the Vortex contributors

import sys


def main() -> None:
from vortex._lib.cli import launch # pyright: ignore[reportMissingModuleSource]

launch(sys.argv)
31 changes: 31 additions & 0 deletions vortex-python/src/cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright the Vortex contributors

use pyo3::exceptions::PyRuntimeError;
use pyo3::prelude::*;

use crate::SESSION;
use crate::TOKIO_RUNTIME;
use crate::install_module;

pub(crate) fn init(py: Python, parent: &Bound<PyModule>) -> PyResult<()> {
let m = PyModule::new(py, "cli")?;
parent.add_submodule(&m)?;
install_module("vortex._lib.cli", &m)?;

m.add_function(wrap_pyfunction!(launch, &m)?)?;

Ok(())
}

/// Launch the `vx` CLI with the given arguments.
///
/// Parameters
/// ----------
/// args : list[str]
/// Command-line arguments, typically ``sys.argv``.
#[pyfunction]
fn launch(py: Python, args: Vec<String>) -> PyResult<()> {
py.detach(|| TOKIO_RUNTIME.block_on(vortex_tui::launch_from(&SESSION, args)))
.map_err(|e| PyRuntimeError::new_err(e.to_string()))
}
2 changes: 2 additions & 0 deletions vortex-python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use pyo3::prelude::*;

pub(crate) mod arrays;
pub mod arrow;
mod cli;
mod compress;
mod dataset;
pub(crate) mod dtype;
Expand Down Expand Up @@ -61,6 +62,7 @@ fn _lib(py: Python, m: &Bound<PyModule>) -> PyResult<()> {

// Initialize our submodules, living under vortex._lib
arrays::init(py, m)?;
cli::init(py, m)?;
compress::init(py, m)?;
dataset::init(py, m)?;
dtype::init(py, m)?;
Expand Down
22 changes: 20 additions & 2 deletions vortex-tui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#![deny(clippy::missing_safety_doc)]
#![deny(missing_docs)]

use std::ffi::OsString;
use std::path::PathBuf;

use clap::CommandFactory;
Expand Down Expand Up @@ -79,13 +80,30 @@ impl Commands {

/// Main entrypoint for `vx` that launches a [`VortexSession`].
///
/// Parses arguments from [`std::env::args_os`]. See [`launch_from`] to supply explicit arguments.
///
/// # Errors
///
/// Raises any errors from subcommands.
pub async fn launch(session: &VortexSession) -> anyhow::Result<()> {
env_logger::init();
launch_from(session, std::env::args_os()).await
}

/// Launch `vx` with explicit command-line arguments.
///
/// This is useful when embedding the TUI inside another process (e.g. Python) where
/// [`std::env::args`] may not reflect the intended arguments.
///
/// # Errors
///
/// Raises any errors from subcommands.
pub async fn launch_from(
session: &VortexSession,
args: impl IntoIterator<Item = impl Into<OsString> + Clone>,
) -> anyhow::Result<()> {
let _ = env_logger::try_init();

let cli = Cli::parse();
let cli = Cli::parse_from(args);

let path = cli.command.file_path();
if !std::fs::exists(path)? {
Expand Down
Loading