diff --git a/Makefile b/Makefile index 7cdf9c60fc..34458d0377 100644 --- a/Makefile +++ b/Makefile @@ -59,6 +59,7 @@ REQUIREMENTS := test-requirements.txt requirements.txt PIP_VERSION ?= 20.3.3 SETUPTOOLS_VERSION ?= 51.3.3 PIP_OPTIONS := $(ST2_PIP_OPTIONS) +PACKAGING_VERSION ?= 23.1 ifndef PYLINT_CONCURRENCY PYLINT_CONCURRENCY := 1 @@ -662,6 +663,7 @@ distclean: clean .PHONY: .requirements .requirements: virtualenv $(VIRTUALENV_DIR)/bin/pip install --upgrade "pip==$(PIP_VERSION)" + $(VIRTUALENV_DIR)/bin/pip install --upgrade "PACKAGING_VERSION==$(PACKAGING_VERSION)" # Print out pip version $(VIRTUALENV_DIR)/bin/pip --version # Generate all requirements to support current CI pipeline. diff --git a/contrib/runners/action_chain_runner/dist_utils.py b/contrib/runners/action_chain_runner/dist_utils.py index a4e9862d2b..fa752580a2 100644 --- a/contrib/runners/action_chain_runner/dist_utils.py +++ b/contrib/runners/action_chain_runner/dist_utils.py @@ -24,8 +24,6 @@ import re import sys -from distutils.version import StrictVersion - # NOTE: This script can't rely on any 3rd party dependency so we need to use this code here # # TODO: Why can't this script rely on 3rd party dependencies? Is it because it has to import @@ -48,8 +46,6 @@ GET_PIP = "curl https://bootstrap.pypa.io/get-pip.py | python" __all__ = [ - "check_pip_is_installed", - "check_pip_version", "fetch_requirements", "apply_vagrant_workaround", "get_version_string", @@ -57,41 +53,6 @@ ] -def check_pip_is_installed(): - """ - Ensure that pip is installed. - """ - try: - import pip # NOQA - except ImportError as e: - print("Failed to import pip: %s" % (text_type(e))) - print("") - print("Download pip:\n%s" % (GET_PIP)) - sys.exit(1) - - return True - - -def check_pip_version(min_version="6.0.0"): - """ - Ensure that a minimum supported version of pip is installed. - """ - check_pip_is_installed() - - import pip - - if StrictVersion(pip.__version__) < StrictVersion(min_version): - print( - "Upgrade pip, your version '{0}' " - "is outdated. Minimum required version is '{1}':\n{2}".format( - pip.__version__, min_version, GET_PIP - ) - ) - sys.exit(1) - - return True - - def fetch_requirements(requirements_file_path): """ Return a list of requirements and links by parsing the provided requirements file. diff --git a/contrib/runners/announcement_runner/dist_utils.py b/contrib/runners/announcement_runner/dist_utils.py index a4e9862d2b..fa752580a2 100644 --- a/contrib/runners/announcement_runner/dist_utils.py +++ b/contrib/runners/announcement_runner/dist_utils.py @@ -24,8 +24,6 @@ import re import sys -from distutils.version import StrictVersion - # NOTE: This script can't rely on any 3rd party dependency so we need to use this code here # # TODO: Why can't this script rely on 3rd party dependencies? Is it because it has to import @@ -48,8 +46,6 @@ GET_PIP = "curl https://bootstrap.pypa.io/get-pip.py | python" __all__ = [ - "check_pip_is_installed", - "check_pip_version", "fetch_requirements", "apply_vagrant_workaround", "get_version_string", @@ -57,41 +53,6 @@ ] -def check_pip_is_installed(): - """ - Ensure that pip is installed. - """ - try: - import pip # NOQA - except ImportError as e: - print("Failed to import pip: %s" % (text_type(e))) - print("") - print("Download pip:\n%s" % (GET_PIP)) - sys.exit(1) - - return True - - -def check_pip_version(min_version="6.0.0"): - """ - Ensure that a minimum supported version of pip is installed. - """ - check_pip_is_installed() - - import pip - - if StrictVersion(pip.__version__) < StrictVersion(min_version): - print( - "Upgrade pip, your version '{0}' " - "is outdated. Minimum required version is '{1}':\n{2}".format( - pip.__version__, min_version, GET_PIP - ) - ) - sys.exit(1) - - return True - - def fetch_requirements(requirements_file_path): """ Return a list of requirements and links by parsing the provided requirements file. diff --git a/contrib/runners/http_runner/dist_utils.py b/contrib/runners/http_runner/dist_utils.py index a4e9862d2b..fa752580a2 100644 --- a/contrib/runners/http_runner/dist_utils.py +++ b/contrib/runners/http_runner/dist_utils.py @@ -24,8 +24,6 @@ import re import sys -from distutils.version import StrictVersion - # NOTE: This script can't rely on any 3rd party dependency so we need to use this code here # # TODO: Why can't this script rely on 3rd party dependencies? Is it because it has to import @@ -48,8 +46,6 @@ GET_PIP = "curl https://bootstrap.pypa.io/get-pip.py | python" __all__ = [ - "check_pip_is_installed", - "check_pip_version", "fetch_requirements", "apply_vagrant_workaround", "get_version_string", @@ -57,41 +53,6 @@ ] -def check_pip_is_installed(): - """ - Ensure that pip is installed. - """ - try: - import pip # NOQA - except ImportError as e: - print("Failed to import pip: %s" % (text_type(e))) - print("") - print("Download pip:\n%s" % (GET_PIP)) - sys.exit(1) - - return True - - -def check_pip_version(min_version="6.0.0"): - """ - Ensure that a minimum supported version of pip is installed. - """ - check_pip_is_installed() - - import pip - - if StrictVersion(pip.__version__) < StrictVersion(min_version): - print( - "Upgrade pip, your version '{0}' " - "is outdated. Minimum required version is '{1}':\n{2}".format( - pip.__version__, min_version, GET_PIP - ) - ) - sys.exit(1) - - return True - - def fetch_requirements(requirements_file_path): """ Return a list of requirements and links by parsing the provided requirements file. diff --git a/contrib/runners/inquirer_runner/dist_utils.py b/contrib/runners/inquirer_runner/dist_utils.py index a4e9862d2b..fa752580a2 100644 --- a/contrib/runners/inquirer_runner/dist_utils.py +++ b/contrib/runners/inquirer_runner/dist_utils.py @@ -24,8 +24,6 @@ import re import sys -from distutils.version import StrictVersion - # NOTE: This script can't rely on any 3rd party dependency so we need to use this code here # # TODO: Why can't this script rely on 3rd party dependencies? Is it because it has to import @@ -48,8 +46,6 @@ GET_PIP = "curl https://bootstrap.pypa.io/get-pip.py | python" __all__ = [ - "check_pip_is_installed", - "check_pip_version", "fetch_requirements", "apply_vagrant_workaround", "get_version_string", @@ -57,41 +53,6 @@ ] -def check_pip_is_installed(): - """ - Ensure that pip is installed. - """ - try: - import pip # NOQA - except ImportError as e: - print("Failed to import pip: %s" % (text_type(e))) - print("") - print("Download pip:\n%s" % (GET_PIP)) - sys.exit(1) - - return True - - -def check_pip_version(min_version="6.0.0"): - """ - Ensure that a minimum supported version of pip is installed. - """ - check_pip_is_installed() - - import pip - - if StrictVersion(pip.__version__) < StrictVersion(min_version): - print( - "Upgrade pip, your version '{0}' " - "is outdated. Minimum required version is '{1}':\n{2}".format( - pip.__version__, min_version, GET_PIP - ) - ) - sys.exit(1) - - return True - - def fetch_requirements(requirements_file_path): """ Return a list of requirements and links by parsing the provided requirements file. diff --git a/contrib/runners/local_runner/dist_utils.py b/contrib/runners/local_runner/dist_utils.py index a4e9862d2b..fa752580a2 100644 --- a/contrib/runners/local_runner/dist_utils.py +++ b/contrib/runners/local_runner/dist_utils.py @@ -24,8 +24,6 @@ import re import sys -from distutils.version import StrictVersion - # NOTE: This script can't rely on any 3rd party dependency so we need to use this code here # # TODO: Why can't this script rely on 3rd party dependencies? Is it because it has to import @@ -48,8 +46,6 @@ GET_PIP = "curl https://bootstrap.pypa.io/get-pip.py | python" __all__ = [ - "check_pip_is_installed", - "check_pip_version", "fetch_requirements", "apply_vagrant_workaround", "get_version_string", @@ -57,41 +53,6 @@ ] -def check_pip_is_installed(): - """ - Ensure that pip is installed. - """ - try: - import pip # NOQA - except ImportError as e: - print("Failed to import pip: %s" % (text_type(e))) - print("") - print("Download pip:\n%s" % (GET_PIP)) - sys.exit(1) - - return True - - -def check_pip_version(min_version="6.0.0"): - """ - Ensure that a minimum supported version of pip is installed. - """ - check_pip_is_installed() - - import pip - - if StrictVersion(pip.__version__) < StrictVersion(min_version): - print( - "Upgrade pip, your version '{0}' " - "is outdated. Minimum required version is '{1}':\n{2}".format( - pip.__version__, min_version, GET_PIP - ) - ) - sys.exit(1) - - return True - - def fetch_requirements(requirements_file_path): """ Return a list of requirements and links by parsing the provided requirements file. diff --git a/contrib/runners/noop_runner/dist_utils.py b/contrib/runners/noop_runner/dist_utils.py index a4e9862d2b..fa752580a2 100644 --- a/contrib/runners/noop_runner/dist_utils.py +++ b/contrib/runners/noop_runner/dist_utils.py @@ -24,8 +24,6 @@ import re import sys -from distutils.version import StrictVersion - # NOTE: This script can't rely on any 3rd party dependency so we need to use this code here # # TODO: Why can't this script rely on 3rd party dependencies? Is it because it has to import @@ -48,8 +46,6 @@ GET_PIP = "curl https://bootstrap.pypa.io/get-pip.py | python" __all__ = [ - "check_pip_is_installed", - "check_pip_version", "fetch_requirements", "apply_vagrant_workaround", "get_version_string", @@ -57,41 +53,6 @@ ] -def check_pip_is_installed(): - """ - Ensure that pip is installed. - """ - try: - import pip # NOQA - except ImportError as e: - print("Failed to import pip: %s" % (text_type(e))) - print("") - print("Download pip:\n%s" % (GET_PIP)) - sys.exit(1) - - return True - - -def check_pip_version(min_version="6.0.0"): - """ - Ensure that a minimum supported version of pip is installed. - """ - check_pip_is_installed() - - import pip - - if StrictVersion(pip.__version__) < StrictVersion(min_version): - print( - "Upgrade pip, your version '{0}' " - "is outdated. Minimum required version is '{1}':\n{2}".format( - pip.__version__, min_version, GET_PIP - ) - ) - sys.exit(1) - - return True - - def fetch_requirements(requirements_file_path): """ Return a list of requirements and links by parsing the provided requirements file. diff --git a/contrib/runners/orquesta_runner/dist_utils.py b/contrib/runners/orquesta_runner/dist_utils.py index a4e9862d2b..fa752580a2 100644 --- a/contrib/runners/orquesta_runner/dist_utils.py +++ b/contrib/runners/orquesta_runner/dist_utils.py @@ -24,8 +24,6 @@ import re import sys -from distutils.version import StrictVersion - # NOTE: This script can't rely on any 3rd party dependency so we need to use this code here # # TODO: Why can't this script rely on 3rd party dependencies? Is it because it has to import @@ -48,8 +46,6 @@ GET_PIP = "curl https://bootstrap.pypa.io/get-pip.py | python" __all__ = [ - "check_pip_is_installed", - "check_pip_version", "fetch_requirements", "apply_vagrant_workaround", "get_version_string", @@ -57,41 +53,6 @@ ] -def check_pip_is_installed(): - """ - Ensure that pip is installed. - """ - try: - import pip # NOQA - except ImportError as e: - print("Failed to import pip: %s" % (text_type(e))) - print("") - print("Download pip:\n%s" % (GET_PIP)) - sys.exit(1) - - return True - - -def check_pip_version(min_version="6.0.0"): - """ - Ensure that a minimum supported version of pip is installed. - """ - check_pip_is_installed() - - import pip - - if StrictVersion(pip.__version__) < StrictVersion(min_version): - print( - "Upgrade pip, your version '{0}' " - "is outdated. Minimum required version is '{1}':\n{2}".format( - pip.__version__, min_version, GET_PIP - ) - ) - sys.exit(1) - - return True - - def fetch_requirements(requirements_file_path): """ Return a list of requirements and links by parsing the provided requirements file. diff --git a/contrib/runners/python_runner/dist_utils.py b/contrib/runners/python_runner/dist_utils.py index a4e9862d2b..fa752580a2 100644 --- a/contrib/runners/python_runner/dist_utils.py +++ b/contrib/runners/python_runner/dist_utils.py @@ -24,8 +24,6 @@ import re import sys -from distutils.version import StrictVersion - # NOTE: This script can't rely on any 3rd party dependency so we need to use this code here # # TODO: Why can't this script rely on 3rd party dependencies? Is it because it has to import @@ -48,8 +46,6 @@ GET_PIP = "curl https://bootstrap.pypa.io/get-pip.py | python" __all__ = [ - "check_pip_is_installed", - "check_pip_version", "fetch_requirements", "apply_vagrant_workaround", "get_version_string", @@ -57,41 +53,6 @@ ] -def check_pip_is_installed(): - """ - Ensure that pip is installed. - """ - try: - import pip # NOQA - except ImportError as e: - print("Failed to import pip: %s" % (text_type(e))) - print("") - print("Download pip:\n%s" % (GET_PIP)) - sys.exit(1) - - return True - - -def check_pip_version(min_version="6.0.0"): - """ - Ensure that a minimum supported version of pip is installed. - """ - check_pip_is_installed() - - import pip - - if StrictVersion(pip.__version__) < StrictVersion(min_version): - print( - "Upgrade pip, your version '{0}' " - "is outdated. Minimum required version is '{1}':\n{2}".format( - pip.__version__, min_version, GET_PIP - ) - ) - sys.exit(1) - - return True - - def fetch_requirements(requirements_file_path): """ Return a list of requirements and links by parsing the provided requirements file. diff --git a/contrib/runners/python_runner/python_runner/python_action_wrapper.py b/contrib/runners/python_runner/python_runner/python_action_wrapper.py index 795b0114a8..50dddad2ff 100644 --- a/contrib/runners/python_runner/python_runner/python_action_wrapper.py +++ b/contrib/runners/python_runner/python_runner/python_action_wrapper.py @@ -26,7 +26,7 @@ import select import traceback -import distutils.sysconfig +import sysconfig # NOTE: We intentionally use orjson directly here instead of json_encode - orjson.dumps relies # on config option which we don't parse for the action wrapper since it speeds things down - action @@ -49,7 +49,7 @@ # This puts priority on loading virtualenv library in the pack's action. This is necessary # for the situation that both st2 and pack require to load same name libraries with different # version. Without this statement, action may call library method with unexpected dependencies. - sys.path.insert(0, distutils.sysconfig.get_python_lib()) + sys.path.insert(0, sysconfig.get_path('platlib')) import sys import argparse diff --git a/contrib/runners/python_runner/tests/integration/test_python_action_process_wrapper.py b/contrib/runners/python_runner/tests/integration/test_python_action_process_wrapper.py index c97a380fb2..da939f4aae 100644 --- a/contrib/runners/python_runner/tests/integration/test_python_action_process_wrapper.py +++ b/contrib/runners/python_runner/tests/integration/test_python_action_process_wrapper.py @@ -37,7 +37,7 @@ import json import unittest2 -from distutils.spawn import find_executable +from shutil import which as shutil_which from st2common.util.shell import run_command from six.moves import range @@ -61,7 +61,7 @@ BASE_DIR, "../../../python_runner/python_runner/python_action_wrapper.py" ) WRAPPER_SCRIPT_PATH = os.path.abspath(WRAPPER_SCRIPT_PATH) -TIME_BINARY_PATH = find_executable("time") +TIME_BINARY_PATH = shutil_which("time") TIME_BINARY_AVAILABLE = TIME_BINARY_PATH is not None diff --git a/contrib/runners/remote_runner/dist_utils.py b/contrib/runners/remote_runner/dist_utils.py index a4e9862d2b..fa752580a2 100644 --- a/contrib/runners/remote_runner/dist_utils.py +++ b/contrib/runners/remote_runner/dist_utils.py @@ -24,8 +24,6 @@ import re import sys -from distutils.version import StrictVersion - # NOTE: This script can't rely on any 3rd party dependency so we need to use this code here # # TODO: Why can't this script rely on 3rd party dependencies? Is it because it has to import @@ -48,8 +46,6 @@ GET_PIP = "curl https://bootstrap.pypa.io/get-pip.py | python" __all__ = [ - "check_pip_is_installed", - "check_pip_version", "fetch_requirements", "apply_vagrant_workaround", "get_version_string", @@ -57,41 +53,6 @@ ] -def check_pip_is_installed(): - """ - Ensure that pip is installed. - """ - try: - import pip # NOQA - except ImportError as e: - print("Failed to import pip: %s" % (text_type(e))) - print("") - print("Download pip:\n%s" % (GET_PIP)) - sys.exit(1) - - return True - - -def check_pip_version(min_version="6.0.0"): - """ - Ensure that a minimum supported version of pip is installed. - """ - check_pip_is_installed() - - import pip - - if StrictVersion(pip.__version__) < StrictVersion(min_version): - print( - "Upgrade pip, your version '{0}' " - "is outdated. Minimum required version is '{1}':\n{2}".format( - pip.__version__, min_version, GET_PIP - ) - ) - sys.exit(1) - - return True - - def fetch_requirements(requirements_file_path): """ Return a list of requirements and links by parsing the provided requirements file. diff --git a/contrib/runners/winrm_runner/dist_utils.py b/contrib/runners/winrm_runner/dist_utils.py index a4e9862d2b..fa752580a2 100644 --- a/contrib/runners/winrm_runner/dist_utils.py +++ b/contrib/runners/winrm_runner/dist_utils.py @@ -24,8 +24,6 @@ import re import sys -from distutils.version import StrictVersion - # NOTE: This script can't rely on any 3rd party dependency so we need to use this code here # # TODO: Why can't this script rely on 3rd party dependencies? Is it because it has to import @@ -48,8 +46,6 @@ GET_PIP = "curl https://bootstrap.pypa.io/get-pip.py | python" __all__ = [ - "check_pip_is_installed", - "check_pip_version", "fetch_requirements", "apply_vagrant_workaround", "get_version_string", @@ -57,41 +53,6 @@ ] -def check_pip_is_installed(): - """ - Ensure that pip is installed. - """ - try: - import pip # NOQA - except ImportError as e: - print("Failed to import pip: %s" % (text_type(e))) - print("") - print("Download pip:\n%s" % (GET_PIP)) - sys.exit(1) - - return True - - -def check_pip_version(min_version="6.0.0"): - """ - Ensure that a minimum supported version of pip is installed. - """ - check_pip_is_installed() - - import pip - - if StrictVersion(pip.__version__) < StrictVersion(min_version): - print( - "Upgrade pip, your version '{0}' " - "is outdated. Minimum required version is '{1}':\n{2}".format( - pip.__version__, min_version, GET_PIP - ) - ) - sys.exit(1) - - return True - - def fetch_requirements(requirements_file_path): """ Return a list of requirements and links by parsing the provided requirements file. diff --git a/scripts/dist_utils.py b/scripts/dist_utils.py index 297efe1689..9c27f683ca 100644 --- a/scripts/dist_utils.py +++ b/scripts/dist_utils.py @@ -20,8 +20,6 @@ import re import sys -from distutils.version import StrictVersion - # // NOTE: After you update this script, please run: # // # // make .sdist-requirements @@ -52,8 +50,6 @@ GET_PIP = "curl https://bootstrap.pypa.io/get-pip.py | python" __all__ = [ - "check_pip_is_installed", - "check_pip_version", "fetch_requirements", "apply_vagrant_workaround", "get_version_string", @@ -61,41 +57,6 @@ ] -def check_pip_is_installed(): - """ - Ensure that pip is installed. - """ - try: - import pip # NOQA - except ImportError as e: - print("Failed to import pip: %s" % (text_type(e))) - print("") - print("Download pip:\n%s" % (GET_PIP)) - sys.exit(1) - - return True - - -def check_pip_version(min_version="6.0.0"): - """ - Ensure that a minimum supported version of pip is installed. - """ - check_pip_is_installed() - - import pip - - if StrictVersion(pip.__version__) < StrictVersion(min_version): - print( - "Upgrade pip, your version '{0}' " - "is outdated. Minimum required version is '{1}':\n{2}".format( - pip.__version__, min_version, GET_PIP - ) - ) - sys.exit(1) - - return True - - def fetch_requirements(requirements_file_path): """ Return a list of requirements and links by parsing the provided requirements file. diff --git a/scripts/dist_utils_old.py b/scripts/dist_utils_old.py index da38f6edbf..05fdb6b92e 100644 --- a/scripts/dist_utils_old.py +++ b/scripts/dist_utils_old.py @@ -27,8 +27,6 @@ import re import sys -from distutils.version import StrictVersion - # NOTE: This script can't rely on any 3rd party dependency so we need to use this code here PY3 = sys.version_info[0] == 3 @@ -62,7 +60,6 @@ sys.exit(1) __all__ = [ - "check_pip_version", "fetch_requirements", "apply_vagrant_workaround", "get_version_string", @@ -70,20 +67,6 @@ ] -def check_pip_version(min_version="6.0.0"): - """ - Ensure that a minimum supported version of pip is installed. - """ - if StrictVersion(pip.__version__) < StrictVersion(min_version): - print( - "Upgrade pip, your version '{0}' " - "is outdated. Minimum required version is '{1}':\n{2}".format( - pip.__version__, min_version, GET_PIP - ) - ) - sys.exit(1) - - def fetch_requirements(requirements_file_path): """ Return a list of requirements and links by parsing the provided requirements file. diff --git a/scripts/fixate-requirements.py b/scripts/fixate-requirements.py index a60f43b4aa..bf5f9c898b 100755 --- a/scripts/fixate-requirements.py +++ b/scripts/fixate-requirements.py @@ -34,7 +34,7 @@ import os.path import sys -from distutils.version import StrictVersion +from packaging.version import Version # NOTE: This script can't rely on any 3rd party dependency so we need to use this code here PY2 = sys.version_info[0] == 2 @@ -116,7 +116,7 @@ def parse_args(): def check_pip_version(): - if StrictVersion(pip.__version__) < StrictVersion("6.1.0"): + if Version(pip.__version__) < Version("6.1.0"): print( "Upgrade pip, your version `{0}' " "is outdated:\n".format(pip.__version__), GET_PIP, diff --git a/st2actions/dist_utils.py b/st2actions/dist_utils.py index a4e9862d2b..fa752580a2 100644 --- a/st2actions/dist_utils.py +++ b/st2actions/dist_utils.py @@ -24,8 +24,6 @@ import re import sys -from distutils.version import StrictVersion - # NOTE: This script can't rely on any 3rd party dependency so we need to use this code here # # TODO: Why can't this script rely on 3rd party dependencies? Is it because it has to import @@ -48,8 +46,6 @@ GET_PIP = "curl https://bootstrap.pypa.io/get-pip.py | python" __all__ = [ - "check_pip_is_installed", - "check_pip_version", "fetch_requirements", "apply_vagrant_workaround", "get_version_string", @@ -57,41 +53,6 @@ ] -def check_pip_is_installed(): - """ - Ensure that pip is installed. - """ - try: - import pip # NOQA - except ImportError as e: - print("Failed to import pip: %s" % (text_type(e))) - print("") - print("Download pip:\n%s" % (GET_PIP)) - sys.exit(1) - - return True - - -def check_pip_version(min_version="6.0.0"): - """ - Ensure that a minimum supported version of pip is installed. - """ - check_pip_is_installed() - - import pip - - if StrictVersion(pip.__version__) < StrictVersion(min_version): - print( - "Upgrade pip, your version '{0}' " - "is outdated. Minimum required version is '{1}':\n{2}".format( - pip.__version__, min_version, GET_PIP - ) - ) - sys.exit(1) - - return True - - def fetch_requirements(requirements_file_path): """ Return a list of requirements and links by parsing the provided requirements file. diff --git a/st2api/dist_utils.py b/st2api/dist_utils.py index a4e9862d2b..fa752580a2 100644 --- a/st2api/dist_utils.py +++ b/st2api/dist_utils.py @@ -24,8 +24,6 @@ import re import sys -from distutils.version import StrictVersion - # NOTE: This script can't rely on any 3rd party dependency so we need to use this code here # # TODO: Why can't this script rely on 3rd party dependencies? Is it because it has to import @@ -48,8 +46,6 @@ GET_PIP = "curl https://bootstrap.pypa.io/get-pip.py | python" __all__ = [ - "check_pip_is_installed", - "check_pip_version", "fetch_requirements", "apply_vagrant_workaround", "get_version_string", @@ -57,41 +53,6 @@ ] -def check_pip_is_installed(): - """ - Ensure that pip is installed. - """ - try: - import pip # NOQA - except ImportError as e: - print("Failed to import pip: %s" % (text_type(e))) - print("") - print("Download pip:\n%s" % (GET_PIP)) - sys.exit(1) - - return True - - -def check_pip_version(min_version="6.0.0"): - """ - Ensure that a minimum supported version of pip is installed. - """ - check_pip_is_installed() - - import pip - - if StrictVersion(pip.__version__) < StrictVersion(min_version): - print( - "Upgrade pip, your version '{0}' " - "is outdated. Minimum required version is '{1}':\n{2}".format( - pip.__version__, min_version, GET_PIP - ) - ) - sys.exit(1) - - return True - - def fetch_requirements(requirements_file_path): """ Return a list of requirements and links by parsing the provided requirements file. diff --git a/st2auth/dist_utils.py b/st2auth/dist_utils.py index a4e9862d2b..fa752580a2 100644 --- a/st2auth/dist_utils.py +++ b/st2auth/dist_utils.py @@ -24,8 +24,6 @@ import re import sys -from distutils.version import StrictVersion - # NOTE: This script can't rely on any 3rd party dependency so we need to use this code here # # TODO: Why can't this script rely on 3rd party dependencies? Is it because it has to import @@ -48,8 +46,6 @@ GET_PIP = "curl https://bootstrap.pypa.io/get-pip.py | python" __all__ = [ - "check_pip_is_installed", - "check_pip_version", "fetch_requirements", "apply_vagrant_workaround", "get_version_string", @@ -57,41 +53,6 @@ ] -def check_pip_is_installed(): - """ - Ensure that pip is installed. - """ - try: - import pip # NOQA - except ImportError as e: - print("Failed to import pip: %s" % (text_type(e))) - print("") - print("Download pip:\n%s" % (GET_PIP)) - sys.exit(1) - - return True - - -def check_pip_version(min_version="6.0.0"): - """ - Ensure that a minimum supported version of pip is installed. - """ - check_pip_is_installed() - - import pip - - if StrictVersion(pip.__version__) < StrictVersion(min_version): - print( - "Upgrade pip, your version '{0}' " - "is outdated. Minimum required version is '{1}':\n{2}".format( - pip.__version__, min_version, GET_PIP - ) - ) - sys.exit(1) - - return True - - def fetch_requirements(requirements_file_path): """ Return a list of requirements and links by parsing the provided requirements file. diff --git a/st2client/dist_utils.py b/st2client/dist_utils.py index a4e9862d2b..fa752580a2 100644 --- a/st2client/dist_utils.py +++ b/st2client/dist_utils.py @@ -24,8 +24,6 @@ import re import sys -from distutils.version import StrictVersion - # NOTE: This script can't rely on any 3rd party dependency so we need to use this code here # # TODO: Why can't this script rely on 3rd party dependencies? Is it because it has to import @@ -48,8 +46,6 @@ GET_PIP = "curl https://bootstrap.pypa.io/get-pip.py | python" __all__ = [ - "check_pip_is_installed", - "check_pip_version", "fetch_requirements", "apply_vagrant_workaround", "get_version_string", @@ -57,41 +53,6 @@ ] -def check_pip_is_installed(): - """ - Ensure that pip is installed. - """ - try: - import pip # NOQA - except ImportError as e: - print("Failed to import pip: %s" % (text_type(e))) - print("") - print("Download pip:\n%s" % (GET_PIP)) - sys.exit(1) - - return True - - -def check_pip_version(min_version="6.0.0"): - """ - Ensure that a minimum supported version of pip is installed. - """ - check_pip_is_installed() - - import pip - - if StrictVersion(pip.__version__) < StrictVersion(min_version): - print( - "Upgrade pip, your version '{0}' " - "is outdated. Minimum required version is '{1}':\n{2}".format( - pip.__version__, min_version, GET_PIP - ) - ) - sys.exit(1) - - return True - - def fetch_requirements(requirements_file_path): """ Return a list of requirements and links by parsing the provided requirements file. diff --git a/st2client/setup.py b/st2client/setup.py index 2404072522..decfaf9237 100644 --- a/st2client/setup.py +++ b/st2client/setup.py @@ -18,14 +18,11 @@ from setuptools import setup, find_packages -from dist_utils import check_pip_version from dist_utils import fetch_requirements from dist_utils import apply_vagrant_workaround from st2client import __version__ -check_pip_version() - ST2_COMPONENT = "st2client" BASE_DIR = os.path.dirname(os.path.abspath(__file__)) REQUIREMENTS_FILE = os.path.join(BASE_DIR, "requirements.txt") diff --git a/st2common/dist_utils.py b/st2common/dist_utils.py index a4e9862d2b..fa752580a2 100644 --- a/st2common/dist_utils.py +++ b/st2common/dist_utils.py @@ -24,8 +24,6 @@ import re import sys -from distutils.version import StrictVersion - # NOTE: This script can't rely on any 3rd party dependency so we need to use this code here # # TODO: Why can't this script rely on 3rd party dependencies? Is it because it has to import @@ -48,8 +46,6 @@ GET_PIP = "curl https://bootstrap.pypa.io/get-pip.py | python" __all__ = [ - "check_pip_is_installed", - "check_pip_version", "fetch_requirements", "apply_vagrant_workaround", "get_version_string", @@ -57,41 +53,6 @@ ] -def check_pip_is_installed(): - """ - Ensure that pip is installed. - """ - try: - import pip # NOQA - except ImportError as e: - print("Failed to import pip: %s" % (text_type(e))) - print("") - print("Download pip:\n%s" % (GET_PIP)) - sys.exit(1) - - return True - - -def check_pip_version(min_version="6.0.0"): - """ - Ensure that a minimum supported version of pip is installed. - """ - check_pip_is_installed() - - import pip - - if StrictVersion(pip.__version__) < StrictVersion(min_version): - print( - "Upgrade pip, your version '{0}' " - "is outdated. Minimum required version is '{1}':\n{2}".format( - pip.__version__, min_version, GET_PIP - ) - ) - sys.exit(1) - - return True - - def fetch_requirements(requirements_file_path): """ Return a list of requirements and links by parsing the provided requirements file. diff --git a/st2common/st2common/util/pack_management.py b/st2common/st2common/util/pack_management.py index ae3c256184..c9576f6fcc 100644 --- a/st2common/st2common/util/pack_management.py +++ b/st2common/st2common/util/pack_management.py @@ -35,7 +35,7 @@ from git.repo import Repo from gitdb.exc import BadName, BadObject from lockfile import LockFile -from distutils.spawn import find_executable +from shutil import which as shutil_which from st2common import log as logging from st2common.content import utils @@ -67,7 +67,7 @@ CURRENT_STACKSTORM_VERSION = get_stackstorm_version() CURRENT_PYTHON_VERSION = get_python_version() -SUDO_BINARY = find_executable("sudo") +SUDO_BINARY = shutil_which("sudo") def download_pack( diff --git a/st2common/st2common/util/sandboxing.py b/st2common/st2common/util/sandboxing.py index 791607471f..89c5b5f7c7 100644 --- a/st2common/st2common/util/sandboxing.py +++ b/st2common/st2common/util/sandboxing.py @@ -23,7 +23,7 @@ import fnmatch import os import sys -from distutils.sysconfig import get_python_lib +import sysconfig from oslo_config import cfg @@ -108,7 +108,7 @@ def get_sandbox_python_path(inherit_from_parent=True, inherit_parent_virtualenv= if inherit_parent_virtualenv and is_in_virtualenv(): # We are running inside virtualenv - site_packages_dir = get_python_lib() + site_packages_dir = sysconfig.get_path('platlib') sys_prefix = os.path.abspath(sys.prefix) if sys_prefix not in site_packages_dir: diff --git a/st2common/st2common/util/virtualenvs.py b/st2common/st2common/util/virtualenvs.py index 20100369b0..188733e85c 100644 --- a/st2common/st2common/util/virtualenvs.py +++ b/st2common/st2common/util/virtualenvs.py @@ -67,7 +67,7 @@ def setup_pack_virtualenv( level logger. :param no_download: Do not download and install latest version of pre-installed packages such - as pip and distutils. + as pip and setuptools. :type no_download: ``bool`` """ logger = logger or LOG @@ -170,7 +170,7 @@ def create_virtualenv( :type include_wheel : ``bool`` :param no_download: Do not download and install latest version of pre-installed packages such - as pip and distutils. + as pip and setuptools. :type no_download: ``bool`` """ diff --git a/st2common/tests/unit/test_dist_utils.py b/st2common/tests/unit/test_dist_utils.py index 1b01d4ff48..3faaf03bec 100644 --- a/st2common/tests/unit/test_dist_utils.py +++ b/st2common/tests/unit/test_dist_utils.py @@ -26,8 +26,6 @@ # Add scripts/ which contain main dist_utils.py to PYTHONPATH sys.path.insert(0, SCRIPTS_PATH) -from dist_utils import check_pip_is_installed -from dist_utils import check_pip_version from dist_utils import fetch_requirements from dist_utils import apply_vagrant_workaround from dist_utils import get_version_string @@ -51,39 +49,6 @@ def setUp(self): def tearDown(self): super(DistUtilsTestCase, self).tearDown() - def test_check_pip_is_installed_success(self): - self.assertTrue(check_pip_is_installed()) - - @mock.patch("sys.exit") - def test_check_pip_is_installed_failure(self, mock_sys_exit): - if six.PY3: - module_name = "builtins.__import__" - else: - module_name = "__builtin__.__import__" - - with mock.patch(module_name) as mock_import: - mock_import.side_effect = ImportError("not found") - - self.assertEqual(mock_sys_exit.call_count, 0) - check_pip_is_installed() - self.assertEqual(mock_sys_exit.call_count, 1) - self.assertEqual(mock_sys_exit.call_args_list[0][0], (1,)) - - def test_check_pip_version_success(self): - self.assertTrue(check_pip_version()) - - @mock.patch("sys.exit") - def test_check_pip_version_failure(self, mock_sys_exit): - - mock_pip = mock.Mock() - mock_pip.__version__ = "0.0.0" - sys.modules["pip"] = mock_pip - - self.assertEqual(mock_sys_exit.call_count, 0) - check_pip_version() - self.assertEqual(mock_sys_exit.call_count, 1) - self.assertEqual(mock_sys_exit.call_args_list[0][0], (1,)) - def test_get_version_string(self): version = get_version_string(VERSION_FILE_PATH) self.assertEqual(version, "1.2.3") diff --git a/st2reactor/dist_utils.py b/st2reactor/dist_utils.py index a4e9862d2b..fa752580a2 100644 --- a/st2reactor/dist_utils.py +++ b/st2reactor/dist_utils.py @@ -24,8 +24,6 @@ import re import sys -from distutils.version import StrictVersion - # NOTE: This script can't rely on any 3rd party dependency so we need to use this code here # # TODO: Why can't this script rely on 3rd party dependencies? Is it because it has to import @@ -48,8 +46,6 @@ GET_PIP = "curl https://bootstrap.pypa.io/get-pip.py | python" __all__ = [ - "check_pip_is_installed", - "check_pip_version", "fetch_requirements", "apply_vagrant_workaround", "get_version_string", @@ -57,41 +53,6 @@ ] -def check_pip_is_installed(): - """ - Ensure that pip is installed. - """ - try: - import pip # NOQA - except ImportError as e: - print("Failed to import pip: %s" % (text_type(e))) - print("") - print("Download pip:\n%s" % (GET_PIP)) - sys.exit(1) - - return True - - -def check_pip_version(min_version="6.0.0"): - """ - Ensure that a minimum supported version of pip is installed. - """ - check_pip_is_installed() - - import pip - - if StrictVersion(pip.__version__) < StrictVersion(min_version): - print( - "Upgrade pip, your version '{0}' " - "is outdated. Minimum required version is '{1}':\n{2}".format( - pip.__version__, min_version, GET_PIP - ) - ) - sys.exit(1) - - return True - - def fetch_requirements(requirements_file_path): """ Return a list of requirements and links by parsing the provided requirements file. diff --git a/st2stream/dist_utils.py b/st2stream/dist_utils.py index a4e9862d2b..fa752580a2 100644 --- a/st2stream/dist_utils.py +++ b/st2stream/dist_utils.py @@ -24,8 +24,6 @@ import re import sys -from distutils.version import StrictVersion - # NOTE: This script can't rely on any 3rd party dependency so we need to use this code here # # TODO: Why can't this script rely on 3rd party dependencies? Is it because it has to import @@ -48,8 +46,6 @@ GET_PIP = "curl https://bootstrap.pypa.io/get-pip.py | python" __all__ = [ - "check_pip_is_installed", - "check_pip_version", "fetch_requirements", "apply_vagrant_workaround", "get_version_string", @@ -57,41 +53,6 @@ ] -def check_pip_is_installed(): - """ - Ensure that pip is installed. - """ - try: - import pip # NOQA - except ImportError as e: - print("Failed to import pip: %s" % (text_type(e))) - print("") - print("Download pip:\n%s" % (GET_PIP)) - sys.exit(1) - - return True - - -def check_pip_version(min_version="6.0.0"): - """ - Ensure that a minimum supported version of pip is installed. - """ - check_pip_is_installed() - - import pip - - if StrictVersion(pip.__version__) < StrictVersion(min_version): - print( - "Upgrade pip, your version '{0}' " - "is outdated. Minimum required version is '{1}':\n{2}".format( - pip.__version__, min_version, GET_PIP - ) - ) - sys.exit(1) - - return True - - def fetch_requirements(requirements_file_path): """ Return a list of requirements and links by parsing the provided requirements file. diff --git a/st2tests/dist_utils.py b/st2tests/dist_utils.py index a4e9862d2b..fa752580a2 100644 --- a/st2tests/dist_utils.py +++ b/st2tests/dist_utils.py @@ -24,8 +24,6 @@ import re import sys -from distutils.version import StrictVersion - # NOTE: This script can't rely on any 3rd party dependency so we need to use this code here # # TODO: Why can't this script rely on 3rd party dependencies? Is it because it has to import @@ -48,8 +46,6 @@ GET_PIP = "curl https://bootstrap.pypa.io/get-pip.py | python" __all__ = [ - "check_pip_is_installed", - "check_pip_version", "fetch_requirements", "apply_vagrant_workaround", "get_version_string", @@ -57,41 +53,6 @@ ] -def check_pip_is_installed(): - """ - Ensure that pip is installed. - """ - try: - import pip # NOQA - except ImportError as e: - print("Failed to import pip: %s" % (text_type(e))) - print("") - print("Download pip:\n%s" % (GET_PIP)) - sys.exit(1) - - return True - - -def check_pip_version(min_version="6.0.0"): - """ - Ensure that a minimum supported version of pip is installed. - """ - check_pip_is_installed() - - import pip - - if StrictVersion(pip.__version__) < StrictVersion(min_version): - print( - "Upgrade pip, your version '{0}' " - "is outdated. Minimum required version is '{1}':\n{2}".format( - pip.__version__, min_version, GET_PIP - ) - ) - sys.exit(1) - - return True - - def fetch_requirements(requirements_file_path): """ Return a list of requirements and links by parsing the provided requirements file.