Skip to content

Commit

Permalink
Avoid datetime deprecations in releaseWizard.py (#751)
Browse files Browse the repository at this point in the history
Python 3.12 deprecates two popular datetime functions that are used
throughout the Release Wizard, 'utcnow()' and 'utcfromtimestamp()',
resulting in many distracting messages that make the other wizard output
hard to read, e.g.

```
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).
```

This commit updates our 'datetime' usage in accordance with the Python
recommendations.
  • Loading branch information
gerlowskija authored Jan 24, 2025
1 parent 47446f0 commit f55725f
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions hack/release/wizard/releaseWizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
from collections import OrderedDict
from datetime import datetime
from datetime import timedelta
from datetime import timezone

try:
import holidays
Expand Down Expand Up @@ -97,7 +98,7 @@ def expand_jinja(text, vars=None):
'state': state,
'gpg_key': state.get_gpg_key(),
'gpg_fingerprint': state.get_gpg_fingerprint(),
'epoch': unix_time_millis(datetime.utcnow()),
'epoch': unix_time_millis(datetime.now(timezone.utc)),
'get_next_version': state.get_next_version(),
'get_next_major_version': state.get_next_major_version(),
'get_next_minor_version': state.get_next_minor_version(),
Expand Down Expand Up @@ -201,7 +202,7 @@ def check_prerequisites(todo=None):
return True


epoch = datetime.utcfromtimestamp(0)
epoch = datetime.fromtimestamp(0, timezone.utc)


def unix_time_millis(dt):
Expand Down Expand Up @@ -295,7 +296,7 @@ def __init__(self, config_path, release_version, script_version):
self.latest_version = None
self.previous_rcs = {}
self.rc_number = 1
self.start_date = unix_time_millis(datetime.utcnow())
self.start_date = unix_time_millis(datetime.now(timezone.utc))
self.script_branch = run("git rev-parse --abbrev-ref HEAD").strip()
self.released_versions = None
try:
Expand Down Expand Up @@ -771,7 +772,7 @@ def get_vars(self):

def set_done(self, is_done):
if is_done:
self.state['done_date'] = unix_time_millis(datetime.utcnow())
self.state['done_date'] = unix_time_millis(datetime.now(timezone.utc))
if self.persist_vars:
for k in self.persist_vars:
self.state[k] = self.get_vars()[k]
Expand Down Expand Up @@ -966,21 +967,21 @@ def expand_multiline(cmd_txt, indent=0):


def unix_to_datetime(unix_stamp):
return datetime.utcfromtimestamp(unix_stamp / 1000)
return datetime.fromtimestamp(unix_stamp / 1000, timezone.utc)


def generate_asciidoc():
base_filename = os.path.join(state.get_release_folder(),
"solr_operator_release_%s"
% (state.release_version.replace("\.", "_")))
% (state.release_version.replace(".", "_")))

filename_adoc = "%s.adoc" % base_filename
filename_html = "%s.html" % base_filename
fh = open(filename_adoc, "w")

fh.write("= Solr Operator Release %s\n\n" % state.release_version)
fh.write("(_Generated by releaseWizard.py %s at %s_)\n\n"
% (getScriptVersion(), datetime.utcnow().strftime("%Y-%m-%d %H:%M UTC")))
% (getScriptVersion(), datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M UTC")))
fh.write(":numbered:\n\n")
fh.write("%s\n\n" % template('help'))
for group in state.todo_groups:
Expand Down Expand Up @@ -1895,17 +1896,17 @@ def create_ical(todo):
return True


today = datetime.utcnow().date()
today = datetime.now(timezone.utc).date()
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(timezone.utc).year
years = [y, y+1]
non_working = holidays.CA(years=years) + holidays.US(years=years) + holidays.UK(years=years) \
+ holidays.DE(years=years) + holidays.NO(years=years) + holidays.IND(years=years) + holidays.RU(years=years)


def vote_close_72h_date():
# Voting open at least 72 hours according to ASF policy
return datetime.utcnow() + timedelta(hours=73)
return datetime.now(timezone.utc) + timedelta(hours=73)


def vote_close_72h_holidays():
Expand Down

0 comments on commit f55725f

Please sign in to comment.