Skip to content

Commit f1b6b74

Browse files
authored
Check pip-compile failed to resolve requirements (#482)
1 parent 915f21b commit f1b6b74

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

python/pip_install/pip_compile.py

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,33 @@
7474
cli()
7575
print("cli() should exit", file=sys.stderr)
7676
sys.exit(1)
77-
except SystemExit:
78-
golden = open(requirements_txt).readlines()
79-
out = open(requirements_out).readlines()
80-
if golden != out:
81-
import difflib
82-
83-
print(''.join(difflib.unified_diff(golden, out)), file=sys.stderr)
77+
except SystemExit as e:
78+
if e.code == 2:
8479
print(
85-
"Lock file out of date. Run '"
86-
+ update_command
87-
+ "' to update.",
80+
"pip-compile exited with code 2. This means that pip-compile found "
81+
"incompatible requirements or could not find a version that matches "
82+
f"the install requirement in {requirements_in}.",
8883
file=sys.stderr,
8984
)
9085
sys.exit(1)
86+
elif e.code == 0:
87+
golden = open(requirements_txt).readlines()
88+
out = open(requirements_out).readlines()
89+
if golden != out:
90+
import difflib
91+
92+
print(''.join(difflib.unified_diff(golden, out)), file=sys.stderr)
93+
print(
94+
"Lock file out of date. Run '"
95+
+ update_command
96+
+ "' to update.",
97+
file=sys.stderr,
98+
)
99+
sys.exit(1)
100+
sys.exit(0)
101+
else:
102+
print(
103+
f"pip-compile unexpectedly exited with code {e.code}.",
104+
file=sys.stderr
105+
)
106+
sys.exit(1)

0 commit comments

Comments
 (0)