Skip to content

Commit

Permalink
MSRV to 1.65,updated fitsio and fitsio-sys,mwalib Python lib now has …
Browse files Browse the repository at this point in the history
…typing and docstrings,added cfitsio CI tests
  • Loading branch information
gsleap committed Oct 23, 2024
1 parent 30a5235 commit 391858b
Show file tree
Hide file tree
Showing 36 changed files with 1,562 additions and 445 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ on:
env:
RUST_BACKTRACE: 1
CARGO_TERM_COLOR: always
CARGO_INCREMENTAL: 0
MWALIB_LINK_STATIC_CFITSIO: 1
CARGO_INCREMENTAL: 0

jobs:
generate_coverage:
Expand Down
111 changes: 111 additions & 0 deletions .github/workflows/run_cfitsio_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
name: cfitsio tests

on:
push:
tags-ignore:
- '**'
branches:
- '**'
pull_request:

env:
RUST_BACKTRACE: 1
CARGO_TERM_COLOR: always
CARGO_INCREMENTAL: 0

jobs:
test_cfitsio_3:
name: Test cfitsio 3.49 on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
# see https://github.com/actions/runner-images?tab=readme-ov-file#available-images for runner types
os: [ubuntu-latest, macos-13, macos-14, macos-15] # macos-13 is x86_64, macos-14 & 15 are Arm64
steps:
- name: Checkout sources
uses: actions/checkout@v4

- name: (macos) install automake and autoconf
if: ${{ startsWith(matrix.os, 'macOS') }}
run: |
brew install automake autoconf
- name: Install stable minimal toolchain
uses: dtolnay/rust-toolchain@v1
with:
toolchain: stable

- name: Install cfitsio 3.49
run: |
curl "https://heasarc.gsfc.nasa.gov/FTP/software/fitsio/c/cfitsio-3.49.tar.gz" -o cfitsio.tar.gz
tar -xf cfitsio.tar.gz
rm cfitsio.tar.gz
cd cfitsio-3.49
# Enabling SSE2/SSSE3 could cause portability problems, but it's unlikely that anyone
# is using such a CPU...
# https://stackoverflow.com/questions/52858556/most-recent-processor-without-support-of-ssse3-instructions
# Disabling curl just means you cannot fits_open() using a URL.
CFLAGS="-O3" ./configure --prefix=/usr/local --enable-reentrant --enable-sse2 --enable-ssse3 --disable-curl
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
make -j
sudo make install
sudo ldconfig
elif [[ "$OSTYPE" == "darwin"* ]]; then
sudo make shared
sudo make install
fi
cd ..
- name: Run tests run on latest stable rust
run: cargo test --features examples

test_cfitsio_4:
name: Test cfitsio 4.5.0 on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
# see https://github.com/actions/runner-images?tab=readme-ov-file#available-images for runner types
os: [ubuntu-latest, macos-13, macos-14, macos-15] # macos-13 is x86_64, macos-14 & 15 are Arm64
steps:
- name: Checkout sources
uses: actions/checkout@v4

- name: (macos) install automake and autoconf
if: ${{ startsWith(matrix.os, 'macOS') }}
run: |
brew install automake autoconf
- name: Install stable minimal toolchain
uses: dtolnay/rust-toolchain@v1
with:
toolchain: stable

- name: Install cfitsio 4.5.0
run: |
curl "https://heasarc.gsfc.nasa.gov/FTP/software/fitsio/c/cfitsio-4.5.0.tar.gz" -o cfitsio.tar.gz
tar -xf cfitsio.tar.gz
rm cfitsio.tar.gz
cd cfitsio-4.5.0
# Enabling SSE2/SSSE3 could cause portability problems, but it's unlikely that anyone
# is using such a CPU...
# https://stackoverflow.com/questions/52858556/most-recent-processor-without-support-of-ssse3-instructions
# Disabling curl just means you cannot fits_open() using a URL.
CFLAGS="-O3" ./configure --prefix=/usr/local --enable-reentrant --enable-sse2 --enable-ssse3 --disable-curl
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
make -j
sudo make install
sudo ldconfig
elif [[ "$OSTYPE" == "darwin"* ]]; then
sudo make
sudo make install
fi
cd ..
- name: Run tests run on latest stable rust
run: cargo test --features examples
2 changes: 1 addition & 1 deletion .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ jobs:
run: |
MIN_RUST=$(grep -m1 "rust-version" Cargo.toml | sed 's|.*\"\(.*\)\"|\1|')
~/.cargo/bin/rustup install $MIN_RUST --profile minimal
cargo +${MIN_RUST} test --features cfitsio-static, examples
cargo +${MIN_RUST} test --features cfitsio-static,examples
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

Changes in each release are listed below.

## 1.7.0 23-Oct-2024

* Bumped MSRV to 1.65.
* Update fitsio to 0.21 and fitsio-sys to 0.5.
* Removed Rust Report Card from README status badges. Looks like this service is abandonded.
* Added Python .pyi stub generation to provide mwalib Python users with type and docstring information. The mwalib.pyi should get baked into the python wheels released to github and Pypi. See `bin/README.md` for caveats and more details.
* Added CI to test compilation against cfitsio 3.x and 4.x when not using the `cfitsio-static` feature.

## 1.6.0 18-Oct-2024

