Skip to content
This repository was archived by the owner on Oct 21, 2022. It is now read-only.

Commit 4430474

Browse files
authored
Throw exception when pip check failed not because of version conflicts (#230)
1 parent e467ace commit 4430474

3 files changed

Lines changed: 17 additions & 5 deletions

File tree

compatibility_lib/compatibility_lib/configs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def _format_url(repo_name, setuppy_path=''):
2828
'pip',
2929
'setuptools',
3030
'wheel',
31+
'virtualenv',
3132
]
3233

3334
PKG_LIST = [

compatibility_server/pip_checker.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@
4545
PIP_ENVIRONMENT_ERROR_PATTERN = re.compile(
4646
r'not install packages due to an EnvironmentError: (?P<error>.*)')
4747

48+
# Pattern for pip check results of version conflicts
49+
PIP_CHECK_CONFLICTS_PATTERN = re.compile(
50+
r'(.*)has requirement(.*)but you have(.*)')
51+
4852

4953
class PipCheckerError(Exception):
5054
"""Pip checker failed in an unexpected way."""
@@ -369,10 +373,17 @@ def _check(self, container: docker.models.containers.Container):
369373
stdout=True,
370374
stderr=True,
371375
raise_on_failure=False)
376+
377+
has_version_conflicts = PIP_CHECK_CONFLICTS_PATTERN.search(output)
372378
if returncode:
373-
return PipCheckResult(self._packages,
374-
PipCheckResultType.CHECK_WARNING,
375-
output)
379+
if not has_version_conflicts:
380+
raise PipCheckerError(
381+
error_msg="The docker container timed out before executing"
382+
"pip command. Error msg: {}".format(output))
383+
else:
384+
return PipCheckResult(self._packages,
385+
PipCheckResultType.CHECK_WARNING,
386+
output)
376387
return PipCheckResult(self._packages, PipCheckResultType.SUCCESS)
377388

378389
def _list(self, container: docker.models.containers.Container):

compatibility_server/test_pip_checker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ def test_check_warning(self, mock_docker, mock__call_pypi_json_api):
262262
pip_command=[
263263
self._fake_pip_path,
264264
'--check-returncode=1',
265-
'--check-output=bad-check',
265+
'--check-output=package has requirement A, but you have B',
266266
'--freeze-output=six==1.2.3\n',
267267
'--list-output={}'.format(
268268
json.dumps(expected_list_output))
@@ -271,7 +271,7 @@ def test_check_warning(self, mock_docker, mock__call_pypi_json_api):
271271
expected_check_result = pip_checker.PipCheckResult(
272272
packages=['six'],
273273
result_type=pip_checker.PipCheckResultType.CHECK_WARNING,
274-
result_text='bad-check',
274+
result_text='package has requirement A, but you have B',
275275
dependency_info=expected_dependency_info)
276276

277277
self.assertEqual(

0 commit comments

Comments
 (0)