Skip to content

Commit

Permalink
remove support for building ansible < 6.0.0 (#477)
Browse files Browse the repository at this point in the history
* ansible setup.py: Remove code for old versions

Relates: #472

* remove other code for < ansible 6

* error when trying to build an unsupported version
  • Loading branch information
gotmax23 authored May 5, 2023
1 parent 5f9b83d commit fe1f294
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 155 deletions.
7 changes: 7 additions & 0 deletions changelogs/fragments/477-setup_py.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
removed_features:
- Remove code to build ansible versions < 6.0.0 from the ``setup.py``
template and elsewhere in the codebase.
``antsibull-build`` will error out if a user attempts to build
an unsupported version
(https://github.com/ansible-community/antsibull/pull/477).
13 changes: 3 additions & 10 deletions src/antsibull/build_ansible_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,6 @@ def _extract_python_requires(ansible_core_version: PypiVer, deps: dict[str, str]
python_requires = deps.pop('_python', None)
if python_requires is not None:
return python_requires
if ansible_core_version < PypiVer('2.12.0a'):
# Ansible 2.9, ansible-base 2.10, and ansible-core 2.11 support Python 2.7 and Python 3.5+
return '>=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*'
if ansible_core_version < PypiVer('2.14.0a'):
# ansible-core 2.12 and 2.13 support Python 3.8+
return '>=3.8'
Expand Down Expand Up @@ -594,9 +591,8 @@ def rebuild_single_command() -> int:
# Write the ansible release info to the collections dir
write_release_py(app_ctx.extra['ansible_version'], ansible_collections_dir)

# Write the ansible-community CLI program (starting with Ansible 6.0.0rc1)
if app_ctx.extra['ansible_version'] >= PypiVer('6.0.0rc1'):
write_ansible_community_py(app_ctx.extra['ansible_version'], ansible_collections_dir)
# Write the ansible-community CLI program
write_ansible_community_py(app_ctx.extra['ansible_version'], ansible_collections_dir)

# Install collections
collections_to_install = [p for f in os.listdir(download_dir)
Expand Down Expand Up @@ -652,10 +648,7 @@ def rebuild_single_command() -> int:
return 3

# Create source distribution
if app_ctx.extra["ansible_version"].major < 6:
make_dist(package_dir, app_ctx.extra['sdist_dir'])
else:
make_dist_with_wheels(package_dir, app_ctx.extra['sdist_dir'])
make_dist_with_wheels(package_dir, app_ctx.extra['sdist_dir'])

return 0

Expand Down
9 changes: 8 additions & 1 deletion src/antsibull/cli/antsibull_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
prepare_command, build_single_command, build_multiple_command, rebuild_single_command,
)
from ..build_changelog import build_changelog # noqa: E402
from ..constants import MINIMUM_ANSIBLE_VERSION # noqa: E402
from ..dep_closure import validate_dependencies_command # noqa: E402
from ..new_ansible import new_ansible_command # noqa: E402
from ..tagging import validate_tags_command, validate_tags_file_command # noqa: E402
Expand Down Expand Up @@ -66,9 +67,15 @@ def _normalize_commands(args: argparse.Namespace) -> None: # pylint: disable=un


def _normalize_build_options(args: argparse.Namespace) -> None:
if args.command in ('validate-deps', 'validate-tags', 'validate-tags-file'):
if args.command in ('validate-deps', 'validate-tags-file'):
return

if args.ansible_version < MINIMUM_ANSIBLE_VERSION:
raise InvalidArgumentError(
f'Ansible < {MINIMUM_ANSIBLE_VERSION} is not supported'
' by this antsibull version.'
)

if not os.path.isdir(args.data_dir):
raise InvalidArgumentError(f'{args.data_dir} must be an existing directory')

Expand Down
14 changes: 14 additions & 0 deletions src/antsibull/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright (C) 2023 Maxwell G <maxwell@gtmx.me>
# SPDX-License-Identifier: GPL-3.0-or-later
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or
# https://www.gnu.org/licenses/gpl-3.0.txt)

"""
Constants used throughout the antsibull codebase
"""

from __future__ import annotations

from packaging.version import Version as PypiVer

MINIMUM_ANSIBLE_VERSION = PypiVer('6.0.0')
144 changes: 0 additions & 144 deletions src/antsibull/data/ansible-setup_py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -11,148 +11,6 @@ from setuptools import setup, find_namespace_packages
from setuptools import setup
{%- endif %}

{%- if version.major < 6 %}

def detect_bad_upgrade():
# prevent direct upgrade from 2.9.x or earlier to 2.10 due to pip limitations
try:
import ansible
except ImportError:
# ansible is not installed
return False

try:
current_version = ansible.__version__.split('.')
current_filename = ansible.__file__
except AttributeError:
# ansible is installed but already broken. We're probably being reinstalled.
return False

try:
current_version = (int(current_version[0]), int(current_version[1]))
except Exception as e:
print("""\n
### ERROR ###
The currently installed ansible found at:
{0}
{%- if ansible_core_package_name == 'ansible-core' %}
is of an unknown version. Since upgrading directly from ansible-2.x, ansible-3, or
ansible-base to ansible-4 or newer with pip is known to cause problems, please uninstall
the old version and install the new version:
pip uninstall ansible # if installed
pip uninstall ansible-base # if installed
pip install ansible
{%- else %}
is of an unknown version. Since upgrading directly from ansible-2.9 or less to
ansible-2.10 with pip is known to cause problems, please uninstall the old version and
install the new version:
pip uninstall ansible
pip install ansible
{%- endif %}
If you have a broken installation, perhaps because {{ ansible_core_package_name }} was installed before
ansible was upgraded, try this to resolve it:
pip install --force-reinstall ansible {{ ansible_core_package_name }}
If ansible is installed in a different location than you will be installing it now
(for example, if the old version is installed by a system package manager to
/usr/lib/python3.8/site-packages/ansible but you are installing the new version into
~/.local/lib/python3.8/site-packages/ansible with `pip install --user ansible`)
or you want to install anyways and cleanup any breakage afterwards, then you may set
the ANSIBLE_SKIP_CONFLICT_CHECK environment variable to ignore this check:
ANSIBLE_SKIP_CONFLICT_CHECK=1 pip install --user ansible
### END ERROR ###
""".format(current_filename))
else:
{%- if ansible_core_package_name == 'ansible-core' %}
if current_version >= (2, 11):
return False

if current_version == (2, 10):
print("""\n
### ERROR ###
Upgrading directly from ansible-2.10, ansible-3, or ansible-base-2.10 to ansible-4
or greater with pip is known to cause problems. Please uninstall the old version found at:
{0}
and install the new version:
pip uninstall ansible # if installed
pip uninstall ansible-base # if installed
pip install ansible
If you have a broken installation, perhaps because {{ ansible_core_package_name }} was installed before
ansible was upgraded, try this to resolve it:
pip install --force-reinstall ansible {{ ansible_core_package_name }}
If ansible is installed in a different location than you will be installing it now
(for example, if the old version is installed by a system package manager to
/usr/lib/python3.8/site-packages/ansible but you are installing the new version into
~/.local/lib/python3.8/site-packages/ansible with `pip install --user ansible`)
or you want to install anyways and cleanup any breakage afterwards, then you may set
the ANSIBLE_SKIP_CONFLICT_CHECK environment variable to ignore this check:
ANSIBLE_SKIP_CONFLICT_CHECK=1 pip install --user ansible
### END ERROR ###
""".format(current_filename))
{%- else %}
if current_version >= (2, 10):
return False
{%- endif %}

print("""\n
### ERROR ###
Upgrading directly from ansible-2.9 or less to ansible-2.10 or greater with pip is
known to cause problems. Please uninstall the old version found at:
{0}
and install the new version:
pip uninstall ansible
pip install ansible
If you have a broken installation, perhaps because {{ ansible_core_package_name }} was installed before
ansible was upgraded, try this to resolve it:
pip install --force-reinstall ansible {{ ansible_core_package_name }}
If ansible is installed in a different location than you will be installing it now
(for example, if the old version is installed by a system package manager to
/usr/lib/python3.8/site-packages/ansible but you are installing the new version into
~/.local/lib/python3.8/site-packages/ansible with `pip install --user ansible`)
or you want to install anyways and cleanup any breakage afterwards, then you may set
the ANSIBLE_SKIP_CONFLICT_CHECK environment variable to ignore this check:
ANSIBLE_SKIP_CONFLICT_CHECK=1 pip install --user ansible
### END ERROR ###
""".format(current_filename))

return True


if not os.environ.get('ANSIBLE_SKIP_CONFLICT_CHECK'):
if detect_bad_upgrade():
sys.exit(1)

{%- endif %}

__version__ = '{{ version }}'
__author__ = 'Ansible, Inc.'
Expand Down Expand Up @@ -252,13 +110,11 @@ setup(
'Topic :: Utilities',
],
data_files=[],
{%- if version >= PypiVer('6.0.0rc1') %}
entry_points={
'console_scripts': [
'ansible-community=ansible_collections.ansible_community:main'
]
},
{%- endif %}
# Installing as zip files would break due to references to __file__
zip_safe=False
)

0 comments on commit fe1f294

Please sign in to comment.