* Updated ndarray to 0.16
Expand Down
34 changes: 23 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,36 +1,44 @@
[package]
name = "mwalib"
version = "1.6.0"
version = "1.7.0"
homepage = "https://github.com/MWATelescope/mwalib"
repository = "https://github.com/MWATelescope/mwalib"
readme = "README.md"
authors = ["Greg Sleap <[email protected]>",
"Christopher H. Jordan <[email protected]>"]
edition = "2021"
rust-version = "1.64"
rust-version = "1.65"
description = "A library to simplify reading Murchison Widefield Array (MWA) raw visibilities, voltages and metadata."
license = "MPL-2.0"
keywords = ["radioastronomy", "mwa", "astronomy"]
categories = ["science","parsing"]
exclude = ["test_files/*", "tools/*",".github/*"]

[[bin]]
name = "stub_gen"
path = "bin/stub_gen.rs"
doc = false
required-features = ["python"]

# Make a rust library, as well as static and C-compatible dynamic libraries
# available as "libmwalib.a" and "libmwalib.so".
[lib]
crate-type = ["rlib", "staticlib", "cdylib"]

[features]
# default
default = ["cfitsio-static", "examples"]
# Compile cfitsio from source and link it statically.
cfitsio-static = ["fitsio-sys/fitsio-src"]
# Enable optional features needed by examples.
examples = ["anyhow", "clap", "env_logger"]
# Enable python
python = ["pyo3", "numpy", "ndarray"]
python = ["anyhow", "env_logger", "ndarray", "numpy", "pyo3", "pyo3-stub-gen", "pyo3-stub-gen-derive"]

[dependencies]
chrono = "0.4.38"
fitsio = "~0.20"
fitsio-sys = "~0.4"
fitsio = "~0.21"
fitsio-sys = "~0.5"
lazy_static = "~1.5"
libc = "~0.2"
log = "~0.4"
Expand All @@ -40,15 +48,19 @@ rayon = "~1.10"
regex = "~1.9"
thiserror = "~1.0"

# "python" feature.
pyo3 = { version = "~0.22", features = ["chrono", "extension-module"], optional = true }
numpy = { version = "~0.22", optional = true }
# "python" and examples features
anyhow = { version = "~1.0", optional = true }
env_logger = { version = "~0.10", optional = true }

# "python" feature
ndarray = { version = "~0.16", optional = true }
numpy = { version = "~0.22", optional = true }
pyo3 = { version = "~0.22", features = ["chrono", "extension-module", "macros"], optional = true }
pyo3-stub-gen = { version = "~0.6", optional = true }
pyo3-stub-gen-derive = { version = "~0.6", optional = true }

# "examples" feature.
anyhow = { version = "~1.0", optional = true }
clap = { version = "~4.1", features = ["derive"], optional = true }
env_logger = { version = "~0.10", optional = true }

[dev-dependencies]
csv = "~1.3"
Expand Down Expand Up @@ -85,4 +97,4 @@ required-features = ["examples"]

[[example]]
name = "mwalib-sum-first-fine-channel-gpubox-hdus"
required-features = ["examples"]
required-features = ["examples"]
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
![Crates.io](https://img.shields.io/crates/d/mwalib)
![Crates.io](https://img.shields.io/crates/l/mwalib)
[![docs](https://docs.rs/mwalib/badge.svg)](https://docs.rs/crate/mwalib/latest)
[![Rust Report Card](https://rust-reportcard.xuri.me/badge/github.com/MWATelescope/mwalib)](https://rust-reportcard.xuri.me/report/github.com/MWATelescope/mwalib)

mwalib is an MWA library to read raw visibilities, voltages and metadata into a common structure.
mwalib supports the existing "legacy" MWA correlator, as well as the "MWAX" correlator observations. This library
Expand Down
20 changes: 20 additions & 0 deletions bin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# mwalib python pyi stub generation

## How it works

1. Build mwalib using: `cargo build --all-features`
2. Run the stub generator: `target/debug/stub_gen`
3. At this point you can view the `mwalib.pyi` file and see what Python stubs were generated.
4. To test, build a python wheel to test with: `maturin build --all-features --out dist`.
5. In a freah Python environment install the wheel: `pip install dist/mwalib-1.7.0-cp313-cp313-manylinux_2_34_x86_64.whl`.
6. Open a python file in your IDE and hopefully you have some type info and some doc strings.

## Caveats

* Due to [this issue](https://github.com/Jij-Inc/pyo3-stub-gen/issues/93) and [this issue](https://github.com/PyO3/pyo3/issues/780), the codem as of mwalib 1.7.0 does NOT produce a full mwalib.pyi file, due to the fact that the stub generation requires the `python` feature and to get all the struct members to appear in the stub you need to decorate each member with `#[pyo3(get,set)]` but this decorator does not work with the `#[cfg_attr(feature = "python", pyo3(get,set))]` syntax needed to allow mwalib to be compiled without the `python` feature! So to get past this, I have removed the `#[cfg_attr(feature = "python", pyo3(get,set))]` syntax from all struct members and changed `#[cfg_attr(feature = "python", pyo3::pyclass]` on each struct to `#[cfg_attr(feature = "python", pyo3::pyclass(get_all, set_all))]` which will still create the python bindings but none of the struct members will be emitted when generating the stub file!

* Docstrings for `#[new]` methods on structs/classes do not get generated.

* `__enter__` method for a class gets the wrong generated stub so I have to override it (see below).

* Some other manual fixes can be seen in `bin/stubgen.rs`. Hacky but we live in an imperfect world!
Loading

0 comments on commit 391858b

Please sign in to comment.