Skip to content

Commit c26b40e

Browse files
committed
feat: add sha
1 parent f40236c commit c26b40e

File tree

7 files changed

+77
-0
lines changed

7 files changed

+77
-0
lines changed

Cargo.lock

Lines changed: 42 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ tokio = { version = "1.44.0", features = ["rt-multi-thread"] }
4141
pyo3-log = "0.12.1"
4242
tracing = "0.1.41"
4343

44+
[build-dependencies]
45+
cargo-lock = "10"
46+
4447
[patch.crates-io]
4548
# TODO unpatch cql2 when we upgrade geoarrow to use geo v0.30
4649
cql2 = { git = "https://github.com/gadomski/cql2-rs", branch = "geo-v0.29" }

build.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
use cargo_lock::Lockfile;
2+
3+
fn main() {
4+
let lockfile = Lockfile::load("Cargo.lock").unwrap();
5+
let package = lockfile
6+
.packages
7+
.into_iter()
8+
.find(|package| package.name.as_str() == "rustac")
9+
.unwrap();
10+
let precise = package.source.unwrap().precise().unwrap().to_string();
11+
println!("cargo:rustc-env=RUSTAC_SHA={}", precise);
12+
}

rustac.pyi

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,3 +453,12 @@ def version(
453453
>>> rustac.version("duckdb")
454454
"1.0.0"
455455
"""
456+
457+
def sha() -> str:
458+
"""
459+
Returns the SHA of the underlying rustac crate.
460+
461+
Examples:
462+
>>> rustac.sha()
463+
"4d6a60a3df1386922285191aba95a76ec704a8b4"
464+
"""

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ fn rustac(py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
3131
m.add_function(wrap_pyfunction!(read::read, m)?)?;
3232
m.add_function(wrap_pyfunction!(search::search, m)?)?;
3333
m.add_function(wrap_pyfunction!(search::search_to, m)?)?;
34+
m.add_function(wrap_pyfunction!(version::sha, m)?)?;
3435
m.add_function(wrap_pyfunction!(version::version, m)?)?;
3536
m.add_function(wrap_pyfunction!(walk::walk, m)?)?;
3637
m.add_function(wrap_pyfunction!(write::write, m)?)?;

src/version.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,9 @@ pub fn version(name: Option<String>) -> Option<String> {
1717
Some(env!("CARGO_PKG_VERSION").to_string())
1818
}
1919
}
20+
21+
#[pyfunction]
22+
pub fn sha() -> String {
23+
// This environment variable is set in the build script
24+
env!("RUSTAC_SHA").to_string()
25+
}

tests/test_version.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@ def test_version() -> None:
66
assert rustac.version("stac") is not None
77
assert rustac.version("stac-api") is not None
88
assert rustac.version("stac-duckdb") is not None
9+
10+
11+
def test_sha() -> None:
12+
assert rustac.sha() is not None

0 commit comments

Comments
 (0)