Updated releaseWizard.py to use timezone-aware objects to represent datetimes in UTC (#14102)

Co-authored-by: Shubham Sharma <shubhamvibrantiit@gmail.com>
This commit is contained in:
Shubham Sharma 2025-01-09 14:23:54 +05:30 committed by GitHub
parent 0169c1efea
commit 3fad719337
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 10 additions and 9 deletions

View File

@ -49,6 +49,7 @@ import urllib
from collections import OrderedDict from collections import OrderedDict
from datetime import datetime from datetime import datetime
from datetime import timedelta from datetime import timedelta
from datetime import timezone
try: try:
import holidays import holidays
@ -99,7 +100,7 @@ def expand_jinja(text, vars=None):
'state': state, 'state': state,
'gpg_key' : state.get_gpg_key(), 'gpg_key' : state.get_gpg_key(),
'gradle_cmd' : 'gradlew.bat' if is_windows() else './gradlew', 'gradle_cmd' : 'gradlew.bat' if is_windows() else './gradlew',
'epoch': unix_time_millis(datetime.utcnow()), 'epoch': unix_time_millis(datetime.now(tz=timezone.utc)),
'get_next_version': state.get_next_version(), 'get_next_version': state.get_next_version(),
'current_git_rev': state.get_current_git_rev(), 'current_git_rev': state.get_current_git_rev(),
'keys_downloaded': keys_downloaded(), 'keys_downloaded': keys_downloaded(),
@ -199,7 +200,7 @@ def check_prerequisites(todo=None):
return True return True
epoch = datetime.utcfromtimestamp(0) epoch = datetime.fromtimestamp(timestamp=0, tz=timezone.utc)
def unix_time_millis(dt): def unix_time_millis(dt):
@ -279,7 +280,7 @@ class ReleaseState:
self.latest_version = None self.latest_version = None
self.previous_rcs = {} self.previous_rcs = {}
self.rc_number = 1 self.rc_number = 1
self.start_date = unix_time_millis(datetime.utcnow()) self.start_date = unix_time_millis(datetime.now(tz=timezone.utc))
self.script_branch = run("git rev-parse --abbrev-ref HEAD").strip() self.script_branch = run("git rev-parse --abbrev-ref HEAD").strip()
self.mirrored_versions = None self.mirrored_versions = None
try: try:
@ -741,7 +742,7 @@ class Todo(SecretYamlObject):
def set_done(self, is_done): def set_done(self, is_done):
if is_done: if is_done:
self.state['done_date'] = unix_time_millis(datetime.utcnow()) self.state['done_date'] = unix_time_millis(datetime.now(tz=timezone.utc))
if self.persist_vars: if self.persist_vars:
for k in self.persist_vars: for k in self.persist_vars:
self.state[k] = self.get_vars()[k] self.state[k] = self.get_vars()[k]
@ -935,7 +936,7 @@ def expand_multiline(cmd_txt, indent=0):
def unix_to_datetime(unix_stamp): def unix_to_datetime(unix_stamp):
return datetime.utcfromtimestamp(unix_stamp / 1000) return datetime.fromtimestamp(timestamp=unix_stamp / 1000, tz=timezone.utc)
def generate_asciidoc(): def generate_asciidoc():
@ -949,7 +950,7 @@ def generate_asciidoc():
fh.write("= Lucene Release %s\n\n" % state.release_version) fh.write("= Lucene Release %s\n\n" % state.release_version)
fh.write("(_Generated by releaseWizard.py v%s at %s_)\n\n" fh.write("(_Generated by releaseWizard.py v%s at %s_)\n\n"
% (getScriptVersion(), datetime.utcnow().strftime("%Y-%m-%d %H:%M UTC"))) % (getScriptVersion(), datetime.now(tz=timezone.utc).strftime("%Y-%m-%d %H:%M UTC")))
fh.write(":numbered:\n\n") fh.write(":numbered:\n\n")
fh.write("%s\n\n" % template('help')) fh.write("%s\n\n" % template('help'))
for group in state.todo_groups: for group in state.todo_groups:
@ -1839,9 +1840,9 @@ def create_ical(todo): # pylint: disable=unused-argument
return True return True
today = datetime.utcnow().date() today = datetime.now(tz=timezone.utc).date()
sundays = {(today + timedelta(days=x)): 'Sunday' for x in range(10) if (today + timedelta(days=x)).weekday() == 6} sundays = {(today + timedelta(days=x)): 'Sunday' for x in range(10) if (today + timedelta(days=x)).weekday() == 6}
y = datetime.utcnow().year y = datetime.now(tz=timezone.utc).year
years = [y, y+1] years = [y, y+1]
non_working = holidays.CA(years=years) + holidays.US(years=years) + holidays.UK(years=years) \ non_working = holidays.CA(years=years) + holidays.US(years=years) + holidays.UK(years=years) \
+ holidays.DE(years=years) + holidays.NO(years=years) + holidays.IN(years=years) + holidays.RU(years=years) + holidays.DE(years=years) + holidays.NO(years=years) + holidays.IN(years=years) + holidays.RU(years=years)
@ -1849,7 +1850,7 @@ non_working = holidays.CA(years=years) + holidays.US(years=years) + holidays.UK(
def vote_close_72h_date(): def vote_close_72h_date():
# Voting open at least 72 hours according to ASF policy # Voting open at least 72 hours according to ASF policy
return datetime.utcnow() + timedelta(hours=73) return datetime.now(tz=timezone.utc) + timedelta(hours=73)
def vote_close_72h_holidays(): def vote_close_72h_holidays():