Skip to content

Commit b2258cf

Browse files
Merge pull request #365 from nyx-space/deps/pyo3
Update PyO3 to 0.23 + fix possible bug in building EPA files from FK files
2 parents 9a3e782 + 60b388d commit b2258cf

File tree

19 files changed

+74
-76
lines changed

19 files changed

+74
-76
lines changed

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ exclude = [
2626
]
2727

2828
[workspace.dependencies]
29-
hifitime = "4.0.1"
29+
hifitime = "4.0.2"
3030
memmap2 = "0.9.4"
3131
crc32fast = "1.4.2"
3232
der = { version = "0.7.8", features = ["derive", "alloc", "real"] }
@@ -40,9 +40,9 @@ zerocopy = { version = "0.8.0", features = ["derive"] }
4040
bytes = "1.6.0"
4141
snafu = { version = "0.8.0", features = ["backtrace"] }
4242
rstest = "0.23.0"
43-
pyo3 = { version = "0.22", features = ["multiple-pymethods"] }
44-
pyo3-log = "0.11"
45-
numpy = "0.22"
43+
pyo3 = { version = "0.23", features = ["multiple-pymethods"] }
44+
pyo3-log = "0.12"
45+
numpy = "0.23"
4646
ndarray = ">= 0.15, < 0.17"
4747

4848
anise = { version = "0.5.1", path = "anise", default-features = false }

anise-py/src/astro.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use anise::frames::Frame;
2020
use super::constants::register_constants;
2121

