Skip to content

Commit

Permalink
feat: refactor cli (#607)
Browse files Browse the repository at this point in the history
CLI refactor

- Closes #413
- Closes #549 as OBE
  • Loading branch information
gadomski authored Jan 23, 2025
1 parent 0ea1c8f commit 268ab6e
Show file tree
Hide file tree
Showing 22 changed files with 660 additions and 1,263 deletions.
130 changes: 26 additions & 104 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,68 +43,33 @@ jobs:
run: cargo install cargo-all-features
- name: Check
run: cargo check-all-features
test-api:
name: Test stac-api
test:
name: Test
runs-on: ubuntu-latest
env:
DUCKDB_LIB_DIR: /opt/duckdb
DUCKDB_INCLUDE_DIR: /opt/duckdb
LD_LIBRARY_PATH: /opt/duckdb
steps:
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
- name: Test
run: cargo test -p stac-api --all-features
test-cli:
name: Test stac-cli
runs-on: ubuntu-latest
defaults:
run:
working-directory: crates/cli
steps:
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
- name: Test
run: cargo test -p stac-cli
test-cli-python:
name: Test stacrs-cli (python)
runs-on: ubuntu-latest
defaults:
run:
working-directory: crates/cli
steps:
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
- uses: actions/setup-python@v5
with:
python-version: 3.x
- uses: astral-sh/setup-uv@v5
with:
enable-cache: true
- name: Install
run: uv sync
- name: Smoke test
run: uv run stacrs --version
test-duckdb:
name: Test stac-duckdb
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
- name: Get DuckDB
run: |
wget https://github.com/duckdb/duckdb/releases/download/v1.1.3/libduckdb-linux-amd64.zip
unzip libduckdb-linux-amd64.zip -d /opt/duckdb
- name: Fmt
run: cargo fmt
- name: Clippy
run: cargo clippy --workspace --all-features
- name: Build # need to build first to get the executable for CLI tests
run: cargo build --all-features
- name: Test
run: cargo test -p stac-duckdb
env:
DUCKDB_LIB_DIR: /opt/duckdb
DUCKDB_INCLUDE_DIR: /opt/duckdb
LD_LIBRARY_PATH: /opt/duckdb
test-extensions:
name: Test stac-extensions
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
- name: Test
run: cargo test -p stac-extensions
run: cargo test --all-features
- name: Validate stac-server
run: uv run --group stac-api-validator scripts/validate-stac-server
- name: Validate stac-geoparquet
run: uv run --group stac-geoparquet scripts/validate-stac-geoparquet
test-pgstac:
name: Test pgstac
runs-on: ubuntu-latest
Expand All @@ -113,6 +78,10 @@ jobs:
pgstac_version:
- v0.8.6
- v0.9.1
env:
DUCKDB_LIB_DIR: /opt/duckdb
DUCKDB_INCLUDE_DIR: /opt/duckdb
LD_LIBRARY_PATH: /opt/duckdb
services:
pgstac:
image: ghcr.io/stac-utils/pgstac:${{ matrix.pgstac_version }}
Expand All @@ -128,46 +97,15 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
- uses: actions/setup-python@v5
with:
python-version: "3.10"
- uses: astral-sh/setup-uv@v5
with:
enable-cache: true
- name: Get DuckDB
run: |
wget https://github.com/duckdb/duckdb/releases/download/v1.1.3/libduckdb-linux-amd64.zip
unzip libduckdb-linux-amd64.zip -d /opt/duckdb
- name: Test
run: cargo test -p pgstac --all-features
- name: Install Python dependencies
run: uv sync --group stac-api-validator
- name: Validate
run: uv run scripts/validate-stac-server --pgstac
test-server:
name: Test stac-server
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
- uses: actions/setup-python@v5
with:
python-version: "3.x"
- uses: astral-sh/setup-uv@v5
with:
enable-cache: true
- name: Test
run: cargo test -p stac-server --all-features
- name: Install Python dependencies
run: uv sync --group stac-api-validator
- name: Validate
run: uv run scripts/validate-stac-server
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
- name: Fmt
run: cargo fmt
- name: Clippy
run: cargo clippy --workspace --all-features
run: uv run --group stac-api-validator scripts/validate-stac-server --pgstac
check-nightly:
name: Check (nightly)
runs-on: ubuntu-latest
Expand Down Expand Up @@ -195,19 +133,3 @@ jobs:
- uses: DavidAnson/markdownlint-cli2-action@v19
- name: Doc
run: cargo doc --workspace --all-features
validate-stac-geoparquet:
name: Validate stac-geoparquet
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
- uses: actions/setup-python@v5
with:
python-version: "3.x"
- uses: astral-sh/setup-uv@v5
with:
enable-cache: true
- name: Install Python dependencies
run: uv sync --group stac-geoparquet
- name: Validate
run: uv run scripts/validate-stac-geoparquet
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ default-members = [
"crates/cli",
"crates/core",
"crates/derive",
"crates/duckdb",
"crates/extensions",
"crates/server",
]

[workspace.package]
Expand All @@ -28,6 +30,7 @@ categories = ["science", "data-structures"]
rust-version = "1.82"

[workspace.dependencies]
anyhow = "1.0"
arrow = "53.1.0"
arrow-array = "53.1.0"
arrow-cast = "53.1.0"
Expand Down
1 change: 1 addition & 0 deletions crates/api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
### Added

- kwargs to Python search build ([#591](https://github.com/stac-utils/stac-rs/pull/591))
- `client::search` function ([#607](https://github.com/stac-utils/stac-rs/pull/607))

## [0.7.0] - 2025-01-02

Expand Down
34 changes: 34 additions & 0 deletions crates/api/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,40 @@ use tokio::{

const DEFAULT_CHANNEL_BUFFER: usize = 4;

/// Searches a STAC API.
pub async fn search(
href: &str,
mut search: Search,
max_items: Option<usize>,
) -> Result<ItemCollection> {
let client = Client::new(href)?;
if search.limit.is_none() {
if let Some(max_items) = max_items {
search.limit = Some(max_items.try_into()?);
}
}
let stream = client.search(search).await.unwrap();
let mut items = if let Some(max_items) = max_items {
if max_items == 0 {
return Ok(ItemCollection::default());
}
Vec::with_capacity(max_items)
} else {
Vec::new()
};
pin_mut!(stream);
while let Some(item) = stream.next().await {
let item = item?;
items.push(item);
if let Some(max_items) = max_items {
if items.len() >= max_items {
break;
}
}
}
ItemCollection::new(items)
}

/// A client for interacting with STAC APIs.
#[derive(Clone, Debug)]
pub struct Client {
Expand Down
4 changes: 4 additions & 0 deletions crates/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]

### Changed

- Pretty big code refactor and a lot of options ([#607](https://github.com/stac-utils/stac-rs/pull/607))

## [0.4.1] - 2024-10-22

### Changed
Expand Down
6 changes: 3 additions & 3 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ rust-version.workspace = true

[features]
default = ["pgstac"]
duckdb = ["dep:stac-duckdb"]
pgstac = ["stac-server/pgstac", "dep:tokio-postgres"]
python = ["dep:pyo3", "pgstac"]

[dependencies]
anyhow.workspace = true
axum.workspace = true
clap = { workspace = true, features = ["derive"] }
object_store.workspace = true
Expand All @@ -32,7 +32,7 @@ stac = { workspace = true, features = [
"validate",
] }
stac-api = { workspace = true, features = ["client"] }
stac-duckdb = { workspace = true, optional = true }
stac-duckdb.workspace = true
stac-server = { workspace = true, features = ["axum"] }
thiserror.workspace = true
tokio = { workspace = true, features = [
Expand All @@ -49,7 +49,7 @@ url.workspace = true

[dev-dependencies]
assert_cmd.workspace = true
tokio-test.workspace = true
rstest.workspace = true

[lib]
crate-type = ["lib", "cdylib"]
Expand Down
Loading

0 comments on commit 268ab6e

Please sign in to comment.