Skip to content

Commit

Permalink
Remove Python 3.10 support for the controller
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrizek committed May 9, 2024
1 parent 8ad68f1 commit a5b922a
Show file tree
Hide file tree
Showing 13 changed files with 19 additions and 69 deletions.
2 changes: 0 additions & 2 deletions .azure-pipelines/azure-pipelines.yml
Expand Up @@ -157,7 +157,6 @@ stages:
nameFormat: Python {0}
testFormat: galaxy/{0}/1
targets:
- test: '3.10'
- test: 3.11
- test: 3.12
- stage: Generic
Expand All @@ -168,7 +167,6 @@ stages:
nameFormat: Python {0}
testFormat: generic/{0}/1
targets:
- test: '3.10'
- test: 3.11
- test: 3.12
- stage: Incidental_Windows
Expand Down
2 changes: 2 additions & 0 deletions changelogs/fragments/remove-python3.10-controller-support.yml
@@ -0,0 +1,2 @@
removed_features:
- Removed Python 3.10 as a supported version on the controller. Python 3.11 or newer is required.
2 changes: 1 addition & 1 deletion hacking/README.md
Expand Up @@ -5,7 +5,7 @@ env-setup
---------

The 'env-setup' script modifies your environment to allow you to run
ansible from a git checkout using python >= 3.10.
ansible from a git checkout using python >= 3.11.

First, set up your environment to run from the checkout:

Expand Down
4 changes: 2 additions & 2 deletions lib/ansible/cli/__init__.py
Expand Up @@ -11,9 +11,9 @@

# Used for determining if the system is running a new enough python version
# and should only restrict on our documented minimum versions
if sys.version_info < (3, 10):
if sys.version_info < (3, 11):
raise SystemExit(
'ERROR: Ansible requires Python 3.10 or newer on the controller. '
'ERROR: Ansible requires Python 3.11 or newer on the controller. '
'Current version: %s' % ''.join(sys.version.splitlines())
)

Expand Down
3 changes: 1 addition & 2 deletions lib/ansible/galaxy/api.py
Expand Up @@ -62,8 +62,7 @@ def should_retry_error(exception):
if isinstance(orig_exc, URLError):
orig_exc = orig_exc.reason

# Handle common URL related errors such as TimeoutError, and BadStatusLine
# Note: socket.timeout is only required for Py3.9
# Handle common URL related errors
if isinstance(orig_exc, (TimeoutError, BadStatusLine, IncompleteRead)):
return True

