diff --git a/.gitignore b/.gitignore index 555d276e69..090159801f 100644 --- a/.gitignore +++ b/.gitignore @@ -70,3 +70,5 @@ benchmark_histograms/ [._]sw[a-px] [._]*.sw[a-p]x [._]sw[a-p]x + +**/build/lib/** \ No newline at end of file diff --git a/CHANGELOG.rst b/CHANGELOG.rst index dbe21c9523..59f4ab2406 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -15,6 +15,7 @@ Fixed Added ~~~~~ + * Move `git clone` to `user_home/.st2packs` #5845 * Error on `st2ctl status` when running in Kubernetes. #5851 @@ -37,6 +38,11 @@ Added * Expose environment variable ST2_ACTION_DEBUG to all StackStorm actions. Contributed by @maxfactor1 +Changed +~~~~~~~ +* Remove `distutils` dependencies across the project. #5992 + Contributed by @AndroxxTraxxon + 3.8.0 - November 18, 2022 ------------------------- 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..0453f7019b 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..739970900c 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 @@ -40,7 +38,6 @@ GET_PIP = "curl https://bootstrap.pypa.io/get-pip.py | python" try: - import pip from pip import __version__ as pip_version except ImportError as e: print("Failed to import pip: %s" % (text_type(e))) @@ -62,7 +59,6 @@ sys.exit(1) __all__ = [ - "check_pip_version", "fetch_requirements", "apply_vagrant_workaround", "get_version_string", @@ -70,20 +66,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..e7b8377297 100755 --- a/scripts/fixate-requirements.py +++ b/scripts/fixate-requirements.py @@ -34,8 +34,6 @@ import os.path 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 PY2 = sys.version_info[0] == 2 PY3 = sys.version_info[0] == 3 @@ -49,7 +47,6 @@ GET_PIP = " curl https://bootstrap.pypa.io/get-pip.py | python" try: - import pip from pip import __version__ as pip_version except ImportError as e: print("Failed to import pip: %s" % (text_type(e))) @@ -115,15 +112,6 @@ def parse_args(): return vars(parser.parse_args()) -def check_pip_version(): - if StrictVersion(pip.__version__) < StrictVersion("6.1.0"): - print( - "Upgrade pip, your version `{0}' " "is outdated:\n".format(pip.__version__), - GET_PIP, - ) - sys.exit(1) - - def load_requirements(file_path): return tuple((r for r in parse_requirements(file_path, session=False))) @@ -282,7 +270,6 @@ def write_requirements( if __name__ == "__main__": - check_pip_version() args = parse_args() if args["skip"]: 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..8640985362 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 +from sysconfig import get_path from oslo_config import cfg @@ -31,6 +31,12 @@ from st2common.constants.pack import SYSTEM_PACK_NAMES from st2common.content.utils import get_pack_base_path + +def get_python_lib(): + """Replacement for distutil.sysconfig.get_python_lib, returns a string with the python platform lib path (to site-packages)""" + return get_path("platlib") + + __all__ = [ "get_sandbox_python_binary_path", "get_sandbox_python_path", 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..e19df80604 100644 --- a/st2common/tests/unit/test_dist_utils.py +++ b/st2common/tests/unit/test_dist_utils.py @@ -16,7 +16,6 @@ import os import sys -import six import mock import unittest2 @@ -26,8 +25,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 +48,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.