diff --git a/CHANGELOG.md b/CHANGELOG.md index 9cbc9e3..6963703 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ### Added - Source distribution to PyPI publish ([#92](https://github.com/stac-utils/rustac-py/pull/92)) +- `rustac.sha` ([#99](https://github.com/stac-utils/rustac-py/pull/99)) ### Fixed diff --git a/Cargo.lock b/Cargo.lock index 471a23a..68fde0a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -685,6 +685,18 @@ version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a" +[[package]] +name = "cargo-lock" +version = "10.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06acb4f71407ba205a07cb453211e0e6a67b21904e47f6ba1f9589e38f2e454" +dependencies = [ + "semver", + "serde", + "toml", + "url", +] + [[package]] name = "cast" version = "0.3.0" @@ -3453,6 +3465,7 @@ dependencies = [ name = "rustac" version = "0.6.0" dependencies = [ + "cargo-lock", "clap", "geoarrow", "geojson", @@ -3637,6 +3650,9 @@ name = "semver" version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56e6fa9c48d24d85fb3de5ad847117517440f6beceb7798af16b4a87d616b8d0" +dependencies = [ + "serde", +] [[package]] name = "seq-macro" @@ -3687,6 +3703,15 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_spanned" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87607cb1398ed59d48732e575a4c28a7a8ebf2454b964fe3f224f2afc07909e1" +dependencies = [ + "serde", +] + [[package]] name = "serde_urlencoded" version = "0.7.1" @@ -4258,11 +4283,26 @@ dependencies = [ "tokio", ] +[[package]] +name = "toml" +version = "0.8.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd87a5cdd6ffab733b2f74bc4fd7ee5fff6634124999ac278c35fc78c6120148" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + [[package]] name = "toml_datetime" version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" +dependencies = [ + "serde", +] [[package]] name = "toml_edit" @@ -4271,6 +4311,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "17b4795ff5edd201c7cd6dca065ae59972ce77d1b80fa0a84d94950ece7d1474" dependencies = [ "indexmap", + "serde", + "serde_spanned", "toml_datetime", "winnow", ] diff --git a/Cargo.toml b/Cargo.toml index 244a704..12ec2e0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,6 +41,9 @@ tokio = { version = "1.44.0", features = ["rt-multi-thread"] } pyo3-log = "0.12.1" tracing = "0.1.41" +[build-dependencies] +cargo-lock = "10" + [patch.crates-io] # TODO unpatch cql2 when we upgrade geoarrow to use geo v0.30 cql2 = { git = "https://github.com/gadomski/cql2-rs", branch = "geo-v0.29" } diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..028ce4c --- /dev/null +++ b/build.rs @@ -0,0 +1,12 @@ +use cargo_lock::Lockfile; + +fn main() { + let lockfile = Lockfile::load("Cargo.lock").unwrap(); + let package = lockfile + .packages + .into_iter() + .find(|package| package.name.as_str() == "rustac") + .unwrap(); + let precise = package.source.unwrap().precise().unwrap().to_string(); + println!("cargo:rustc-env=RUSTAC_SHA={}", precise); +} diff --git a/docs/api/version.md b/docs/api/version.md index 5453ae0..d501861 100644 --- a/docs/api/version.md +++ b/docs/api/version.md @@ -4,4 +4,5 @@ description: Return this package's version or the version of an upstream # Version +::: rustac.sha ::: rustac.version diff --git a/rustac.pyi b/rustac.pyi index ffd2322..aa76584 100644 --- a/rustac.pyi +++ b/rustac.pyi @@ -453,3 +453,12 @@ def version( >>> rustac.version("duckdb") "1.0.0" """ + +def sha() -> str: + """ + Returns the SHA of the underlying rustac crate. + + Examples: + >>> rustac.sha() + "4d6a60a3df1386922285191aba95a76ec704a8b4" + """ diff --git a/src/lib.rs b/src/lib.rs index af1b973..5b970d8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -31,6 +31,7 @@ fn rustac(py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> { m.add_function(wrap_pyfunction!(read::read, m)?)?; m.add_function(wrap_pyfunction!(search::search, m)?)?; m.add_function(wrap_pyfunction!(search::search_to, m)?)?; + m.add_function(wrap_pyfunction!(version::sha, m)?)?; m.add_function(wrap_pyfunction!(version::version, m)?)?; m.add_function(wrap_pyfunction!(walk::walk, m)?)?; m.add_function(wrap_pyfunction!(write::write, m)?)?; diff --git a/src/version.rs b/src/version.rs index 74a42ec..8712592 100644 --- a/src/version.rs +++ b/src/version.rs @@ -17,3 +17,9 @@ pub fn version(name: Option) -> Option { Some(env!("CARGO_PKG_VERSION").to_string()) } } + +#[pyfunction] +pub fn sha() -> String { + // This environment variable is set in the build script + env!("RUSTAC_SHA").to_string() +} diff --git a/tests/test_version.py b/tests/test_version.py index 9b81804..ace63ab 100644 --- a/tests/test_version.py +++ b/tests/test_version.py @@ -6,3 +6,7 @@ def test_version() -> None: assert rustac.version("stac") is not None assert rustac.version("stac-api") is not None assert rustac.version("stac-duckdb") is not None + + +def test_sha() -> None: + assert rustac.sha() is not None