Skip to content

Commit

Permalink
feat(python): add version
Browse files Browse the repository at this point in the history
  • Loading branch information
gadomski authored Oct 19, 2024
1 parent 8faf305 commit 0681fdf
Show file tree
Hide file tree
Showing 17 changed files with 1,114 additions and 1 deletion.
4 changes: 4 additions & 0 deletions crates/api/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]

### Added

- `version` ([#476](https://github.com/stac-utils/stac-rs/pull/476))

## [0.6.0] - 2024-09-19

### Added
Expand Down
11 changes: 11 additions & 0 deletions crates/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,17 @@ pub type Result<T> = std::result::Result<T, Error>;
/// servers to explicitly include or exclude certain fields.
pub type Item = serde_json::Map<String, serde_json::Value>;

/// Return this crate's version.
///
/// # Examples
///
/// ```
/// println!("{}", stac_api::version());
/// ```
pub fn version() -> &'static str {
env!("CARGO_PKG_VERSION")
}

#[cfg(test)]
use {geojson as _, tokio_test as _};
#[cfg(all(not(feature = "client"), test))]
Expand Down
4 changes: 4 additions & 0 deletions crates/core/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]

### Added

- `version` ([#476](https://github.com/stac-utils/stac-rs/pull/476))

## [0.10.2] - 2024-10-18

### Added
Expand Down
11 changes: 11 additions & 0 deletions crates/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,17 @@ where
}
}

/// Return this crate's version.
///
/// # Examples
///
/// ```
/// println!("{}", stac::version());
/// ```
pub fn version() -> &'static str {
env!("CARGO_PKG_VERSION")
}

#[cfg(test)]
mod tests {
use rstest as _;
Expand Down
4 changes: 4 additions & 0 deletions crates/duckdb/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]

### Added

- `version` ([#476](https://github.com/stac-utils/stac-rs/pull/476))

## [0.0.2] - 2024-09-19

### Changed
Expand Down
11 changes: 11 additions & 0 deletions crates/duckdb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,17 @@ fn repeat_vars(count: usize) -> String {
s
}

/// Return this crate's version.
///
/// # Examples
///
/// ```
/// println!("{}", stac_duckdb::version());
/// ```
pub fn version() -> &'static str {
env!("CARGO_PKG_VERSION")
}

#[cfg(test)]
mod tests {
use super::Client;
Expand Down
7 changes: 7 additions & 0 deletions docs/python/api/version.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
description: Return this package's version or the version of an upstream
---

# Version

::: stacrs.version
Binary file added docs/python/items-compressed.parquet
Binary file not shown.
1 change: 1 addition & 0 deletions docs/python/items.json

Large diffs are not rendered by default.

1,000 changes: 1,000 additions & 0 deletions docs/python/items.ndjson

Large diffs are not rendered by default.

Binary file added docs/python/items.parquet
Binary file not shown.
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ nav:
- read: python/api/read.md
- search: python/api/search.md
- validate: python/api/validate.md
- version: python/api/version.md
- write: python/api/write.md
- Command-line interface:
- cli/index.md
Expand Down
6 changes: 5 additions & 1 deletion python/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]

### Added

- `version` ([#476](https://github.com/stac-utils/stac-rs/pull/476))

### Changed

- Moved docstrings to stub file ([#468](https://github.com/stac-utils/stac-rs/pull/468))

### Removed

- `stacrs.pystac` ([#468](https://github.com/stac-utils/stac-rs/pull/468))
- `pystac` ([#468](https://github.com/stac-utils/stac-rs/pull/468))

## [0.1.3] - 2024-10-17

Expand Down
2 changes: 2 additions & 0 deletions python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mod migrate;
mod read;
mod search;
mod validate;
mod version;
mod write;

use duckdb as _;
Expand All @@ -23,6 +24,7 @@ fn stacrs(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_function(wrap_pyfunction!(search::search_to, m)?)?;
m.add_function(wrap_pyfunction!(validate::validate, m)?)?;
m.add_function(wrap_pyfunction!(validate::validate_href, m)?)?;
m.add_function(wrap_pyfunction!(version::version, m)?)?;
m.add_function(wrap_pyfunction!(write::write, m)?)?;
Ok(())
}
26 changes: 26 additions & 0 deletions python/src/version.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use duckdb::Connection;
use pyo3::prelude::*;

#[pyfunction]
#[pyo3(signature = (name=None))]
pub fn version(name: Option<String>) -> Option<String> {
if let Some(name) = name {
if name.eq_ignore_ascii_case("stac") {
Some(stac::version().to_string())
} else if name.eq_ignore_ascii_case("stac-api") {
Some(stac_api::version().to_string())
} else if name.eq_ignore_ascii_case("stac-duckdb") {
Some(stac_duckdb::version().to_string())
} else if name.eq_ignore_ascii_case("duckdb") {
Some(
Connection::open_in_memory()
.and_then(|c| c.version().map(|s| s[1..].to_string()))
.unwrap_or("unknown".to_string()),
)
} else {
None
}
} else {
Some(env!("CARGO_PKG_VERSION").to_string())
}
}
18 changes: 18 additions & 0 deletions python/stacrs.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -277,3 +277,21 @@ def write(
... items = json.load(f)
>>> stacrs.write("items.parquet", items)
"""

def version(name: str | None = None) -> str | None:
"""
Returns this package's version, or the version of a upstream.
Args:
name (str | None): The name of the upstream version to return. Valid
values are "stac", "stac-api", "stac-duckdb", or "duckdb".
Returns:
str: The version, or None if the name is not recognized as an upstream.
Examples:
>>> stacrs.version()
"0.2.0"
>>> stacrs.version("duckdb")
"1.0.0"
"""
9 changes: 9 additions & 0 deletions python/tests/test_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import stacrs


def test_version() -> None:
stacrs.version()
stacrs.version("stac")
stacrs.version("stac-api")
stacrs.version("stac-duckdb")
stacrs.version("duckdb")

0 comments on commit 0681fdf

Please sign in to comment.