2222
pub(crate) fn register_astro(parent_module: &Bound<'_, PyModule>) -> PyResult<()> {
23-
let sm = PyModule::new_bound(parent_module.py(), "astro")?;
23+
let sm = PyModule::new(parent_module.py(), "astro")?;
2424
sm.add_class::<Ellipsoid>()?;
2525
sm.add_class::<Frame>()?;
2626
sm.add_class::<Orbit>()?;

anise-py/src/constants.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ impl UsualConstants {
190190
}
191191

192192
pub(crate) fn register_constants(parent_module: &Bound<'_, PyModule>) -> PyResult<()> {
193-
let sm = PyModule::new_bound(parent_module.py(), "astro.constants")?;
193+
let sm = PyModule::new(parent_module.py(), "astro.constants")?;
194194
sm.add_class::<CelestialObjects>()?;
195195
sm.add_class::<Frames>()?;
196196
sm.add_class::<Orientations>()?;

anise-py/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ fn anise(m: &Bound<'_, PyModule>) -> PyResult<()> {
4040

4141
/// Reexport hifitime as anise.time
4242
fn register_time_module(parent_module: &Bound<'_, PyModule>) -> PyResult<()> {
43-
let sm = PyModule::new_bound(parent_module.py(), "time")?;
43+
let sm = PyModule::new(parent_module.py(), "time")?;
4444

4545
sm.add_class::<Epoch>()?;
4646
sm.add_class::<TimeScale>()?;

anise-py/src/rotation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use pyo3::prelude::*;
1313
use pyo3::py_run;
1414

1515
pub(crate) fn register_rotation(parent_module: &Bound<'_, PyModule>) -> PyResult<()> {
16-
let sm = PyModule::new_bound(parent_module.py(), "rotation")?;
16+
let sm = PyModule::new(parent_module.py(), "rotation")?;
1717
sm.add_class::<DCM>()?;
1818

1919
Python::with_gil(|py| {

anise-py/src/utils.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use anise::structure::dataset::DataSetError;
1515
use pyo3::{prelude::*, py_run};
1616

1717
pub(crate) fn register_utils(parent_module: &Bound<'_, PyModule>) -> PyResult<()> {
18-
let sm = PyModule::new_bound(parent_module.py(), "utils")?;
18+
let sm = PyModule::new(parent_module.py(), "utils")?;
1919
sm.add_function(wrap_pyfunction!(convert_fk, &sm)?)?;
2020
sm.add_function(wrap_pyfunction!(convert_tpc, &sm)?)?;
2121

@@ -35,6 +35,7 @@ pub(crate) fn register_utils(parent_module: &Bound<'_, PyModule>) -> PyResult<()
3535
/// :type overwrite: bool, optional
3636
/// :rtype: None
3737
#[pyfunction]
38+
#[pyo3(signature = (fk_file_path, anise_output_path, show_comments=None, overwrite=None))]
3839
fn convert_fk(
3940
fk_file_path: String,
4041
anise_output_path: String,
@@ -60,6 +61,7 @@ fn convert_fk(
6061
/// :type overwrite: bool, optional
6162
/// :rtype: None
6263
#[pyfunction]
64+
#[pyo3(signature = (pck_file_path, gm_file_path, anise_output_path, overwrite=None))]
6365
fn convert_tpc(
6466
pck_file_path: String,
6567
gm_file_path: String,

anise/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ regex = { version = "1.10.5", optional = true }
4444

4545
[dev-dependencies]
4646
rust-spice = "0.7.6"
47-
parquet = "53.0.0"
48-
arrow = "53.0.0"
47+
parquet = "54.0.0"
48+
arrow = "54.0.0"
4949
criterion = "0.5"
5050
iai = "0.1"
5151
pretty_env_logger = { workspace = true }

anise/src/almanac/metaload/metaalmanac.rs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,13 @@ impl MetaAlmanac {
5757
}
5858

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

75-
/// Fetch all of the URIs and return a loaded Almanac
76-
/// When downloading the data, ANISE will create a temporarily lock file to prevent race conditions
77-
/// where multiple processes download the data at the same time. Set `autodelete` to true to delete
78-
/// this lock file if a dead lock is detected after 10 seconds. Set this flag to false if you have
79-
/// more than ten processes which may attempt to download files in parallel.
80-
#[cfg(not(feature = "python"))]
81-
pub fn process(&mut self, autodelete: bool) -> AlmanacResult<Almanac> {
82-
self._process(autodelete)
83-
}
84-
8579
/// Returns an Almanac loaded from the latest NAIF data via the `default` MetaAlmanac.
8680
/// 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.
8781
///
@@ -95,7 +89,6 @@ impl MetaAlmanac {
9589
///
9690
/// Note that the `earth_latest_high_prec.bpc` file is regularly updated daily (or so). As such,
9791
/// if queried at some future time, the Earth rotation parameters may have changed between two queries.
98-
#[cfg(not(feature = "python"))]
9992
pub fn latest() -> AlmanacResult<Almanac> {
10093
Self::default().process(true)
10194
}
@@ -144,6 +137,7 @@ impl MetaAlmanac {
144137
impl MetaAlmanac {
145138
/// Loads the provided path as a Dhall file. If no path is provided, creates an empty MetaAlmanac that can store MetaFiles.
146139
#[new]
140+
#[pyo3(signature=(maybe_path=None))]
147141
pub fn py_new(maybe_path: Option<String>) -> Result<Self, MetaAlmanacError> {
148142
match maybe_path {
149143
Some(path) => Self::new(path),
@@ -179,13 +173,15 @@ impl MetaAlmanac {
179173
/// :type autodelete: bool, optional
180174
/// :rtype: MetaAlmanac
181175
#[classmethod]
182-
fn latest(
176+
#[pyo3(name = "latest")]
177+
#[pyo3(signature=(autodelete=None))]
178+
fn py_latest(
183179
_cls: &Bound<'_, PyType>,
184180
py: Python,
185181
autodelete: Option<bool>,
186182
) -> AlmanacResult<Almanac> {
187183
let mut meta = Self::default();
188-
py.allow_threads(|| match meta._process(autodelete.unwrap_or(false)) {
184+
py.allow_threads(|| match meta.process(autodelete.unwrap_or(false)) {
189185
Ok(almanac) => Ok(almanac),
190186
Err(e) => Err(e),
191187
})
@@ -199,8 +195,10 @@ impl MetaAlmanac {
199195
///
200196
/// :type autodelete: bool, optional
201197
/// :rtype: Almanac
202-
pub fn process(&mut self, py: Python, autodelete: Option<bool>) -> AlmanacResult<Almanac> {
203-
py.allow_threads(|| self._process(autodelete.unwrap_or(true)))
198+
#[pyo3(name = "process")]
199+
#[pyo3(signature=(autodelete=None))]
200+
pub fn py_process(&mut self, py: Python, autodelete: Option<bool>) -> AlmanacResult<Almanac> {
201+
py.allow_threads(|| self.process(autodelete.unwrap_or(true)))
204202
}
205203

206204
fn __str__(&self) -> String {

anise/src/almanac/metaload/metafile.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,7 @@ impl MetaFile {
5656
/// Processes this MetaFile by downloading it if it's a URL and sets this structure's `uri` field to the local path
5757
///
5858
/// This function modified `self` and changes the URI to be the path to the downloaded file.
59-
#[cfg(not(feature = "python"))]
6059
pub fn process(&mut self, autodelete: bool) -> Result<(), MetaAlmanacError> {
61-
self._process(autodelete)
62-
}
63-
64-
pub(crate) fn _process(&mut self, autodelete: bool) -> Result<(), MetaAlmanacError> {
6560
// First, parse environment variables if any.
6661
self.uri = replace_env_vars(&self.uri);
6762
match Url::parse(&self.uri) {
@@ -268,6 +263,7 @@ impl MetaFile {
268263
impl MetaFile {
269264
/// Builds a new MetaFile from the provided URI and optionally its CRC32 checksum.
270265
#[new]
266+
#[pyo3(signature=(uri, crc32=None))]
271267
pub fn py_new(uri: String, crc32: Option<u32>) -> Self {
272268
Self { uri, crc32 }
273269
}
@@ -296,12 +292,13 @@ impl MetaFile {
296292
///
297293
/// :type autodelete: bool, optional
298294
/// :rtype: None
299-
pub fn process(
295+
#[pyo3(name = "process", signature=(autodelete=None))]
296+
pub fn py_process(
300297
&mut self,
301298
py: Python,
302299
autodelete: Option<bool>,
303300
) -> Result<(), MetaAlmanacError> {
304-
py.allow_threads(|| self._process(autodelete.unwrap_or(false)))
301+
py.allow_threads(|| self.process(autodelete.unwrap_or(false)))
305302
}
306303

307304
/// :rtype: str
@@ -347,28 +344,28 @@ mod ut_metafile {
347344
uri: "C:\\Users\\me\\meta.dhall".to_string(),
348345
crc32: None,
349346
};
350-
assert!(window_path._process(true).is_ok());
347+
assert!(window_path.process(true).is_ok());
351348
assert_eq!(window_path.uri, "C:\\Users\\me\\meta.dhall".to_string());
352349

353350
let mut file_prefix_path = MetaFile {
354351
uri: "fIlE:///Users/me/meta.dhall".to_string(),
355352
crc32: None,
356353
};
357-
assert!(file_prefix_path._process(true).is_ok());
354+
assert!(file_prefix_path.process(true).is_ok());
358355
assert_eq!(file_prefix_path.uri, "/Users/me/meta.dhall".to_string());
359356

360357
let mut unix_abs_path = MetaFile {
361358
uri: "/Users/me/meta.dhall".to_string(),
362359
crc32: None,
363360
};
364-
assert!(unix_abs_path._process(true).is_ok());
361+
assert!(unix_abs_path.process(true).is_ok());
365362
assert_eq!(unix_abs_path.uri, "/Users/me/meta.dhall".to_string());
366363

367364
let mut unix_rel_path = MetaFile {
368365
uri: "../Users/me/meta.dhall".to_string(),
369366
crc32: None,
370367
};
371-
assert!(unix_rel_path._process(true).is_ok());
368+
assert!(unix_rel_path.process(true).is_ok());
372369
assert_eq!(unix_rel_path.uri, "../Users/me/meta.dhall".to_string());
373370
}
374371

@@ -379,14 +376,14 @@ mod ut_metafile {
379376
uri: "env:USER/.cargo/env".to_string(),
380377
crc32: None,
381378
};
382-
user_path._process(false).unwrap();
379+
user_path.process(false).unwrap();
383380
assert_eq!(user_path.uri, env::var("USER").unwrap() + "/.cargo/env");
384381

385382
let mut unknown_path = MetaFile {
386383
uri: "env:BLAH_BLAH_NO_EXIST/.cargo/env".to_string(),
387384
crc32: None,
388385
};
389-
unknown_path._process(false).unwrap();
386+
unknown_path.process(false).unwrap();
390387
assert_eq!(
391388
unknown_path.uri,
392389
"env:BLAH_BLAH_NO_EXIST/.cargo/env".to_string()

anise/src/almanac/metaload/mod.rs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,25 +54,23 @@ pub enum MetaAlmanacError {
5454
}
5555

5656
impl Almanac {
57-
/// Load from the provided MetaFile.
58-
fn _load_from_metafile(&self, mut metafile: MetaFile, autodelete: bool) -> AlmanacResult<Self> {
59-
metafile._process(autodelete).context(MetaSnafu {
57+
/// Load from the provided MetaFile, downloading it if necessary.
58+
/// Set autodelete to true to automatically delete lock files. Lock files are important in multi-threaded loads.
59+
pub fn load_from_metafile(
60+
&self,
61+
mut metafile: MetaFile,
62+
autodelete: bool,
63+
) -> AlmanacResult<Self> {
64+
metafile.process(autodelete).context(MetaSnafu {
6065
fno: 0_usize,
6166
file: metafile.clone(),
6267
})?;
6368
self.load(&metafile.uri)
6469
}
65-
66-
/// Load from the provided MetaFile, downloading it if necessary.
67-
/// Set autodelete to true to automatically delete lock files. Lock files are important in multi-threaded loads.
68-
#[cfg(not(feature = "python"))]
69-
pub fn load_from_metafile(&self, metafile: MetaFile, autodelete: bool) -> AlmanacResult<Self> {
70-
self._load_from_metafile(metafile, autodelete)
71-
}
7270
}
7371

7472
#[cfg(feature = "python")]
75-
#[cfg_attr(feature = "python", pymethods)]
73+
#[pymethods]
7674
impl Almanac {
7775
/// Load from the provided MetaFile, downloading it if necessary.
7876
/// Set autodelete to true to automatically delete lock files. Lock files are important in multi-threaded loads.
@@ -81,13 +79,14 @@ impl Almanac {
8179
/// :type metafile: Metafile
8280
/// :type autodelete: bool
8381
/// :rtype: Almanac
84-
fn load_from_metafile(
82+
#[pyo3(name = "load_from_metafile")]
83+
fn py_load_from_metafile(
8584
&mut self,
8685
py: Python,
8786
metafile: MetaFile,
8887
autodelete: bool,
8988
) -> AlmanacResult<Self> {
90-
py.allow_threads(|| self._load_from_metafile(metafile, autodelete))
89+
py.allow_threads(|| self.load_from_metafile(metafile, autodelete))
9190
}
9291
}
9392

@@ -105,15 +104,15 @@ mod meta_test {
105104
let mut meta = MetaAlmanac::default();
106105
println!("{meta:?}");
107106

108-
let almanac = meta._process(true).unwrap();
107+
let almanac = meta.process(true).unwrap();
109108
// Shows everything in this Almanac
110109
almanac.describe(None, None, None, None, None, None);
111110

112111
// Process again to confirm that the CRC check works
113-
assert!(meta._process(true).is_ok());
112+
assert!(meta.process(true).is_ok());
114113
// Test that loading from an invalid URI reports an error
115114
assert!(almanac
116-
._load_from_metafile(
115+
.load_from_metafile(
117116
MetaFile {
118117
uri: "http://example.com/non/existing.pca".to_string(),
119118
crc32: None

anise/src/astro/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ impl AzElRange {
7979
impl AzElRange {
8080
/// Initializes a new AzElRange instance
8181
#[new]
82+
#[pyo3(signature=(epoch, azimuth_deg, elevation_deg, range_km, range_rate_km_s, obstructed_by=None))]
8283
pub fn py_new(
8384
epoch: Epoch,
8485
azimuth_deg: f64,

anise/src/frames/frame.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ impl Frame {
9898
impl Frame {
9999
/// 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]).
100100
#[new]
101+
#[pyo3(signature=(ephemeris_id, orientation_id, mu_km3_s2=None, shape=None))]
101102
pub fn py_new(
102103
ephemeris_id: NaifId,
103104
orientation_id: NaifId,

anise/src/math/cartesian_py.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ impl CartesianState {
167167

168168
let state = Array1::from_iter(data);
169169

170-
Ok(PyArray1::<f64>::from_owned_array_bound(py, state))
170+
Ok(PyArray1::<f64>::from_owned_array(py, state))
171171
}
172172

173173
fn __str__(&self) -> String {

anise/src/math/rotation/dcm_py.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use pyo3::types::PyType;
2323
#[pymethods]
2424
impl DCM {
2525
#[new]
26+
#[pyo3(signature=(np_rot_mat, from_id, to_id, np_rot_mat_dt=None))]
2627
pub fn py_new<'py>(
2728
np_rot_mat: PyReadonlyArray2<'py, f64>,
2829
from_id: NaifId,
@@ -129,7 +130,7 @@ impl DCM {
129130
// Create an ndarray Array2 (row-major order)
130131
let rot_mat = Array2::from_shape_vec((3, 3), data).unwrap();
131132

132-
let py_rot_mat = PyArray2::<f64>::from_owned_array_bound(py, rot_mat);
133+
let py_rot_mat = PyArray2::<f64>::from_owned_array(py, rot_mat);
133134

134135
Ok(py_rot_mat)
135136
}
@@ -152,7 +153,7 @@ impl DCM {
152153
// Create an ndarray Array2 (row-major order)
153154
let rot_mat_dt = Array2::from_shape_vec((3, 3), data).unwrap();
154155

155-
let py_rot_mat_dt = PyArray2::<f64>::from_owned_array_bound(py, rot_mat_dt);
156+
let py_rot_mat_dt = PyArray2::<f64>::from_owned_array(py, rot_mat_dt);
156157

157158
Ok(Some(py_rot_mat_dt))
158159
}
@@ -179,7 +180,7 @@ impl DCM {
179180
// Create an ndarray Array2 (row-major order)
180181
let state_dcm = Array2::from_shape_vec((6, 6), data).unwrap();
181182

182-
let pt_state_dcm = PyArray2::<f64>::from_owned_array_bound(py, state_dcm);
183+
let pt_state_dcm = PyArray2::<f64>::from_owned_array(py, state_dcm);
183184

184185
Ok(pt_state_dcm)
185186
}

0 commit comments

Comments
 (0)