diff --git a/src/octoprint/util/pip.py b/src/octoprint/util/pip.py index 205185c27..bf50e048f 100644 --- a/src/octoprint/util/pip.py +++ b/src/octoprint/util/pip.py @@ -27,6 +27,9 @@ OUTPUT_SUCCESS = "Successfully installed" OUTPUT_FAILURE = "Could not install" """Start of failure result line""" +OUTPUT_ERROR = "ERROR:" +"""Start of error line""" + OUTPUT_ALREADY_INSTALLED = "Requirement already satisfied" """Start of a line indicating some package was already installed in this version""" @@ -58,8 +61,10 @@ def is_already_installed(lines): bool: True if detected, False otherwise """ result_line = get_result_line(lines) # neither success nor failure reported - return not result_line and any( - line.strip().startswith(OUTPUT_ALREADY_INSTALLED) for line in lines + return ( + not result_line + and not any(line.strip().startswith(OUTPUT_ERROR) for line in lines) + and any(line.strip().startswith(OUTPUT_ALREADY_INSTALLED) for line in lines) ) @@ -114,7 +119,7 @@ def get_result_line(lines): pip might generate more lines after the actual result line, which is why we can't just take the final line. So instead we look for the last line - starting with either "Successfully installed" or "Could not installed". + starting with either "Successfully installed" or "Could not install". If neither can be found, an empty string will be returned, which should also be considered a failure to install. diff --git a/tests/util/_files/pip_test_data/dependency_error.txt b/tests/util/_files/pip_test_data/dependency_error.txt new file mode 100644 index 000000000..ce4cdfa3f --- /dev/null +++ b/tests/util/_files/pip_test_data/dependency_error.txt @@ -0,0 +1,18 @@ +Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple +Processing /tmp/tmprvq8z421.zip +Preparing metadata (setup.py): started +Preparing metadata (setup.py): finished with status 'done' +Requirement already satisfied: OctoPrint in /home/pi/oprint/lib/python3.9/site-packages (from OctoEverywhere==1.11.2) (1.8.6) +Requirement already satisfied: certifi in /home/pi/oprint/lib/python3.9/site-packages (from OctoEverywhere==1.11.2) (2022.9.24) +WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError(': Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/dnspython/ +WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError(': Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/dnspython/ +WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError(': Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/dnspython/ +WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError(': Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/dnspython/ +WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError(': Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/dnspython/ +WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError(': Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/dnspython/ +WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError(': Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/dnspython/ +WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError(': Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/dnspython/ +WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError(': Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/dnspython/ +WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError(': Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/dnspython/ +ERROR: Could not find a version that satisfies the requirement dnspython (from octoeverywhere) (from versions: none) +ERROR: No matching distribution found for dnspython diff --git a/tests/util/test_pip.py b/tests/util/test_pip.py index 2d480e0ee..da80a3f79 100644 --- a/tests/util/test_pip.py +++ b/tests/util/test_pip.py @@ -165,6 +165,7 @@ class PipUtilTest(unittest.TestCase): ("already_installed_1.txt", True), ("already_installed_2.txt", True), ("successful_install_1.txt", False), + ("dependency_error.txt", False), ) @ddt.unpack def test_is_already_installed(self, file, expected):