Fix deprecated utcnow() usage in build-many-glibcs.py

Message ID b591634-55b1-3d7c-81b1-337ed4ed214@redhat.com
State Committed
Commit 9da45337e4fcaa710e849e8c6baf22341c059e00
Headers
Series Fix deprecated utcnow() usage in build-many-glibcs.py |

Checks

Context Check Description
redhat-pt-bot/TryBot-apply_patch success Patch applied to master at the time it was sent
linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 success Testing passed
redhat-pt-bot/TryBot-32bit success Build for i686
linaro-tcwg-bot/tcwg_glibc_check--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_glibc_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_glibc_check--master-arm success Testing passed

Commit Message

Joseph Myers Jan. 9, 2024, 9:39 p.m. UTC
  Running build-many-glibcs.py with Python 3.12 or later produces a
warning:

build-many-glibcs.py:566: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
  build_time = datetime.datetime.utcnow()

Replace with datetime.datetime.now(datetime.timezone.utc) (the
datetime.UTC constant is new in 3.11, so not suitable for use in this
script at present).
  

Comments

Florian Weimer Jan. 10, 2024, 10:41 a.m. UTC | #1
* Joseph Myers:

> Running build-many-glibcs.py with Python 3.12 or later produces a
> warning:
>
> build-many-glibcs.py:566: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
>   build_time = datetime.datetime.utcnow()
>
> Replace with datetime.datetime.now(datetime.timezone.utc) (the
> datetime.UTC constant is new in 3.11, so not suitable for use in this
> script at present).
>
> diff --git a/scripts/build-many-glibcs.py b/scripts/build-many-glibcs.py
> index 7e0b90be89..87a42e4aef 100755
> --- a/scripts/build-many-glibcs.py
> +++ b/scripts/build-many-glibcs.py
> @@ -563,7 +563,7 @@ class Context(object):
>                  print(config.name, config.compiler.name)
>              return
>          self.clear_last_build_state(action)
> -        build_time = datetime.datetime.utcnow()
> +        build_time = datetime.datetime.now(datetime.timezone.utc)
>          if action == 'host-libraries':
>              build_components = ('gmp', 'mpfr', 'mpc')
>              old_components = ()

Double-checked that this works with Python 3.6, looks good, thanks.

Florian
  

Patch

diff --git a/scripts/build-many-glibcs.py b/scripts/build-many-glibcs.py
index 7e0b90be89..87a42e4aef 100755
--- a/scripts/build-many-glibcs.py
+++ b/scripts/build-many-glibcs.py
@@ -563,7 +563,7 @@  class Context(object):
                 print(config.name, config.compiler.name)
             return
         self.clear_last_build_state(action)
-        build_time = datetime.datetime.utcnow()
+        build_time = datetime.datetime.now(datetime.timezone.utc)
         if action == 'host-libraries':
             build_components = ('gmp', 'mpfr', 'mpc')
             old_components = ()