Skip to content

Commit

Permalink
Update to hifitime 4.0.2 (for pyo3)
Browse files Browse the repository at this point in the history
Fixed half of the deprecation warnings of pyo3 0.23
  • Loading branch information
ChristopherRabotin committed Dec 24, 2024
1 parent 22fdcc9 commit 45d8d76
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 28 deletions.
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ exclude = [
]

[workspace.dependencies]
# hifitime = "4.0.1"
hifitime = { path = "../hifitime" }
hifitime = "4.0.2"
memmap2 = "0.9.4"
crc32fast = "1.4.2"
der = { version = "0.7.8", features = ["derive", "alloc", "real"] }
Expand Down
2 changes: 2 additions & 0 deletions anise-py/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub(crate) fn register_utils(parent_module: &Bound<'_, PyModule>) -> PyResult<()
/// :type overwrite: bool, optional
/// :rtype: None
#[pyfunction]
#[pyo3(signature = (fk_file_path, anise_output_path, show_comments=None, overwrite=None))]
fn convert_fk(
fk_file_path: String,
anise_output_path: String,
Expand All @@ -60,6 +61,7 @@ fn convert_fk(
/// :type overwrite: bool, optional
/// :rtype: None
#[pyfunction]
#[pyo3(signature = (pck_file_path, gm_file_path, anise_output_path, overwrite=None))]
fn convert_tpc(
pck_file_path: String,
gm_file_path: String,
Expand Down
32 changes: 15 additions & 17 deletions anise/src/almanac/metaload/metaalmanac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,13 @@ impl MetaAlmanac {
}

/// Fetch all of the URIs and return a loaded Almanac
pub(crate) fn _process(&mut self, autodelete: bool) -> AlmanacResult<Almanac> {
/// When downloading the data, ANISE will create a temporarily lock file to prevent race conditions
/// where multiple processes download the data at the same time. Set `autodelete` to true to delete
/// this lock file if a dead lock is detected after 10 seconds. Set this flag to false if you have
/// more than ten processes which may attempt to download files in parallel.
pub fn process(&mut self, autodelete: bool) -> AlmanacResult<Almanac> {
for (fno, file) in self.files.iter_mut().enumerate() {
file._process(autodelete).context(MetaSnafu {
file.process(autodelete).context(MetaSnafu {
fno,
file: file.clone(),
})?;
Expand All @@ -72,16 +76,6 @@ impl MetaAlmanac {
Ok(ctx)
}

/// Fetch all of the URIs and return a loaded Almanac
/// When downloading the data, ANISE will create a temporarily lock file to prevent race conditions
/// where multiple processes download the data at the same time. Set `autodelete` to true to delete
/// this lock file if a dead lock is detected after 10 seconds. Set this flag to false if you have
/// more than ten processes which may attempt to download files in parallel.
#[cfg(not(feature = "python"))]
pub fn process(&mut self, autodelete: bool) -> AlmanacResult<Almanac> {
self._process(autodelete)
}

/// Returns an Almanac loaded from the latest NAIF data via the `default` MetaAlmanac.
/// The MetaAlmanac will download the DE440s.bsp file, the PCK0008.PCA, the full Moon Principal Axis BPC (moon_pa_de440_200625) and the latest high precision Earth kernel from JPL.
///
Expand All @@ -95,7 +89,6 @@ impl MetaAlmanac {
///
/// Note that the `earth_latest_high_prec.bpc` file is regularly updated daily (or so). As such,
/// if queried at some future time, the Earth rotation parameters may have changed between two queries.
#[cfg(not(feature = "python"))]
pub fn latest() -> AlmanacResult<Almanac> {
Self::default().process(true)
}
Expand Down Expand Up @@ -144,6 +137,7 @@ impl MetaAlmanac {
impl MetaAlmanac {
/// Loads the provided path as a Dhall file. If no path is provided, creates an empty MetaAlmanac that can store MetaFiles.
#[new]
#[pyo3(signature=(maybe_path=None))]
pub fn py_new(maybe_path: Option<String>) -> Result<Self, MetaAlmanacError> {
match maybe_path {
Some(path) => Self::new(path),
Expand Down Expand Up @@ -179,13 +173,15 @@ impl MetaAlmanac {
/// :type autodelete: bool, optional
/// :rtype: MetaAlmanac
#[classmethod]
fn latest(
#[pyo3(name = "latest")]
#[pyo3(signature=(autodelete=None))]
fn py_latest(
_cls: &Bound<'_, PyType>,
py: Python,
autodelete: Option<bool>,
) -> AlmanacResult<Almanac> {
let mut meta = Self::default();
py.allow_threads(|| match meta._process(autodelete.unwrap_or(false)) {
py.allow_threads(|| match meta.process(autodelete.unwrap_or(false)) {
Ok(almanac) => Ok(almanac),
Err(e) => Err(e),
})
Expand All @@ -199,8 +195,10 @@ impl MetaAlmanac {
///
/// :type autodelete: bool, optional
/// :rtype: Almanac
pub fn process(&mut self, py: Python, autodelete: Option<bool>) -> AlmanacResult<Almanac> {
py.allow_threads(|| self._process(autodelete.unwrap_or(true)))
#[pyo3(name = "process")]
#[pyo3(signature=(autodelete=None))]
pub fn py_process(&mut self, py: Python, autodelete: Option<bool>) -> AlmanacResult<Almanac> {
py.allow_threads(|| self.process(autodelete.unwrap_or(true)))
}

fn __str__(&self) -> String {
Expand Down
11 changes: 4 additions & 7 deletions anise/src/almanac/metaload/metafile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,7 @@ impl MetaFile {
/// Processes this MetaFile by downloading it if it's a URL and sets this structure's `uri` field to the local path
///
/// This function modified `self` and changes the URI to be the path to the downloaded file.
#[cfg(not(feature = "python"))]
pub fn process(&mut self, autodelete: bool) -> Result<(), MetaAlmanacError> {
self._process(autodelete)
}

pub(crate) fn _process(&mut self, autodelete: bool) -> Result<(), MetaAlmanacError> {
// First, parse environment variables if any.
self.uri = replace_env_vars(&self.uri);
match Url::parse(&self.uri) {
Expand Down Expand Up @@ -268,6 +263,7 @@ impl MetaFile {
impl MetaFile {
/// Builds a new MetaFile from the provided URI and optionally its CRC32 checksum.
#[new]
#[pyo3(signature=(uri, crc32=None))]
pub fn py_new(uri: String, crc32: Option<u32>) -> Self {
Self { uri, crc32 }
}
Expand Down Expand Up @@ -296,12 +292,13 @@ impl MetaFile {
///
/// :type autodelete: bool, optional
/// :rtype: None
pub fn process(
#[pyo3(name = "process", signature=(autodelete=None))]
pub fn py_process(
&mut self,
py: Python,
autodelete: Option<bool>,
) -> Result<(), MetaAlmanacError> {
py.allow_threads(|| self._process(autodelete.unwrap_or(false)))
py.allow_threads(|| self.process(autodelete.unwrap_or(false)))
}

/// :rtype: str
Expand Down
2 changes: 1 addition & 1 deletion anise/src/almanac/metaload/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl Almanac {
mut metafile: MetaFile,
autodelete: bool,
) -> AlmanacResult<Self> {
metafile._process(autodelete).context(MetaSnafu {
metafile.process(autodelete).context(MetaSnafu {
fno: 0_usize,
file: metafile.clone(),
})?;
Expand Down
1 change: 1 addition & 0 deletions anise/src/astro/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ impl AzElRange {
impl AzElRange {
/// Initializes a new AzElRange instance
#[new]
#[pyo3(signature=(epoch, azimuth_deg, elevation_deg, range_km, range_rate_km_s, obstructed_by=None))]
pub fn py_new(
epoch: Epoch,
azimuth_deg: f64,
Expand Down
1 change: 1 addition & 0 deletions anise/src/frames/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ impl Frame {
impl Frame {
/// Initializes a new [Frame] provided its ephemeris and orientation identifiers, and optionally its gravitational parameter (in km^3/s^2) and optionally its shape (cf. [Ellipsoid]).
#[new]
#[pyo3(signature=(ephemeris_id, orientation_id, mu_km3_s2=None, shape=None))]
pub fn py_new(
ephemeris_id: NaifId,
orientation_id: NaifId,
Expand Down
1 change: 1 addition & 0 deletions anise/src/math/rotation/dcm_py.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use pyo3::types::PyType;
#[pymethods]
impl DCM {
#[new]
#[pyo3(signature=(np_rot_mat, from_id, to_id, np_rot_mat_dt=None))]
pub fn py_new<'py>(
np_rot_mat: PyReadonlyArray2<'py, f64>,
from_id: NaifId,
Expand Down
2 changes: 1 addition & 1 deletion anise/src/naif/daf/data_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use super::DAFError;
#[cfg(feature = "python")]
use pyo3::prelude::*;

#[cfg_attr(feature = "python", pyclass)]
#[cfg_attr(feature = "python", pyclass(eq, eq_int))]
#[derive(Copy, Clone, Debug, PartialEq)]
#[repr(u8)]
pub enum DataType {
Expand Down
1 change: 1 addition & 0 deletions anise/src/structure/planetocentric/ellipsoid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ impl Ellipsoid {
/// All units are in kilometers. If the semi minor equatorial radius is not provided, a bi-axial spheroid will be created using the semi major equatorial radius as
/// the equatorial radius and using the provided polar axis radius. If only the semi major equatorial radius is provided, a perfect sphere will be built.
#[new]
#[pyo3(signature=(semi_major_equatorial_radius_km, polar_radius_km=None, semi_minor_equatorial_radius_km=None))]
fn py_new(
semi_major_equatorial_radius_km: f64,
polar_radius_km: Option<f64>,
Expand Down

0 comments on commit 45d8d76

Please sign in to comment.