Skip to contentSkip to conversation

xen.inc: python 3.12: fix datetime deprecation warning

PATCH Superseded Stanley Stanton 2 participants 7 messages Nov 18, 2024 – Nov 25, 2024 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen.inc: python 3.12: fix datetime deprecation warning

Datetime.UTC seems is a wrapper for datetime.timezone.utc, which is available on both python 3.10, and python 3.12 (Ubuntu 24.04) so, opt to use that instead.

---
 recipes-extended/xen/xen.inc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
recipes-extended/xen/xen.inc +1 -1
index dcd281b5..63790f73 100644
@@ -151,7 +151,7 @@ def get_build_time_vars(d):
     source_date_epoch = d.getVar('SOURCE_DATE_EPOCH')
     if source_date_epoch is not None:
         import datetime
-        utc_datetime = datetime.datetime.utcfromtimestamp(float(source_date_epoch))
+        utc_datetime =  datetime.datetime.fromtimestamp(float(source_date_epoch), datetime.timezone.utc)
         return " XEN_BUILD_DATE=" + utc_datetime.strftime("%Y-%m-%d") + \
                " XEN_BUILD_TIME=" + utc_datetime.strftime("%H:%M:%S")
     return ""
Signature · 8 lines
2.43.0


-- 

This communication is confidential. We only send and receive email on the
basis of the terms set out at www.taitcommunications.com/email_disclaimer 
<http://www.taitcommunications.com/email_disclaimer>
#1 lore raw
Quoted 4 lines · Stanley Stanton via lists.yoctoproject.org

Datetime.UTC seems is a wrapper for datetime.timezone.utc, which is available on both python 3.10, and python 3.12 (Ubuntu 24.04) so, opt to use that instead.

No objection to the patch, but this commit log doesn't actually tell me what the problem is, so I can't tell what this is fixing.

Bruce

Quoted 44 lines
---
 recipes-extended/xen/xen.inc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
recipes-extended/xen/xen.inc +1 -1
index dcd281b5..63790f73 100644
@@ -151,7 +151,7 @@ def get_build_time_vars(d):
     source_date_epoch = d.getVar('SOURCE_DATE_EPOCH')
     if source_date_epoch is not None:
         import datetime
-        utc_datetime =
 datetime.datetime.utcfromtimestamp(float(source_date_epoch))
+        utc_datetime =
 datetime.datetime.fromtimestamp(float(source_date_epoch),
 datetime.timezone.utc)
         return " XEN_BUILD_DATE=" + utc_datetime.strftime("%Y-%m-%d") + \
                " XEN_BUILD_TIME=" + utc_datetime.strftime("%H:%M:%S")
     return ""

--
2.43.0

--

