This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch v2-8-test
in repository https://gitbox.apache.org/repos/asf/airflow.git

commit 89272d5d37848a8719490edfcab8a0af7c5b118a
Author: Andrey Anshin <[email protected]>
AuthorDate: Fri Feb 16 16:43:52 2024 +0400

    Replace usage of `datetime.utcnow` and `datetime.utcfromtimestamp` in dev 
(#37473)
    
    * Replace usage of `datetime.utcnow` and `datetime.utcfromtimestamp` in dev
    
    * Apply suggestions from code review
    
    Co-authored-by: Pankaj Koti <[email protected]>
    
    ---------
    
    Co-authored-by: Pankaj Koti <[email protected]>
    (cherry picked from commit a3e939f22f0e895d7b0897b4eba13908822f267d)
---
 dev/breeze/src/airflow_breeze/utils/github.py          | 4 ++--
 dev/breeze/src/airflow_breeze/utils/parallel.py        | 4 ++--
 pyproject.toml                                         | 3 +++
 scripts/in_container/update_quarantined_test_status.py | 4 ++--
 4 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/dev/breeze/src/airflow_breeze/utils/github.py 
b/dev/breeze/src/airflow_breeze/utils/github.py
index d2f7d53239..9c4c2da07c 100644
--- a/dev/breeze/src/airflow_breeze/utils/github.py
+++ b/dev/breeze/src/airflow_breeze/utils/github.py
@@ -18,7 +18,7 @@ from __future__ import annotations
 
 import re
 import sys
-from datetime import datetime
+from datetime import datetime, timezone
 from pathlib import Path
 from typing import Any
 
@@ -155,4 +155,4 @@ def get_tag_date(tag: str) -> str | None:
     timestamp: int = (
         tag_object.committed_date if hasattr(tag_object, "committed_date") 
else tag_object.tagged_date
     )
-    return datetime.utcfromtimestamp(timestamp).strftime("%Y-%m-%dT%H:%M:%SZ")
+    return datetime.fromtimestamp(timestamp, 
tz=timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
diff --git a/dev/breeze/src/airflow_breeze/utils/parallel.py 
b/dev/breeze/src/airflow_breeze/utils/parallel.py
index eca700a18a..f2fd915b41 100644
--- a/dev/breeze/src/airflow_breeze/utils/parallel.py
+++ b/dev/breeze/src/airflow_breeze/utils/parallel.py
@@ -283,7 +283,7 @@ class ParallelMonitor(Thread):
         self.time_in_seconds = time_in_seconds
         self.debug_resources = debug_resources
         self.progress_matcher = progress_matcher
-        self.start_time = datetime.datetime.utcnow()
+        self.start_time = datetime.datetime.now(tz=datetime.timezone.utc)
 
     def print_single_progress(self, output: Output):
         if self.progress_matcher:
@@ -312,7 +312,7 @@ class ParallelMonitor(Thread):
     def print_summary(self):
         import psutil
 
-        time_passed = datetime.datetime.utcnow() - self.start_time
+        time_passed = datetime.datetime.now(tz=datetime.timezone.utc) - 
self.start_time
         get_console().rule()
         for output in self.outputs:
             self.print_single_progress(output)
diff --git a/pyproject.toml b/pyproject.toml
index cd8e649671..67cf05952a 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1370,6 +1370,9 @@ banned-module-level-imports = ["numpy", "pandas"]
 "airflow.AirflowException".msg = "Use airflow.exceptions.AirflowException 
instead."
 "airflow.Dataset".msg = "Use airflow.datasets.Dataset instead."
 "airflow.models.baseoperator.BaseOperatorLink".msg = "Use 
airflow.models.baseoperatorlink.BaseOperatorLink"
+# Deprecated in Python 3.12: https://github.com/python/cpython/issues/103857
+"datetime.datetime.utcnow".msg = "Use airflow.utils.timezone.utcnow or 
datetime.datetime.now(tz=datetime.timezone.utc)"
+"datetime.datetime.utcfromtimestamp".msg = "Use 
airflow.utils.timezone.from_timestamp or 
datetime.datetime.fromtimestamp(tz=datetime.timezone.utc)"
 # Uses deprecated in Python 3.12 `datetime.datetime.utcfromtimestamp`
 "pendulum.from_timestamp".msg = "Use airflow.utils.timezone.from_timestamp"
 
diff --git a/scripts/in_container/update_quarantined_test_status.py 
b/scripts/in_container/update_quarantined_test_status.py
index 2d589f1f89..a3f045843c 100755
--- a/scripts/in_container/update_quarantined_test_status.py
+++ b/scripts/in_container/update_quarantined_test_status.py
@@ -20,7 +20,7 @@ from __future__ import annotations
 import os
 import re
 import sys
-from datetime import datetime
+from datetime import datetime, timezone
 from pathlib import Path
 from typing import NamedTuple
 from urllib.parse import urlsplit
@@ -236,7 +236,7 @@ if __name__ == "__main__":
     print()
     with 
Path(__file__).resolve().with_name("quarantine_issue_header.md").open() as f:
         header = jinja2.Template(f.read(), autoescape=True, 
undefined=StrictUndefined).render(
-            DATE_UTC_NOW=datetime.utcnow()
+            DATE_UTC_NOW=datetime.now(tz=timezone.utc).isoformat("T", 
timespec="seconds")
         )
     quarantined_issue.edit(
         title=None, body=f"{header}\n\n{table}", state="open" if test_results 
else "closed"

Reply via email to