Skip to content

Commit

Permalink
[python] [CI] Change pytest depending on arch
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherRabotin committed Dec 30, 2023
1 parent 19fc724 commit 7e5b6ab
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 4 deletions.
22 changes: 20 additions & 2 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,33 @@ jobs:
path: anise-py/dist

- name: pytest
if: ${{ startsWith(matrix.target, 'x86') }}
shell: bash
env:
RUST_BACKTRACE: 1
run: |
set -e
pip debug --verbose
pip install anise --find-links anise-py/dist --force-reinstall -vv
pip install pytest
pytest
- name: pytest
if: ${{ !startsWith(matrix.target, 'x86') && matrix.target != 'ppc64' }}
uses: uraimo/run-on-arch-action@v2
with:
arch: ${{ matrix.target }}
distro: ubuntu22.04
githubToken: ${{ github.token }}
install: |
apt-get update
apt-get install -y --no-install-recommends python3 python3-pip
pip3 install -U pip pytest
run: |
set -e
pip debug --verbose
pip install anise --find-links anise-py/dist --force-reinstall -vv
pip install pytest
pytest
windows:
runs-on: windows-latest
strategy:
Expand Down Expand Up @@ -141,6 +158,7 @@ jobs:
path: anise-py/dist

- name: pytest
if: ${{ !startsWith(matrix.target, 'aarch64') }}
shell: bash
env:
RUST_BACKTRACE: 1
Expand Down
2 changes: 1 addition & 1 deletion anise-py/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ name = "anise"
crate-type = ["cdylib"]

[dependencies]
anise = { workspace = true, features = ["python"] }
anise = { workspace = true, features = ["python", "metaload"] }
snafu = { workspace = true }
hifitime = { workspace = true, features = ["python"] }
pyo3 = { workspace = true, features = ["extension-module"] }
Expand Down
2 changes: 2 additions & 0 deletions anise-py/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Documentation: https://nyxspace.com/
*/

use ::anise::almanac::meta::MetaAlmanac;
use ::anise::almanac::Almanac;
use ::anise::astro::Aberration;
use hifitime::leap_seconds::{LatestLeapSeconds, LeapSecondsFile};
Expand All @@ -26,6 +27,7 @@ fn anise(py: Python, m: &PyModule) -> PyResult<()> {
astro::register_astro(py, m)?;
m.add_class::<Almanac>()?;
m.add_class::<Aberration>()?;
m.add_class::<MetaAlmanac>()?;
Ok(())
}

Expand Down
15 changes: 14 additions & 1 deletion anise-py/tests/test_almanac.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pathlib import Path
import pickle

from anise import Aberration, Almanac
from anise import Aberration, Almanac, MetaAlmanac
from anise.astro import *
from anise.astro.constants import Frames
from anise.time import Epoch
Expand Down Expand Up @@ -85,6 +85,18 @@ def test_state_transformation():
# cf. https://github.com/nyx-space/hifitime/issues/270


def test_meta_load():
data_path = Path(__file__).parent.joinpath("..", "..", "data", "local.dhall")
meta = MetaAlmanac(str(data_path))
print(meta)
# Process the files to be loaded
almanac = meta.process()
# And check that everything is loaded
eme2k = almanac.frame_info(Frames.EME2000)
assert eme2k.mu_km3_s2() == 398600.435436096
assert eme2k.shape.polar_radius_km == 6356.75
assert abs(eme2k.shape.flattening() - 0.0033536422844278) < 2e-16

def test_exports():
for cls in [Frame, Ellipsoid, Orbit]:
print(f"{cls} OK")
Expand All @@ -99,6 +111,7 @@ def test_frame_defs():


if __name__ == "__main__":
test_meta_load()
test_exports()
test_frame_defs()
test_state_transformation()
33 changes: 33 additions & 0 deletions anise/src/almanac/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ use std::io::Write;
use std::path::Path;
use url::Url;

#[cfg(feature = "python")]
use pyo3::exceptions::PyTypeError;
#[cfg(feature = "python")]
use pyo3::prelude::*;
#[cfg(feature = "python")]
use pyo3::pyclass::CompareOp;

use crate::errors::{AlmanacError, MetaSnafu};
use crate::file2heap;
use crate::prelude::InputOutputError;
Expand Down Expand Up @@ -56,12 +63,17 @@ pub enum MetaAlmanacError {
/// If it does not match, the file will be downloaded again. If no CRC32 is provided but the file exists, then the MetaAlmanac will fetch the remote file and overwrite the existing file.
/// The downloaded path will be stored in the "AppData" folder.
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[cfg_attr(feature = "python", pyclass)]
#[cfg_attr(feature = "python", pyo3(module = "anise"))]
pub struct MetaAlmanac {
files: Vec<MetaFile>,
}

#[cfg_attr(feature = "python", pymethods)]
impl MetaAlmanac {
/// Loads the provided path as a Dhall file and processes each file.
#[cfg(feature = "python")]
#[new]
pub fn new(path: String) -> Result<Self, MetaAlmanacError> {
match serde_dhall::from_file(&path).parse::<Self>() {
Err(e) => Err(MetaAlmanacError::ParseDhall {
Expand Down Expand Up @@ -100,6 +112,27 @@ impl MetaAlmanac {
err: format!("{e}"),
})
}

#[cfg(feature = "python")]
fn __str__(&self) -> String {
format!("{self:?}")
}

#[cfg(feature = "python")]
fn __repr__(&self) -> String {
format!("{self:?} (@{self:p})")
}

#[cfg(feature = "python")]
fn __richcmp__(&self, other: &Self, op: CompareOp) -> Result<bool, PyErr> {
match op {
CompareOp::Eq => Ok(self == other),
CompareOp::Ne => Ok(self != other),
_ => Err(PyErr::new::<PyTypeError, _>(format!(
"{op:?} not available"
))),
}
}
}

/// By default, the MetaAlmanac will download the DE440s.bsp file, the PCK0008.PCA, and the latest high precision Earth kernel from JPL.
Expand Down
7 changes: 7 additions & 0 deletions anise/src/py_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Documentation: https://nyxspace.com/
*/

use crate::almanac::meta::MetaAlmanacError;
use crate::almanac::planetary::PlanetaryDataError;
use crate::ephemerides::EphemerisError;
use crate::errors::{AlmanacError, DecodingError, InputOutputError, IntegrityError, PhysicsError};
Expand Down Expand Up @@ -58,3 +59,9 @@ impl From<PlanetaryDataError> for PyErr {
PyException::new_err(err.to_string())
}
}

impl From<MetaAlmanacError> for PyErr {
fn from(err: MetaAlmanacError) -> PyErr {
PyException::new_err(err.to_string())
}
}
6 changes: 6 additions & 0 deletions data/local.dhall
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- Default Almanac
{ files =
[ { crc32 = None Natural, uri = "../data/de440s.bsp" }
, { crc32 = None Natural, uri = "../data/pck08.pca" }
]
}

0 comments on commit 7e5b6ab

Please sign in to comment.