Skip to content

Commit

Permalink
Update jiff to v0.2 (#4903)
Browse files Browse the repository at this point in the history
* Update jiff to v0.2

* Update (hopefully) all urls in features.md
  • Loading branch information
bschoenmaeckers authored Feb 14, 2025
1 parent 4f1af4d commit f3d3245
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ jobs:
- uses: dtolnay/rust-toolchain@nightly
with:
components: rust-src
- run: cargo rustdoc --lib --no-default-features --features full,jiff-01 -Zunstable-options --config "build.rustdocflags=[\"--cfg\", \"docsrs\"]"
- run: cargo rustdoc --lib --no-default-features --features full,jiff-02 -Zunstable-options --config "build.rustdocflags=[\"--cfg\", \"docsrs\"]"

coverage:
if: ${{ github.event_name != 'merge_group' }}
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ either = { version = "1.9", optional = true }
eyre = { version = ">= 0.6.8, < 0.7", optional = true }
hashbrown = { version = ">= 0.14.5, < 0.16", optional = true }
indexmap = { version = ">= 2.5.0, < 3", optional = true }
jiff-01 = { package = "jiff", version = "0.1.18", optional = true }
jiff-02 = { package = "jiff", version = "0.2", optional = true }
num-bigint = { version = "0.4.2", optional = true }
num-complex = { version = ">= 0.4.6, < 0.5", optional = true }
num-rational = {version = "0.4.1", optional = true }
Expand Down
22 changes: 11 additions & 11 deletions guide/src/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,17 @@ Adds a dependency on [hashbrown](https://docs.rs/hashbrown) and enables conversi

Adds a dependency on [indexmap](https://docs.rs/indexmap) and enables conversions into its [`IndexMap`](https://docs.rs/indexmap/latest/indexmap/map/struct.IndexMap.html) type.

### `jiff-01`

Adds a dependency on [jiff@0.1](https://docs.rs/jiff/0.1) and requires MSRV 1.70. Enables a conversion from [jiff](https://docs.rs/jiff)'s types to python:
- [SignedDuration](https://docs.rs/jiff/0.1/jiff/struct.SignedDuration.html) -> [`PyDelta`]({{#PYO3_DOCS_URL}}/pyo3/types/struct.PyDelta.html)
- [TimeZone](https://docs.rs/jiff/0.1/jiff/tz/struct.TimeZone.html) -> [`PyTzInfo`]({{#PYO3_DOCS_URL}}/pyo3/types/struct.PyTzInfo.html)
- [Offset](https://docs.rs/jiff/0.1/jiff/tz/struct.Offset.html) -> [`PyTzInfo`]({{#PYO3_DOCS_URL}}/pyo3/types/struct.PyTzInfo.html)
- [Date](https://docs.rs/jiff/0.1/jiff/civil/struct.Date.html) -> [`PyDate`]({{#PYO3_DOCS_URL}}/pyo3/types/struct.PyDate.html)
- [Time](https://docs.rs/jiff/0.1/jiff/civil/struct.Time.html) -> [`PyTime`]({{#PYO3_DOCS_URL}}/pyo3/types/struct.PyTime.html)
- [DateTime](https://docs.rs/jiff/0.1/jiff/civil/struct.DateTime.html) -> [`PyDateTime`]({{#PYO3_DOCS_URL}}/pyo3/types/struct.PyDateTime.html)
- [Zoned](https://docs.rs/jiff/0.1/jiff/struct.Zoned.html) -> [`PyDateTime`]({{#PYO3_DOCS_URL}}/pyo3/types/struct.PyDateTime.html)
- [Timestamp](https://docs.rs/jiff/0.1/jiff/struct.Timestamp.html) -> [`PyDateTime`]({{#PYO3_DOCS_URL}}/pyo3/types/struct.PyDateTime.html)
### `jiff-02`

Adds a dependency on [jiff@0.2](https://docs.rs/jiff/0.2) and requires MSRV 1.70. Enables a conversion from [jiff](https://docs.rs/jiff)'s types to python:
- [SignedDuration](https://docs.rs/jiff/0.2/jiff/struct.SignedDuration.html) -> [`PyDelta`]({{#PYO3_DOCS_URL}}/pyo3/types/struct.PyDelta.html)
- [TimeZone](https://docs.rs/jiff/0.2/jiff/tz/struct.TimeZone.html) -> [`PyTzInfo`]({{#PYO3_DOCS_URL}}/pyo3/types/struct.PyTzInfo.html)
- [Offset](https://docs.rs/jiff/0.2/jiff/tz/struct.Offset.html) -> [`PyTzInfo`]({{#PYO3_DOCS_URL}}/pyo3/types/struct.PyTzInfo.html)
- [Date](https://docs.rs/jiff/0.2/jiff/civil/struct.Date.html) -> [`PyDate`]({{#PYO3_DOCS_URL}}/pyo3/types/struct.PyDate.html)
- [Time](https://docs.rs/jiff/0.2/jiff/civil/struct.Time.html) -> [`PyTime`]({{#PYO3_DOCS_URL}}/pyo3/types/struct.PyTime.html)
- [DateTime](https://docs.rs/jiff/0.2/jiff/civil/struct.DateTime.html) -> [`PyDateTime`]({{#PYO3_DOCS_URL}}/pyo3/types/struct.PyDateTime.html)
- [Zoned](https://docs.rs/jiff/0.2/jiff/struct.Zoned.html) -> [`PyDateTime`]({{#PYO3_DOCS_URL}}/pyo3/types/struct.PyDateTime.html)
- [Timestamp](https://docs.rs/jiff/0.2/jiff/struct.Timestamp.html) -> [`PyDateTime`]({{#PYO3_DOCS_URL}}/pyo3/types/struct.PyDateTime.html)

### `num-bigint`

Expand Down
12 changes: 6 additions & 6 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ def test_rust(session: nox.Session):
if not FREE_THREADED_BUILD:
_run_cargo_test(session, features="abi3")
if "skip-full" not in session.posargs:
_run_cargo_test(session, features="full jiff-01")
_run_cargo_test(session, features="full jiff-02")
if not FREE_THREADED_BUILD:
_run_cargo_test(session, features="abi3 full jiff-01")
_run_cargo_test(session, features="abi3 full jiff-02")


@nox.session(name="test-py", venv_backend="none")
Expand Down Expand Up @@ -395,7 +395,7 @@ def docs(session: nox.Session) -> None:

if get_rust_version()[:2] >= (1, 70):
# jiff needs MSRC 1.70+
features += ",jiff-01"
features += ",jiff-02"

shutil.rmtree(PYO3_DOCS_TARGET, ignore_errors=True)
_run_cargo(
Expand Down Expand Up @@ -777,8 +777,8 @@ def update_ui_tests(session: nox.Session):
env["TRYBUILD"] = "overwrite"
command = ["test", "--test", "test_compile_error"]
_run_cargo(session, *command, env=env)
_run_cargo(session, *command, "--features=full,jiff-01", env=env)
_run_cargo(session, *command, "--features=abi3,full,jiff-01", env=env)
_run_cargo(session, *command, "--features=full,jiff-02", env=env)
_run_cargo(session, *command, "--features=abi3,full,jiff-02", env=env)


def _build_docs_for_ffi_check(session: nox.Session) -> None:
Expand Down Expand Up @@ -831,7 +831,7 @@ def _get_feature_sets() -> Generator[Tuple[str, ...], None, None]:

if get_rust_version()[:2] >= (1, 70):
# jiff needs MSRC 1.70+
features += ",jiff-01"
features += ",jiff-02"

yield (f"--features={features}",)
yield (f"--features=abi3,{features}",)
Expand Down
20 changes: 11 additions & 9 deletions src/conversions/jiff.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg(feature = "jiff-01")]
#![cfg(feature = "jiff-02")]

//! Conversions to and from [jiff](https://docs.rs/jiff/)’s `Span`, `SignedDuration`, `TimeZone`,
//! `Offset`, `Date`, `Time`, `DateTime`, `Zoned`, and `Timestamp`.
Expand All @@ -9,8 +9,8 @@
//!
//! ```toml
//! [dependencies]
//! jiff = "0.1"
#![doc = concat!("pyo3 = { version = \"", env!("CARGO_PKG_VERSION"), "\", features = [\"jiff-01\"] }")]
//! jiff = "0.2"
#![doc = concat!("pyo3 = { version = \"", env!("CARGO_PKG_VERSION"), "\", features = [\"jiff-02\"] }")]
//! ```
//!
//! Note that you must use compatible versions of jiff and PyO3.
Expand All @@ -21,7 +21,7 @@
//!
//! ```rust
//! # #![cfg_attr(windows, allow(unused_imports))]
//! # use jiff_01 as jiff;
//! # use jiff_02 as jiff;
//! use jiff::{Zoned, SignedDuration, ToSpan};
//! use pyo3::{Python, PyResult, IntoPyObject, types::PyAnyMethods};
//!
Expand Down Expand Up @@ -65,8 +65,8 @@ use crate::{intern, Bound, FromPyObject, IntoPyObject, Py, PyAny, PyErr, PyResul
use jiff::civil::{Date, DateTime, Time};
use jiff::tz::{Offset, TimeZone};
use jiff::{SignedDuration, Span, Timestamp, Zoned};
#[cfg(feature = "jiff-01")]
use jiff_01 as jiff;
#[cfg(feature = "jiff-02")]
use jiff_02 as jiff;

#[cfg(not(Py_LIMITED_API))]
fn datetime_to_pydatetime<'py>(
Expand Down Expand Up @@ -1120,6 +1120,7 @@ mod tests {
use super::*;
use crate::types::IntoPyDict;
use jiff::tz::TimeZoneTransition;
use jiff::SpanRelativeTo;
use proptest::prelude::*;
use std::ffi::CString;

Expand Down Expand Up @@ -1191,10 +1192,11 @@ mod tests {
// python values of durations (from -999999999 to 999999999 days),
Python::with_gil(|py| {
if let Ok(span) = Span::new().try_days(days) {
let date = Date::new(2025, 1, 1).unwrap();
let py_delta = span.to_jiff_duration(date).unwrap().into_pyobject(py).unwrap();
let relative_to = SpanRelativeTo::days_are_24_hours();
let jiff_duration = span.to_duration(relative_to).unwrap();
let py_delta = jiff_duration.into_pyobject(py).unwrap();
let roundtripped: Span = py_delta.extract().expect("Round trip");
assert_eq!(span.compare(roundtripped).unwrap(), Ordering::Equal);
assert_eq!(span.compare((roundtripped, relative_to)).unwrap(), Ordering::Equal);
}
})
}
Expand Down
4 changes: 2 additions & 2 deletions src/types/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use crate::types::any::PyAnyMethods;
use crate::types::PyTuple;
use crate::{Bound, IntoPyObject, PyAny, PyErr, Python};
use std::os::raw::c_int;
#[cfg(any(feature = "chrono", feature = "jiff-01"))]
#[cfg(any(feature = "chrono", feature = "jiff-02"))]
use std::ptr;

fn ensure_datetime_api(py: Python<'_>) -> PyResult<&'static PyDateTime_CAPI> {
Expand Down Expand Up @@ -698,7 +698,7 @@ pub fn timezone_utc_bound(py: Python<'_>) -> Bound<'_, PyTzInfo> {
/// Equivalent to `datetime.timezone` constructor
///
/// Only used internally
#[cfg(any(feature = "chrono", feature = "jiff-01"))]
#[cfg(any(feature = "chrono", feature = "jiff-02"))]
pub(crate) fn timezone_from_offset<'py>(
offset: &Bound<'py, PyDelta>,
) -> PyResult<Bound<'py, PyTzInfo>> {
Expand Down
2 changes: 1 addition & 1 deletion src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ mod code;
pub(crate) mod complex;
#[cfg(not(Py_LIMITED_API))]
pub(crate) mod datetime;
#[cfg(all(Py_LIMITED_API, any(feature = "chrono", feature = "jiff-01")))]
#[cfg(all(Py_LIMITED_API, any(feature = "chrono", feature = "jiff-02")))]
pub(crate) mod datetime_abi3;
pub(crate) mod dict;
mod ellipsis;
Expand Down

0 comments on commit f3d3245

Please sign in to comment.