From 1792afc138454a165eb5d87a69f6ac1742294e3e Mon Sep 17 00:00:00 2001 From: Ryo Takahashi Date: Tue, 8 Jun 2021 13:22:20 +0900 Subject: [PATCH 1/3] Check pip-compile failed to resolve requirements --- python/pip_install/pip_compile.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/python/pip_install/pip_compile.py b/python/pip_install/pip_compile.py index 1c22d2c0af..f4694f67b0 100644 --- a/python/pip_install/pip_compile.py +++ b/python/pip_install/pip_compile.py @@ -73,7 +73,15 @@ cli() print("cli() should exit", file=sys.stderr) sys.exit(1) - except SystemExit: + except SystemExit as e: + if e.code == 2: + print( + "pip-compile exit with code 2. This means that pip-compile found " + "incompatible requirements or could not find a version that matches " + f"the install requirement in {requirements_txt}.", + file=sys.stderr, + ) + sys.exit(1) golden = open(requirements_txt).readlines() out = open(requirements_out).readlines() if golden != out: From 6387b266332b7b3d084557f7fa6565a6030b4d2f Mon Sep 17 00:00:00 2001 From: Ryo Takahashi Date: Wed, 9 Jun 2021 09:51:03 +0900 Subject: [PATCH 2/3] Check for codes other than 2 as well --- python/pip_install/pip_compile.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/python/pip_install/pip_compile.py b/python/pip_install/pip_compile.py index f4694f67b0..6dbae4b269 100644 --- a/python/pip_install/pip_compile.py +++ b/python/pip_install/pip_compile.py @@ -82,16 +82,24 @@ file=sys.stderr, ) sys.exit(1) - golden = open(requirements_txt).readlines() - out = open(requirements_out).readlines() - if golden != out: - import difflib + elif e.code == 0: + golden = open(requirements_txt).readlines() + out = open(requirements_out).readlines() + if golden != out: + import difflib - print(''.join(difflib.unified_diff(golden, out)), file=sys.stderr) + print(''.join(difflib.unified_diff(golden, out)), file=sys.stderr) + print( + "Lock file out of date. Run '" + + update_command + + "' to update.", + file=sys.stderr, + ) + sys.exit(1) + sys.exit(0) + else: print( - "Lock file out of date. Run '" - + update_command - + "' to update.", - file=sys.stderr, + f"pip-compile unexpectedly exited with code {e.code}.", + file=sys.stderr ) sys.exit(1) From 0cef7835c34b1499760d76ff0b3500b286809fbb Mon Sep 17 00:00:00 2001 From: Ryo Takahashi Date: Wed, 9 Jun 2021 09:52:06 +0900 Subject: [PATCH 3/3] Fix error message --- python/pip_install/pip_compile.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/pip_install/pip_compile.py b/python/pip_install/pip_compile.py index 6dbae4b269..9e1eca8525 100644 --- a/python/pip_install/pip_compile.py +++ b/python/pip_install/pip_compile.py @@ -76,9 +76,9 @@ except SystemExit as e: if e.code == 2: print( - "pip-compile exit with code 2. This means that pip-compile found " + "pip-compile exited with code 2. This means that pip-compile found " "incompatible requirements or could not find a version that matches " - f"the install requirement in {requirements_txt}.", + f"the install requirement in {requirements_in}.", file=sys.stderr, ) sys.exit(1)