Skip to content

Commit

Permalink
add pendulum-wheel
Browse files Browse the repository at this point in the history
- add cross/pendulum with patch for 32-bit archs
- add cross/pendulum to python311-wheels
  • Loading branch information
hgy59 committed Jan 19, 2025
1 parent f2a562d commit d880f44
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 0 deletions.
22 changes: 22 additions & 0 deletions cross/pendulum/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
PKG_NAME = pendulum
PKG_VERS = 3.0.0
PKG_EXT = tar.gz
PKG_DIST_NAME = $(PKG_NAME)-$(PKG_VERS).$(PKG_EXT)
PKG_DIST_SITE = https://files.pythonhosted.org/packages/b8/fe/27c7438c6ac8b8f8bef3c6e571855602ee784b85d072efddfff0ceb1cd77
PKG_DIR = $(PKG_NAME)-$(PKG_VERS)

DEPENDS =

HOMEPAGE = https://pendulum.eustace.io
COMMENT = Python datetimes made easy.
LICENSE = MIT

PATCHES_LEVEL = 1

include ../../mk/spksrc.common.mk

ifeq ($(call version_le, $(TC_GCC), 5),1)
ADDITIONAL_CFLAGS = -std=c99
endif

include ../../mk/spksrc.python-wheel.mk
3 changes: 3 additions & 0 deletions cross/pendulum/digests
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pendulum-3.0.0.tar.gz SHA1 ea64f64ccbe4ec6bc05c63c28da6910fb5ac0842
pendulum-3.0.0.tar.gz SHA256 5d034998dea404ec31fae27af6b22cff1708f830a1ed7353be4d1019bb9f584e
pendulum-3.0.0.tar.gz MD5 3beb45818d19839157e57a2f81b40ebb
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
https://sources.debian.org/patches/pendulum/3.0.0-2/rust-Use-i64-for-internal-unix-timestamps.patch

From: Benjamin Drung <[email protected]>
Date: Thu, 5 Sep 2024 14:03:44 +0200
Subject: rust: Use i64 for internal unix timestamps

pendulum 3.0.0 fails to build on 32-bit armhf:

