diff --git a/Cargo.toml b/Cargo.toml index 789093b..fe497f9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,6 +36,8 @@ tabled = { version = "0.16.0", optional = true } openssl = { version = "0.10", features = ["vendored"], optional = true } web-time = { version = "1.0.0", optional = true } snafu = { version = "0.8.2", default-features = false } +pyo3-stub-gen = { version = "0.6.0", default-features = false } +pyo3-stub-gen-derive = "0.6.0" [features] default = ["std"] diff --git a/hifitime.pyi b/hifitime.pyi new file mode 100644 index 0000000..246657c --- /dev/null +++ b/hifitime.pyi @@ -0,0 +1,81 @@ +# This file is automatically generated by pyo3_stub_gen +# ruff: noqa: E501, F401 + +import typing +from enum import Enum, auto + +class DurationError: + def __new__(cls,* _args,* * _kwargs): ... + ... + +class Epoch: + r""" + Defines a nanosecond-precision Epoch. + + Refer to the appropriate functions for initializing this Epoch from different time scales or representations. + """ + ... + +class HifitimeError: + def __new__(cls,* _args,* * _kwargs): ... + ... + +class LatestLeapSeconds: + r""" + List of leap seconds from https://www.ietf.org/timezones/data/leap-seconds.list . + This list corresponds the number of seconds in TAI to the UTC offset and to whether it was an announced leap second or not. + The unannoucned leap seconds come from dat.c in the SOFA library. + """ + def __new__(cls,): ... + def __repr__(self) -> str: + ... + + +class LeapSecond: + r""" + A structure representing a leap second + """ + ... + +class LeapSecondsFile: + r""" + A leap second provider that uses an IERS formatted leap seconds file. + """ + def __new__(cls,path:str): ... + def __repr__(self) -> str: + ... + + +class ParsingError: + def __new__(cls,* _args,* * _kwargs): ... + ... + +class TimeSeries: + r""" + An iterator of a sequence of evenly spaced Epochs. + """ + ... + +class Ut1Provider: + r""" + A structure storing all of the TAI-UT1 data + """ + def __new__(cls,): ... + def __repr__(self) -> str: + ... + + +class TimeScale(Enum): + r""" + Enum of the different time systems available + """ + TAI = auto() + TT = auto() + ET = auto() + TDB = auto() + UTC = auto() + GPST = auto() + GST = auto() + BDT = auto() + QZSST = auto() + diff --git a/src/bin/stub_gen.rs b/src/bin/stub_gen.rs new file mode 100644 index 0000000..d10db3c --- /dev/null +++ b/src/bin/stub_gen.rs @@ -0,0 +1,13 @@ +use pyo3_stub_gen::Result; + +#[cfg(feature = "python")] +fn main() -> Result<()> { + let stub = hifitime::python::stub_info()?; + stub.generate()?; + Ok(()) +} + +#[cfg(not(feature = "python"))] +fn main() -> Result<()> { + Ok(()) +} \ No newline at end of file diff --git a/src/epoch/leap_seconds.rs b/src/epoch/leap_seconds.rs index 2d5bcde..2cd07cd 100644 --- a/src/epoch/leap_seconds.rs +++ b/src/epoch/leap_seconds.rs @@ -11,6 +11,9 @@ #[cfg(feature = "python")] use pyo3::prelude::*; +#[cfg(feature = "python")] +use pyo3_stub_gen::derive::*; + #[cfg(feature = "std")] pub use super::leap_seconds_file::LeapSecondsFile; @@ -21,6 +24,7 @@ pub trait LeapSecondProvider: DoubleEndedIterator + Index) -> PyResult<()> { Ok(()) } +#[gen_stub_pyclass] #[pyclass] #[pyo3(name = "HifitimeError", extends = PyException)] pub struct PyHifitimeError {} +#[gen_stub_pymethods] #[pymethods] impl PyHifitimeError { #[new] @@ -48,10 +51,12 @@ impl PyHifitimeError { } } +#[gen_stub_pyclass] #[pyclass] #[pyo3(name = "ParsingError", extends = PyException)] pub struct PyParsingError {} +#[gen_stub_pymethods] #[pymethods] impl PyParsingError { #[new] @@ -61,10 +66,12 @@ impl PyParsingError { } } +#[gen_stub_pyclass] #[pyclass] #[pyo3(name = "DurationError", extends = PyException)] pub struct PyDurationError {} +#[gen_stub_pymethods] #[pymethods] impl PyDurationError { #[new] @@ -92,3 +99,5 @@ impl From for PyErr { PyException::new_err(err.to_string()) } } + +define_stub_info_gatherer!(stub_info); diff --git a/src/timescale/mod.rs b/src/timescale/mod.rs index d0c77b9..82d13d1 100644 --- a/src/timescale/mod.rs +++ b/src/timescale/mod.rs @@ -11,6 +11,9 @@ #[cfg(feature = "python")] use pyo3::prelude::*; +#[cfg(feature = "python")] +use pyo3_stub_gen::derive::*; + #[cfg(kani)] mod kani; @@ -81,6 +84,7 @@ pub(crate) const HIFITIME_REF_YEAR: i32 = 1900; /// Enum of the different time systems available #[non_exhaustive] +#[cfg_attr(feature = "python", gen_stub_pyclass_enum)] #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] #[cfg_attr(feature = "python", pyclass(eq, eq_int))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] @@ -171,6 +175,7 @@ impl TimeScale { } } +#[cfg_attr(feature = "python", gen_stub_pymethods)] #[cfg_attr(feature = "python", pymethods)] impl TimeScale { /// Returns true if self takes leap seconds into account diff --git a/src/timeseries.rs b/src/timeseries.rs index 48a326d..36045f1 100644 --- a/src/timeseries.rs +++ b/src/timeseries.rs @@ -19,6 +19,9 @@ use num_traits::Float; #[cfg(feature = "python")] use pyo3::prelude::*; +#[cfg(feature = "python")] +use pyo3_stub_gen::derive::*; + /* NOTE: This is taken from itertools: https://docs.rs/itertools-num/0.1.3/src/itertools_num/linspace.rs.html#78-93 . @@ -28,6 +31,7 @@ NOTE: This is taken from itertools: https://docs.rs/itertools-num/0.1.3/src/iter /// An iterator of a sequence of evenly spaced Epochs. #[cfg_attr(kani, derive(kani::Arbitrary))] #[derive(Clone, Debug, PartialEq, Eq)] +#[cfg_attr(feature = "python", gen_stub_pyclass)] #[cfg_attr(feature = "python", pyclass)] #[cfg_attr(feature = "python", pyo3(module = "hifitime"))] pub struct TimeSeries {