-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MSRV to 1.65,updated fitsio and fitsio-sys,mwalib Python lib now has …
…typing and docstrings,added cfitsio CI tests
- Loading branch information
Showing
36 changed files
with
1,562 additions
and
445 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
|
@@ -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" | ||
|
@@ -85,4 +97,4 @@ required-features = ["examples"] | |
|
||
[[example]] | ||
name = "mwalib-sum-first-fine-channel-gpubox-hdus" | ||
required-features = ["examples"] | ||
required-features = ["examples"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! |
Oops, something went wrong.