Expand Down
7 changes: 0 additions & 7 deletions lib/ansible/galaxy/collection/__init__.py
Expand Up @@ -1584,13 +1584,6 @@ def install_artifact(b_coll_targz_path, b_collection_path, b_temp_path, signatur
"""
try:
with tarfile.open(b_coll_targz_path, mode='r') as collection_tar:
# Remove this once py3.11 is our controller minimum
# Workaround for https://bugs.python.org/issue47231
# See _extract_tar_dir
collection_tar._ansible_normalized_cache = {
m.name.removesuffix(os.path.sep): m for m in collection_tar.getmembers()
} # deprecated: description='TarFile member index' core_version='2.18' python_version='3.11'

# Verify the signature on the MANIFEST.json before extracting anything else
_extract_tar_file(collection_tar, MANIFEST_FILENAME, b_collection_path, b_temp_path)

Expand Down
44 changes: 3 additions & 41 deletions lib/ansible/utils/collection_loader/_collection_finder.py
Expand Up @@ -32,27 +32,8 @@ def import_module(name): # type: ignore[misc]
__import__(name)
return sys.modules[name]

try:
from importlib import reload as reload_module
except ImportError:
# 2.7 has a global reload function instead...
reload_module = reload # type: ignore[name-defined] # pylint:disable=undefined-variable

try:
try:
# Available on Python >= 3.11
# We ignore the import error that will trigger when running mypy with
# older Python versions.
from importlib.resources.abc import TraversableResources # type: ignore[import]
except ImportError:
# Used with Python 3.9 and 3.10 only
# This member is still available as an alias up until Python 3.14 but
# is deprecated as of Python 3.12.
from importlib.abc import TraversableResources # deprecated: description='TraversableResources move' python_version='3.10'
except ImportError:
# Python < 3.9
# deprecated: description='TraversableResources fallback' python_version='3.8'
TraversableResources = object # type: ignore[assignment,misc]
from importlib import reload as reload_module
from importlib.resources.abc import TraversableResources

try:
from importlib.util import find_spec, spec_from_loader
Expand All @@ -77,26 +58,7 @@ def import_module(name): # type: ignore[misc]
except ImportError:
_meta_yml_to_dict = None


if not hasattr(__builtins__, 'ModuleNotFoundError'):
# this was introduced in Python 3.6
ModuleNotFoundError = ImportError


_VALID_IDENTIFIER_STRING_REGEX = re.compile(
''.join((_VALID_IDENTIFIER_REGEX, r'\Z')),
)


try: # NOTE: py3/py2 compat
# py2 mypy can't deal with try/excepts
is_python_identifier = str.isidentifier # type: ignore[attr-defined]
except AttributeError: # Python 2
def is_python_identifier(self): # type: (str) -> bool
"""Determine whether the given string is a Python identifier."""
# Ref: https://stackoverflow.com/a/55802320/595220
return bool(re.match(_VALID_IDENTIFIER_STRING_REGEX, self))

is_python_identifier = str.isidentifier # type: ignore[attr-defined]

PB_EXTENSIONS = ('.yml', '.yaml')
SYNTHETIC_PACKAGE_NAME = '<ansible_synthetic_collection_package>'
Expand Down
5 changes: 3 additions & 2 deletions packaging/release.py
Expand Up @@ -866,8 +866,9 @@ def get_wheel_path(version: Version, dist_dir: pathlib.Path = DIST_DIR) -> pathl

def calculate_digest(path: pathlib.Path) -> str:
"""Return the digest for the specified file."""
# TODO: use hashlib.file_digest once Python 3.11 is the minimum supported version
return hashlib.new(DIGEST_ALGORITHM, path.read_bytes()).hexdigest()
with open(path, "rb") as f:
digest = hashlib.file_digest(f, DIGEST_ALGORITHM)
return digest.hexdigest()


@functools.cache
Expand Down
3 changes: 1 addition & 2 deletions setup.cfg
Expand Up @@ -27,7 +27,6 @@ classifiers =
Natural Language :: English
Operating System :: POSIX
Programming Language :: Python :: 3
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11
Programming Language :: Python :: 3.12
Programming Language :: Python :: 3 :: Only
Expand All @@ -37,7 +36,7 @@ classifiers =

[options]
zip_safe = False
python_requires = >=3.10
python_requires = >=3.11
# keep ansible-test as a verbatim script to work with editable installs, since it needs to do its
# own package redirection magic that's beyond the scope of the normal `ansible` path redirection
# done by setuptools `develop`
Expand Down
3 changes: 1 addition & 2 deletions test/lib/ansible_test/_data/requirements/constraints.txt
@@ -1,8 +1,7 @@
# do not add a cryptography or pyopenssl constraint to this file, they require special handling, see get_cryptography_requirements in python_requirements.py
# do not add a coverage constraint to this file, it is handled internally by ansible-test
pypsrp < 1.0.0 # in case the next major version is too big of a change
pywinrm >= 0.3.0 ; python_version < '3.11' # message encryption support
pywinrm >= 0.4.3 ; python_version >= '3.11' # support for Python 3.11
pywinrm >= 0.4.3 # support for Python 3.11
pytest >= 4.5.0 # pytest 4.5.0 added support for --strict-markers
ntlm-auth >= 1.3.0 # message encryption support using cryptography
requests-ntlm >= 1.1.0 # message encryption support
Expand Down
2 changes: 1 addition & 1 deletion test/lib/ansible_test/_util/target/common/constants.py
Expand Up @@ -7,10 +7,10 @@
REMOTE_ONLY_PYTHON_VERSIONS = (
'3.8',
'3.9',
'3.10',
)

CONTROLLER_PYTHON_VERSIONS = (
'3.10',
'3.11',
'3.12',
)
3 changes: 0 additions & 3 deletions test/sanity/ignore.txt
Expand Up @@ -2,13 +2,10 @@ lib/ansible/config/base.yml no-unwanted-files
lib/ansible/executor/powershell/async_watchdog.ps1 pslint:PSCustomUseLiteralPath
lib/ansible/executor/powershell/async_wrapper.ps1 pslint:PSCustomUseLiteralPath
lib/ansible/executor/powershell/exec_wrapper.ps1 pslint:PSCustomUseLiteralPath
lib/ansible/galaxy/collection/__init__.py mypy-3.10:attr-defined # inline ignore has no effect
lib/ansible/galaxy/collection/__init__.py mypy-3.11:attr-defined # inline ignore has no effect
lib/ansible/galaxy/collection/__init__.py mypy-3.12:attr-defined # inline ignore has no effect
lib/ansible/galaxy/collection/gpg.py mypy-3.10:arg-type
lib/ansible/galaxy/collection/gpg.py mypy-3.11:arg-type
lib/ansible/galaxy/collection/gpg.py mypy-3.12:arg-type
lib/ansible/parsing/yaml/constructor.py mypy-3.10:type-var # too many occurrences to ignore inline
lib/ansible/parsing/yaml/constructor.py mypy-3.11:type-var # too many occurrences to ignore inline
lib/ansible/parsing/yaml/constructor.py mypy-3.12:type-var # too many occurrences to ignore inline
lib/ansible/keyword_desc.yml no-unwanted-files
Expand Down
8 changes: 4 additions & 4 deletions test/units/requirements.txt
@@ -1,4 +1,4 @@
bcrypt ; python_version >= '3.10' # controller only
passlib ; python_version >= '3.10' # controller only
pexpect ; python_version >= '3.10' # controller only
pywinrm ; python_version >= '3.10' # controller only
bcrypt ; python_version >= '3.11' # controller only
passlib ; python_version >= '3.11' # controller only
pexpect ; python_version >= '3.11' # controller only
pywinrm ; python_version >= '3.11' # controller only

0 comments on commit a5b922a

Please sign in to comment.