* Fix building Ansible dist w/ setuptools>=48,<49.1 (#70525) * Fix building Ansible dist w/ setuptools>=48,<49.1 This change addresses the deprecation of the use of stdlib `distutils`. It's a short-term hotfix for the problem and we'll need to consider dropping the use of `distutils` from our `setup.py`. Refs: * https://github.com/ansible/ansible/issues/70456 * https://github.com/pypa/setuptools/issues/2230 * https://github.com/pypa/setuptools/commit/bd110264 Co-Authored-By: Jason R. Coombs <jaraco@jaraco.com> * Add a change note for PR #70525 Co-authored-by: Jason R. Coombs <jaraco@jaraco.com> (cherry picked from commit918388b85f
) * Guard against allowing ansible to ansible-base upgrades (#70529) * Guard against allowing ansible to ansible-base upgrades * newline * use alias * Add an explicit line detailing this is a 1 time thing * period * Read __version__ and __author__ rather than import, update working, and add ability to skip conflict checks * Remove commented code * Re introduce removed changes from rebase * Just use open * Nuke unused import (cherry picked from commit54b002e1ac
) Co-authored-by: Sviatoslav Sydorenko <webknjaz@redhat.com>
This commit is contained in:
parent
ffd3757fc3
commit
448f17e9a5
2 changed files with 93 additions and 4 deletions
|
@ -0,0 +1,7 @@
|
|||
bugfixes:
|
||||
- >
|
||||
Address the deprecation of the use of stdlib
|
||||
distutils in packaging. It's a short-term hotfix for the problem
|
||||
(https://github.com/ansible/ansible/issues/70456,
|
||||
https://github.com/pypa/setuptools/issues/2230,
|
||||
https://github.com/pypa/setuptools/commit/bd110264)
|
90
setup.py
90
setup.py
|
@ -9,8 +9,6 @@ import sys
|
|||
import warnings
|
||||
|
||||
from collections import defaultdict
|
||||
from distutils.command.build_scripts import build_scripts as BuildScripts
|
||||
from distutils.command.sdist import sdist as SDist
|
||||
|
||||
try:
|
||||
from setuptools import setup, find_packages
|
||||
|
@ -23,8 +21,90 @@ except ImportError:
|
|||
" install setuptools).", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
sys.path.insert(0, os.path.abspath('lib'))
|
||||
from ansible.release import __version__, __author__
|
||||
# `distutils` must be imported after `setuptools` or it will cause explosions
|
||||
# with `setuptools >=48.0.0, <49.1`.
|
||||
# Refs:
|
||||
# * https://github.com/ansible/ansible/issues/70456
|
||||
# * https://github.com/pypa/setuptools/issues/2230
|
||||
# * https://github.com/pypa/setuptools/commit/bd110264
|
||||
from distutils.command.build_scripts import build_scripts as BuildScripts
|
||||
from distutils.command.sdist import sdist as SDist
|
||||
|
||||
|
||||
def find_package_info(*file_paths):
|
||||
try:
|
||||
with open(os.path.join(*file_paths), 'r') as f:
|
||||
info_file = f.read()
|
||||
except Exception:
|
||||
raise RuntimeError("Unable to find package info.")
|
||||
|
||||
# The version line must have the form
|
||||
# __version__ = 'ver'
|
||||
version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]",
|
||||
info_file, re.M)
|
||||
author_match = re.search(r"^__author__ = ['\"]([^'\"]*)['\"]",
|
||||
info_file, re.M)
|
||||
|
||||
if version_match and author_match:
|
||||
return version_match.group(1), author_match.group(1)
|
||||
raise RuntimeError("Unable to find package info.")
|
||||
|
||||
|
||||
def _validate_install_ansible_base():
|
||||
"""Validate that we can install ansible-base. Currently this only
|
||||
cares about upgrading to ansible-base from ansible<2.10
|
||||
"""
|
||||
if os.getenv('ANSIBLE_SKIP_CONFLICT_CHECK', '') not in ('', '0'):
|
||||
return
|
||||
|
||||
# Save these for later restoring things to pre invocation
|
||||
sys_modules = sys.modules.copy()
|
||||
sys_modules_keys = set(sys_modules)
|
||||
|
||||
# Make sure `lib` isn't in `sys.path` that could confuse this
|
||||
sys_path = sys.path[:]
|
||||
abspath = os.path.abspath
|
||||
sys.path[:] = [p for p in sys.path if abspath(p) != abspath('lib')]
|
||||
|
||||
try:
|
||||
from ansible.release import __version__
|
||||
except ImportError:
|
||||
pass
|
||||
else:
|
||||
version_tuple = tuple(int(v) for v in __version__.split('.')[:2])
|
||||
if version_tuple < (2, 10):
|
||||
stars = '*' * 76
|
||||
raise RuntimeError(
|
||||
'''
|
||||
|
||||
%s
|
||||
|
||||
Cannot install ansible-base with a pre-existing ansible==%s
|
||||
installation.
|
||||
|
||||
Installing ansible-base with ansible-2.9 or older currently installed with
|
||||
pip is known to cause problems. Please uninstall ansible and install the new
|
||||
version:
|
||||
|
||||
pip uninstall ansible
|
||||
pip install ansible-base
|
||||
|
||||
If you want to skip the conflict checks and manually resolve any issues
|
||||
afterwards, set the ANSIBLE_SKIP_CONFLICT_CHECK environment variable:
|
||||
|
||||
ANSIBLE_SKIP_CONFLICT_CHECK=1 pip install ansible-base
|
||||
|
||||
%s
|
||||
''' % (stars, __version__, stars)
|
||||
)
|
||||
finally:
|
||||
sys.path[:] = sys_path
|
||||
for key in sys_modules_keys.symmetric_difference(sys.modules):
|
||||
sys.modules.pop(key, None)
|
||||
sys.modules.update(sys_modules)
|
||||
|
||||
|
||||
_validate_install_ansible_base()
|
||||
|
||||
|
||||
SYMLINK_CACHE = 'SYMLINK_CACHE.json'
|
||||
|
@ -247,6 +327,8 @@ def get_dynamic_setup_params():
|
|||
}
|
||||
|
||||
|
||||
here = os.path.abspath(os.path.dirname(__file__))
|
||||
__version__, __author__ = find_package_info(here, 'lib', 'ansible', 'release.py')
|
||||
static_setup_params = dict(
|
||||
# Use the distutils SDist so that symlinks are not expanded
|
||||
# Use a custom Build for the same reason
|
||||
|
|
Loading…
Reference in a new issue