Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 26 additions & 10 deletions python/pip_install/pip_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,33 @@
cli()
print("cli() should exit", file=sys.stderr)
sys.exit(1)
except SystemExit:
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)
except SystemExit as e:
if e.code == 2:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This improves things for sure, but still leaves us open to cases where e.code not in {0, 2}. Looking at the piptools source, it only ever exits 0 or 2, but my preference would be to check for the unexpected cases and exit(1) instead of incorrectly succeeding .

if e.code == 2:
   # handle 2
   # ...
   sys.exit(1)
elif e.code == 0:
   # handle 0
   # ...
   sys.exit(0)
else:
   # handle unexpected
   # ...
   sys.exit(1)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I totally agree. I have fixed it that way.

print(
"Lock file out of date. Run '"
+ update_command
+ "' to update.",
"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_in}.",
file=sys.stderr,
)
sys.exit(1)
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(
"Lock file out of date. Run '"
+ update_command
+ "' to update.",
file=sys.stderr,
)
sys.exit(1)
sys.exit(0)
else:
print(
f"pip-compile unexpectedly exited with code {e.code}.",
file=sys.stderr
)
sys.exit(1)