Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include function to get cfitsio version #379

Merged
merged 3 commits into from
Dec 31, 2024
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
13 changes: 13 additions & 0 deletions bin/test
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,17 @@ class TestRunner:
sys.exit(e.returncode)
print()

def _print_cfitsio_version_with_features(self, *features: str, default_features: bool = True):
cmd = ["cargo", "run", "--package", "fitsio-sys", "--example", "print_version"]
for feature in features:
cmd.extend(["--features", feature])
if not default_features:
cmd.append("--no-default-features")
print(f"Running {' '.join(cmd)}")
sp.check_call(cmd)

def _run_test_workspace(self):
self._print_cfitsio_version_with_features()
self._run_cargo("test", "--locked", "--", "--test-threads", "1")

def _run_test_clippy(self, extra_clippy_flags: str):
Expand All @@ -75,6 +85,7 @@ class TestRunner:
self._run_cargo("test", "--locked", "--manifest-path", "fitsio/Cargo.toml", "--features", "array", "--", "--test-threads", "1")

def _run_test_fitsio_src(self):
self._print_cfitsio_version_with_features("fitsio-src")
self._run_cargo(
"test",
"--locked",
Expand All @@ -88,6 +99,7 @@ class TestRunner:
)

def _run_test_fitsio_src_and_bindgen(self):
self._print_cfitsio_version_with_features("fitsio-src", "with-bindgen")
self._run_cargo(
"test",
"--locked",
Expand All @@ -103,6 +115,7 @@ class TestRunner:
)

def _run_test_bindgen(self):
self._print_cfitsio_version_with_features("with-bindgen", default_features=False)
self._run_cargo(
"test",
"--locked",
Expand Down
5 changes: 5 additions & 0 deletions fitsio-sys/examples/print_version.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use fitsio_sys::cfitsio_version;

fn main() {
println!("cfitsio version: {}", cfitsio_version());
}
26 changes: 26 additions & 0 deletions fitsio-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,29 @@ mod sys {
}

pub use sys::*;

// global functions

/// Representation of the version of cfitsio used within bindings
pub struct CfitsioVersion {
/// Minor version
pub minor: u32,
/// Major version
pub major: u32,
}

impl std::fmt::Display for CfitsioVersion {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}.{}", self.major, self.minor)
}
}

pub fn cfitsio_version() -> CfitsioVersion {
CfitsioVersion {
// TODO: we need to detect the version of cfitsio we are binding to. Version >=4 supports
// this field, but earlier versions don't.
// patch: CFITSIO_MICRO,
minor: CFITSIO_MINOR,
major: CFITSIO_MAJOR,
}
}
3 changes: 3 additions & 0 deletions fitsio/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,9 @@ let _hdu = t.hdu(hdu_num).unwrap();

pub use fitsio_sys as sys;

// re-export version information
pub use sys::{cfitsio_version, CfitsioVersion};

#[macro_use]
mod macros;
mod fitsfile;
Expand Down
Loading