This communication is confidential. We only send and receive email on the basis of the terms set out at www.taitcommunications.com/email_disclaimer
<http://www.taitcommunications.com/email_disclaimer>

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group. View/Reply Online (#8972):
https://lists.yoctoproject.org/g/meta-virtualization/message/8972
Mute This Topic: https://lists.yoctoproject.org/mt/109654730/1050810
Group Owner: [email protected]
Unsubscribe: https://lists.yoctoproject.org/g/meta-virtualization/unsub [ [email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Signature · 3 lines
- Thou shalt not follow the NULL pointer, for chaos and madness await thee
at its end
- "Use the force Harry" - Gandalf, Star Trek II

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw
Quoted 5 lines · Bruce Ashfield via lists.yoctoproject.org

On Mon, Nov 18, 2024 at 5:32 PM Stanley Stanton via lists.yoctoproject.org <[email protected]> wrote:

Quoted 8 lines
Quoted 4 lines

Datetime.UTC seems is a wrapper for datetime.timezone.utc, which is available on both python 3.10, and python 3.12 (Ubuntu 24.04) so, opt to use that instead.

No objection to the patch, but this commit log doesn't actually tell me what the problem is, so I can't tell what this is fixing.

Sorry, what I meant to say (and I said it badly), is that we should capture the warning that is being thrown, since that is what someone will search for if they are having the same issue.

We also need to make sure that all of the versions of python (and hosts) supported by OE core / yocto have the function in question (or does this just get executed by python3-native and not the host python ? .. I'll have to check on that tomorrow, I can't recall right now). Your current commit log makes me think that it is the host distro python, otherwise, the version of python in ubuntu 24.04 isn't relevant.

Bruce

Quoted 59 lines

Bruce

Quoted 26 lines
---
 recipes-extended/xen/xen.inc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
recipes-extended/xen/xen.inc +1 -1
index dcd281b5..63790f73 100644
@@ -151,7 +151,7 @@ def get_build_time_vars(d):
     source_date_epoch = d.getVar('SOURCE_DATE_EPOCH')
     if source_date_epoch is not None:
         import datetime
-        utc_datetime =
 datetime.datetime.utcfromtimestamp(float(source_date_epoch))
+        utc_datetime =
 datetime.datetime.fromtimestamp(float(source_date_epoch),
 datetime.timezone.utc)
         return " XEN_BUILD_DATE=" + utc_datetime.strftime("%Y-%m-%d") + \
                " XEN_BUILD_TIME=" + utc_datetime.strftime("%H:%M:%S")
     return ""

--
2.43.0

Quoted 10 lines

--

This communication is confidential. We only send and receive email on the basis of the terms set out at www.taitcommunications.com/email_disclaimer
<http://www.taitcommunications.com/email_disclaimer>

--
- Thou shalt not follow the NULL pointer, for chaos and madness await thee at its end
- "Use the force Harry" - Gandalf, Star Trek II

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group. View/Reply Online (#8973):
https://lists.yoctoproject.org/g/meta-virtualization/message/8973
Mute This Topic: https://lists.yoctoproject.org/mt/109654730/1050810
Group Owner: [email protected]
Unsubscribe: https://lists.yoctoproject.org/g/meta-virtualization/unsub [ [email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Signature · 3 lines
- Thou shalt not follow the NULL pointer, for chaos and madness await thee
at its end
- "Use the force Harry" - Gandalf, Star Trek II
#4 lore raw

Thanks for the feedback Bruce. To clarify:

*
Yes, the hosttools Python version is being used for the get_build_time_vars function in xen.inc.
*
The warning in particular I'm seeing

     *

DeprecationWarning: datetime.datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.fromtimestamp(timestamp, datetime.UTC)
*
I have only truly tested the backwards compatibility with Ubuntu 22.04, which provides python 3.10. A brief look also shows that python 3.2 contained datetime.timezone, which is the API used in the patch.

I will send a v2 of this patch describing this information.

Thanks,

Stanley
________________________________
From: Bruce Ashfield <[email protected]>
Sent: Tuesday, November 19, 2024 3:40 PM
To: [email protected] <[email protected]>
Cc: Stanley Stanton <[email protected]>; [email protected] <[email protected]>
Subject: Re: [meta-virtualization] [PATCH] xen.inc: python 3.12: fix datetime deprecation warning

You don't often get email from [email protected]. Learn why this is important<https://aka.ms/LearnAboutSenderIdentification>

On Mon, Nov 18, 2024 at 9:30 PM Bruce Ashfield via lists.yoctoproject.org<http://lists.yoctoproject.org/> <[email protected]<mailto:[email protected]>> wrote:

On Mon, Nov 18, 2024 at 5:32 PM Stanley Stanton via lists.yoctoproject.org<http://lists.yoctoproject.org/> <[email protected]<mailto:[email protected]>> wrote:
Datetime.UTC seems is a wrapper for datetime.timezone.utc,
which is available on both python 3.10, and python 3.12 (Ubuntu 24.04)
so, opt to use that instead.

No objection to the patch, but this commit log doesn't actually tell me what the problem is, so I can't tell what this is fixing.

Sorry, what I meant to say (and I said it badly), is that we should capture the warning that is being thrown, since that is what someone will search for if they are having the same issue.

We also need to make sure that all of the versions of python (and hosts) supported by OE core / yocto have the function in question (or does this just get executed by python3-native and not the host python ? .. I'll have to check on that tomorrow, I can't recall right now). Your current commit log makes me think that it is the host distro python, otherwise, the version of python in ubuntu 24.04 isn't relevant.

Bruce

Bruce

---
 recipes-extended/xen/xen.inc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
recipes-extended/xen/xen.inc +1 -1
index dcd281b5..63790f73 100644
@@ -151,7 +151,7 @@ def get_build_time_vars(d):
     source_date_epoch = d.getVar('SOURCE_DATE_EPOCH')
     if source_date_epoch is not None:
         import datetime
-        utc_datetime = datetime.datetime.utcfromtimestamp(float(source_date_epoch))
+        utc_datetime =  datetime.datetime.fromtimestamp(float(source_date_epoch), datetime.timezone.utc)
         return " XEN_BUILD_DATE=" + utc_datetime.strftime("%Y-%m-%d") + \
                " XEN_BUILD_TIME=" + utc_datetime.strftime("%H:%M:%S")
     return ""

--
2.43.0

--

This communication is confidential. We only send and receive email on the
basis of the terms set out at www.taitcommunications.com/email_disclaimer<http://www.taitcommunications.com/email_disclaimer>
<http://www.taitcommunications.com/email_disclaimer>

--
- Thou shalt not follow the NULL pointer, for chaos and madness await thee at its end
- "Use the force Harry" - Gandalf, Star Trek II

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#8973): https://lists.yoctoproject.org/g/meta-virtualization/message/8973
Mute This Topic: https://lists.yoctoproject.org/mt/109654730/1050810
Group Owner: [email protected]<mailto:meta-virtualization%[email protected]>
Unsubscribe: https://lists.yoctoproject.org/g/meta-virtualization/unsub [[email protected]<mailto:[email protected]>]
-=-=-=-=-=-=-=-=-=-=-=-

--
- Thou shalt not follow the NULL pointer, for chaos and madness await thee at its end
- "Use the force Harry" - Gandalf, Star Trek II

#5 lore raw

PATCH v2 1/1 xen.inc: python 3.12: fix datetime deprecation warning

In reply to Bruce Ashfield

Parsing xen.inc with a host distro that provides python 3.12 (such as Ubuntu 24.04) generates the following deprecation warning:

DeprecationWarning: datetime.datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.fromtimestamp(timestamp, datetime.UTC)

This warning comes from the use of datetime.datetime.utcfromtimestamp() in get_build_time_vars.

datetime.UTC seems to be a getter wrapper for datetime.timezone.utc, which is already available on older host distro python versions (I have tested only with python 3.10 provided by Ubuntu 22.04) so, opt to use that instead to prevent a breaking change.

---
 recipes-extended/xen/xen.inc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
recipes-extended/xen/xen.inc +1 -1
index dcd281b5..63790f73 100644
@@ -151,7 +151,7 @@ def get_build_time_vars(d):
     source_date_epoch = d.getVar('SOURCE_DATE_EPOCH')
     if source_date_epoch is not None:
         import datetime
-        utc_datetime = datetime.datetime.utcfromtimestamp(float(source_date_epoch))
+        utc_datetime =  datetime.datetime.fromtimestamp(float(source_date_epoch), datetime.timezone.utc)
         return " XEN_BUILD_DATE=" + utc_datetime.strftime("%Y-%m-%d") + \
                " XEN_BUILD_TIME=" + utc_datetime.strftime("%H:%M:%S")
     return ""
Signature · 8 lines
2.43.0


-- 

This communication is confidential. We only send and receive email on the
basis of the terms set out at www.taitcommunications.com/email_disclaimer 
<http://www.taitcommunications.com/email_disclaimer>
#6 lore raw

v2 is merged to master. Request cherry-picks to any other branches of interest.

Bruce

In message: [meta-virtualization] [PATCH v2] xen.inc: python 3.12: fix datetime deprecation warning

Quoted 52 lines · on 19/11/2024 Stanley Stanton via lists.yoctoproject.org wrote:

Parsing xen.inc with a host distro that provides python 3.12 (such as Ubuntu 24.04) generates the following deprecation warning:

DeprecationWarning: datetime.datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.fromtimestamp(timestamp, datetime.UTC)

This warning comes from the use of datetime.datetime.utcfromtimestamp() in get_build_time_vars.

datetime.UTC seems to be a getter wrapper for datetime.timezone.utc, which is already available on older host distro python versions (I have tested only with python 3.10 provided by Ubuntu 22.04) so, opt to use that instead to prevent a breaking change.

---
 recipes-extended/xen/xen.inc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
recipes-extended/xen/xen.inc +1 -1
index dcd281b5..63790f73 100644
@@ -151,7 +151,7 @@ def get_build_time_vars(d):
     source_date_epoch = d.getVar('SOURCE_DATE_EPOCH')
     if source_date_epoch is not None:
         import datetime
-        utc_datetime = datetime.datetime.utcfromtimestamp(float(source_date_epoch))
+        utc_datetime =  datetime.datetime.fromtimestamp(float(source_date_epoch), datetime.timezone.utc)
         return " XEN_BUILD_DATE=" + utc_datetime.strftime("%Y-%m-%d") + \
                " XEN_BUILD_TIME=" + utc_datetime.strftime("%H:%M:%S")
     return ""
Signature · 18 lines
2.43.0


-- 

This communication is confidential. We only send and receive email on the
basis of the terms set out at www.taitcommunications.com/email_disclaimer 
<http://www.taitcommunications.com/email_disclaimer>



-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#8976): https://lists.yoctoproject.org/g/meta-virtualization/message/8976
Mute This Topic: https://lists.yoctoproject.org/mt/109659338/1050810
Group Owner: [email protected]
Unsubscribe: https://lists.yoctoproject.org/g/meta-virtualization/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-
#7 lore raw

Hi Bruce,

I'd like to request this patch be cherry-picked to scarthgap.

Thanks,
Stan

________________________________
From: Bruce Ashfield <[email protected]>
Sent: Thursday, November 21, 2024 5:30 PM
To: Stanley Stanton <[email protected]>
Cc: [email protected] <[email protected]>
Subject: Re: [meta-virtualization] [PATCH v2] xen.inc: python 3.12: fix datetime deprecation warning

[You don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]

v2 is merged to master. Request cherry-picks to any other branches of interest.

Bruce

In message: [meta-virtualization] [PATCH v2] xen.inc: python 3.12: fix datetime deprecation warning

Quoted 52 lines · on 19/11/2024 Stanley Stanton via lists.yoctoproject.org wrote:

Parsing xen.inc with a host distro that provides python 3.12 (such as Ubuntu 24.04) generates the following deprecation warning:

DeprecationWarning: datetime.datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.fromtimestamp(timestamp, datetime.UTC)

This warning comes from the use of datetime.datetime.utcfromtimestamp() in get_build_time_vars.

datetime.UTC seems to be a getter wrapper for datetime.timezone.utc, which is already available on older host distro python versions (I have tested only with python 3.10 provided by Ubuntu 22.04) so, opt to use that instead to prevent a breaking change.

---
 recipes-extended/xen/xen.inc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
recipes-extended/xen/xen.inc +1 -2
index dcd281b5..63790f73 100644
@@ -151,7 +151,7 @@ def get_build_time_vars(d):
     source_date_epoch = d.getVar('SOURCE_DATE_EPOCH')
     if source_date_epoch is not None:
         import datetime
-        utc_datetime = datetime.datetime.utcfromtimestamp(float(source_date_epoch))
+        utc_datetime =  datetime.datetime.fromtimestamp(float(source_date_epoch), datetime.timezone.utc)
         return " XEN_BUILD_DATE=" + utc_datetime.strftime("%Y-%m-%d") + \
                " XEN_BUILD_TIME=" + utc_datetime.strftime("%H:%M:%S")
     return ""
--

2.43.0

--

This communication is confidential. We only send and receive email on the
basis of the terms set out at https://aus01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.taitcommunications.com%2Femail_disclaimer&data=05%7C02%7Cstanley.stanton%40taitcommunications.com%7C031f9b33b39345c39da608dd09e550c8%7Cb9ac1691179e406f90a36d5b9a817466%7C0%7C0%7C638677602708905473%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=Tsw5pm4dYCwVwQAEJAVqa6ChRJKHV%2FyOOLkiLFWo8zE%3D&reserved=0<http://www.taitcommunications.com/email_disclaimer>
<https://aus01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.taitcommunications.com%2Femail_disclaimer&data=05%7C02%7Cstanley.stanton%40taitcommunications.com%7C031f9b33b39345c39da608dd09e550c8%7Cb9ac1691179e406f90a36d5b9a817466%7C0%7C0%7C638677602708929015%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=zbqbUs9GZKe3d%2BhWA3U0b4MrfWFqqYzTgpiPJJHsc1I%3D&reserved=0<http://www.taitcommunications.com/email_disclaimer>>

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#8976): https://aus01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.yoctoproject.org%2Fg%2Fmeta-virtualization%2Fmessage%2F8976&data=05%7C02%7Cstanley.stanton%40taitcommunications.com%7C031f9b33b39345c39da608dd09e550c8%7Cb9ac1691179e406f90a36d5b9a817466%7C0%7C0%7C638677602708943105%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=xe6ynKi6mSTfH9UchDc8oNCr19kX60IuRArtqoGPKpM%3D&reserved=0<https://lists.yoctoproject.org/g/meta-virtualization/message/8976>
Mute This Topic: https://aus01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.yoctoproject.org%2Fmt%2F109659338%2F1050810&data=05%7C02%7Cstanley.stanton%40taitcommunications.com%7C031f9b33b39345c39da608dd09e550c8%7Cb9ac1691179e406f90a36d5b9a817466%7C0%7C0%7C638677602708954926%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=PNTWHSzu3JHYVAm3Eevly2O%2BxIr%2Fz6oq%2BxGnX43T2pU%3D&reserved=0<https://lists.yoctoproject.org/mt/109659338/1050810>
Group Owner: [email protected]
Unsubscribe: https://aus01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.yoctoproject.org%2Fg%2Fmeta-virtualization%2Funsub&data=05%7C02%7Cstanley.stanton%40taitcommunications.com%7C031f9b33b39345c39da608dd09e550c8%7Cb9ac1691179e406f90a36d5b9a817466%7C0%7C0%7C638677602708969331%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=OBh4KvfqkwNa17qx%2F39cjPhgp4U%2ByKv3B6sQiMB4q90%3D&reserved=0<https://lists.yoctoproject.org/g/meta-virtualization/unsub> [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-