```
error: this arithmetic operation will overflow
--> src/helpers.rs:59:20
|
59 | seconds += ((146_097 - 10957) * SECS_PER_DAY as usize) as isize;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attempt to compute `135140_usize * 86400_usize`, which would overflow
|
= note: `#[deny(arithmetic_overflow)]` on by default
```

`(146_097 - 10957) * SECS_PER_DAY` equals 11,676,096,000 which does not
fit into 32 bit integers.

Use i64 for the seconds variable while handling with the timestamp. Only
convert in to `usize` once the timestamp is split into its components.

Fixes https://github.com/sdispater/pendulum/issues/784
Ubuntu-Bug: https://bugs.launchpad.net/ubuntu/+source/pendulum/+bug/2079029
Forwarded: https://github.com/sdispater/pendulum/pull/842
---
rust/src/helpers.rs | 38 +++++++++++++++++++-------------------
1 file changed, 19 insertions(+), 19 deletions(-)

diff --git a/rust/src/helpers.rs b/rust/src/helpers.rs
index 364075a..7927413 100644
--- a/rust/src/helpers.rs
+++ b/rust/src/helpers.rs
@@ -49,57 +49,57 @@ pub fn local_time(
microsecond: usize,
) -> (usize, usize, usize, usize, usize, usize, usize) {
let mut year: usize = EPOCH_YEAR as usize;
- let mut seconds: isize = unix_time.floor() as isize;
+ let mut seconds: i64 = unix_time.floor() as i64;

// Shift to a base year that is 400-year aligned.
if seconds >= 0 {
- seconds -= (10957 * SECS_PER_DAY as usize) as isize;
+ seconds -= 10957 * SECS_PER_DAY as i64;
year += 30; // == 2000
} else {
- seconds += ((146_097 - 10957) * SECS_PER_DAY as usize) as isize;
+ seconds += (146_097 - 10957) * SECS_PER_DAY as i64;
year -= 370; // == 1600
}

- seconds += utc_offset;
+ seconds += utc_offset as i64;

// Handle years in chunks of 400/100/4/1
- year += 400 * (seconds / SECS_PER_400_YEARS as isize) as usize;
- seconds %= SECS_PER_400_YEARS as isize;
+ year += 400 * (seconds / SECS_PER_400_YEARS as i64) as usize;
+ seconds %= SECS_PER_400_YEARS as i64;
if seconds < 0 {
- seconds += SECS_PER_400_YEARS as isize;
+ seconds += SECS_PER_400_YEARS as i64;
year -= 400;
}

let mut leap_year = 1; // 4-century aligned
- let mut sec_per_100years = SECS_PER_100_YEARS[leap_year] as isize;
+ let mut sec_per_100years = SECS_PER_100_YEARS[leap_year].try_into().unwrap();

while seconds >= sec_per_100years {
seconds -= sec_per_100years;
year += 100;
leap_year = 0; // 1-century, non 4-century aligned
- sec_per_100years = SECS_PER_100_YEARS[leap_year] as isize;
+ sec_per_100years = SECS_PER_100_YEARS[leap_year].try_into().unwrap();
}

- let mut sec_per_4years = SECS_PER_4_YEARS[leap_year] as isize;
+ let mut sec_per_4years = SECS_PER_4_YEARS[leap_year].try_into().unwrap();
while seconds >= sec_per_4years {
seconds -= sec_per_4years;
year += 4;
leap_year = 1; // 4-year, non century aligned
- sec_per_4years = SECS_PER_4_YEARS[leap_year] as isize;
+ sec_per_4years = SECS_PER_4_YEARS[leap_year].try_into().unwrap();
}

- let mut sec_per_year = SECS_PER_YEAR[leap_year] as isize;
+ let mut sec_per_year = SECS_PER_YEAR[leap_year].try_into().unwrap();
while seconds >= sec_per_year {
seconds -= sec_per_year;
year += 1;
leap_year = 0; // non 4-year aligned
- sec_per_year = SECS_PER_YEAR[leap_year] as isize;
+ sec_per_year = SECS_PER_YEAR[leap_year].try_into().unwrap();
}

// Handle months and days
let mut month = TM_DECEMBER + 1;
- let mut day: usize = (seconds / (SECS_PER_DAY as isize) + 1) as usize;
- seconds %= SECS_PER_DAY as isize;
+ let mut day: usize = (seconds / (SECS_PER_DAY as i64) + 1) as usize;
+ seconds %= SECS_PER_DAY as i64;

let mut month_offset: usize;
while month != (TM_JANUARY + 1) {
@@ -113,10 +113,10 @@ pub fn local_time(
}

// Handle hours, minutes and seconds
- let hour: usize = (seconds / SECS_PER_HOUR as isize) as usize;
- seconds %= SECS_PER_HOUR as isize;
- let minute: usize = (seconds / SECS_PER_MIN as isize) as usize;
- let second: usize = (seconds % SECS_PER_MIN as isize) as usize;
+ let hour: usize = (seconds / SECS_PER_HOUR as i64) as usize;
+ seconds %= SECS_PER_HOUR as i64;
+ let minute: usize = (seconds / SECS_PER_MIN as i64) as usize;
+ let second: usize = (seconds % SECS_PER_MIN as i64) as usize;

(year, month, day, hour, minute, second, microsecond)
}
4 changes: 4 additions & 0 deletions spk/python311-wheels/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ WHEELS += src/requirements-pure.txt

include ../../mk/spksrc.common.mk

# [Pendulum] python-wheel
DEPENDS += cross/pendulum


# [borgbackup]
# Use OpenSSL path as defined by either
# spksrc.wheel-env.mk or spksrc.python.mk
Expand Down

0 comments on commit d880f44

Please sign in to comment.