mirror of
https://github.com/ansible/awx.git
synced 2026-04-07 02:59:21 -02:30
AAP-59874: Update to Python 3.12 (#16208)
* update to Python 3.12 * remove use of utcnow * switch to timezone.utc datetime.UTC is an alias of datetime.timezone.utc. if we're doing the double import for datetime it's more straightforward to just import timezone as well and get it directly * debug python env version issue * change python version * pin to SHA and remove debug portion
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
import json
|
||||
|
||||
from awxkit.utils import poll_until
|
||||
@@ -35,10 +35,10 @@ class HasStatus(object):
|
||||
return self
|
||||
|
||||
def wait_until_completed(self, interval=5, timeout=60, **kwargs):
|
||||
start_time = datetime.utcnow()
|
||||
start_time = datetime.now(timezone.utc)
|
||||
HasStatus.wait_until_status(self, self.completed_statuses, interval=interval, timeout=timeout, **kwargs)
|
||||
if not getattr(self, 'event_processing_finished', True):
|
||||
elapsed = datetime.utcnow() - start_time
|
||||
elapsed = datetime.now(timezone.utc) - start_time
|
||||
time_left = timeout - elapsed.total_seconds()
|
||||
poll_until(lambda: getattr(self.get(), 'event_processing_finished', True), interval=interval, timeout=time_left, **kwargs)
|
||||
return self
|
||||
@@ -92,7 +92,7 @@ class HasStatus(object):
|
||||
except Exception as e:
|
||||
msg += '\nFailed to obtain dependency stdout: {}'.format(e)
|
||||
|
||||
msg += '\nTIME WHEN STATUS WAS FOUND: {} (UTC)\n'.format(datetime.utcnow())
|
||||
msg += '\nTIME WHEN STATUS WAS FOUND: {} (UTC)\n'.format(datetime.now(timezone.utc))
|
||||
|
||||
raise AssertionError(msg)
|
||||
|
||||
|
||||
@@ -1,5 +1,15 @@
|
||||
from distutils.version import LooseVersion
|
||||
from packaging.version import Version
|
||||
|
||||
|
||||
def version_cmp(x, y):
|
||||
return LooseVersion(x)._cmp(y)
|
||||
"""Compare two version strings.
|
||||
Returns -1 if x < y, 0 if x == y, 1 if x > y
|
||||
"""
|
||||
vx = Version(x)
|
||||
vy = Version(y)
|
||||
if vx < vy:
|
||||
return -1
|
||||
elif vx > vy:
|
||||
return 1
|
||||
else:
|
||||
return 0
|
||||
|
||||
@@ -1,13 +1,29 @@
|
||||
import locale
|
||||
import json
|
||||
from distutils.util import strtobool
|
||||
|
||||
import yaml
|
||||
|
||||
from awxkit.cli.utils import colored
|
||||
from awxkit import config
|
||||
|
||||
|
||||
def strtobool(val):
|
||||
"""Convert a string representation of truth to true (1) or false (0).
|
||||
|
||||
True values are 'y', 'yes', 't', 'true', 'on', and '1'.
|
||||
False values are 'n', 'no', 'f', 'false', 'off', and '0'.
|
||||
Raises ValueError if 'val' is anything else.
|
||||
|
||||
This replaces the deprecated distutils.util.strtobool removed in Python 3.12.
|
||||
"""
|
||||
val = val.lower()
|
||||
if val in ('y', 'yes', 't', 'true', 'on', '1'):
|
||||
return 1
|
||||
elif val in ('n', 'no', 'f', 'false', 'off', '0'):
|
||||
return 0
|
||||
else:
|
||||
raise ValueError(f"invalid truth value {val!r}")
|
||||
|
||||
|
||||
def get_config_credentials():
|
||||
"""Load username and password from config.credentials.default.
|
||||
|
||||
|
||||
@@ -6,10 +6,8 @@ import re
|
||||
import sys
|
||||
import yaml
|
||||
|
||||
from distutils.util import strtobool
|
||||
|
||||
from .custom import CustomAction
|
||||
from .format import add_output_formatting_arguments
|
||||
from .format import add_output_formatting_arguments, strtobool
|
||||
from .resource import DEPRECATED_RESOURCES_REVERSE
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from datetime import datetime, timedelta, tzinfo
|
||||
from datetime import datetime, timedelta, tzinfo, timezone
|
||||
import inspect
|
||||
import logging
|
||||
import random
|
||||
@@ -364,7 +364,7 @@ def are_same_endpoint(first, second):
|
||||
|
||||
def utcnow():
|
||||
"""Provide a wrapped copy of the built-in utcnow that can be easily mocked."""
|
||||
return datetime.utcnow()
|
||||
return datetime.now(timezone.utc)
|
||||
|
||||
|
||||
class UTC(tzinfo):
|
||||
|
||||
@@ -205,7 +205,7 @@ class WSClient(object):
|
||||
message = json.loads(message)
|
||||
log.debug('received message: {}'.format(message))
|
||||
if self._add_received_time:
|
||||
message['received_time'] = datetime.datetime.utcnow()
|
||||
message['received_time'] = datetime.datetime.now(datetime.UTC)
|
||||
|
||||
if all([message.get('group_name') == 'jobs', message.get('status') == 'pending', message.get('unified_job_id'), self._should_subscribe_to_pending_job]):
|
||||
if bool(message.get('project_id')) == (self._should_subscribe_to_pending_job['events'] == 'project_update_events'):
|
||||
|
||||
@@ -92,7 +92,7 @@ setup(
|
||||
'requests',
|
||||
'setuptools',
|
||||
],
|
||||
python_requires=">=3.8",
|
||||
python_requires=">=3.12",
|
||||
extras_require={'formatting': ['jq'], 'websockets': ['websocket-client==0.57.0'], 'crypto': ['cryptography']},
|
||||
license='Apache 2.0',
|
||||
classifiers=[
|
||||
@@ -104,7 +104,7 @@ setup(
|
||||
'Operating System :: MacOS :: MacOS X',
|
||||
'Operating System :: POSIX :: Linux',
|
||||
'Programming Language :: Python',
|
||||
'Programming Language :: Python :: 3.8',
|
||||
'Programming Language :: Python :: 3.12',
|
||||
'Topic :: System :: Software Distribution',
|
||||
'Topic :: System :: Systems Administration',
|
||||
],
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
import sys
|
||||
|
||||
from unittest import mock
|
||||
@@ -379,7 +379,7 @@ class TestUpdatePayload(object):
|
||||
|
||||
|
||||
def test_to_ical():
|
||||
now = datetime.utcnow()
|
||||
now = datetime.now(timezone.utc)
|
||||
ical_datetime = utils.to_ical(now)
|
||||
date = str(now.date()).replace('-', '')
|
||||
time = str(now.time()).split('.')[0].replace(':', '')
|
||||
|
||||
@@ -8,7 +8,7 @@ skip_missing_interpreters = true
|
||||
# skipsdist = true
|
||||
|
||||
[testenv]
|
||||
basepython = python3.11
|
||||
basepython = python3.12
|
||||
setenv =
|
||||
PYTHONPATH = {toxinidir}:{env:PYTHONPATH:}:.
|
||||
deps =
|
||||
|
||||
Reference in New Issue
Block a user