Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't print stacktrace due to invalid req #5923

Merged
merged 1 commit into from
Nov 8, 2018
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions news/5147.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Invalid requirement no longer causes stack trace to be printed.
3 changes: 1 addition & 2 deletions src/pip/_internal/req/constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import logging
import os
import re
import traceback

from pip._vendor.packaging.markers import Marker
from pip._vendor.packaging.requirements import InvalidRequirement, Requirement
Expand Down Expand Up @@ -258,7 +257,7 @@ def install_req_from_line(
elif '=' in req and not any(op in req for op in operators):
add_msg = "= is not a valid operator. Did you mean == ?"
else:
add_msg = traceback.format_exc()
add_msg = ""
Copy link
Member

Choose a reason for hiding this comment

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

Ideally, I'd say we'd llike an additional logger.debug() to have the traceback in verbose mode

raise InstallationError(
"Invalid requirement: '%s'\n%s" % (req, add_msg)
)
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/test_req.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,12 +542,12 @@ def test_single_equal_sign(self):
assert "Invalid requirement" in err_msg
assert "= is not a valid operator. Did you mean == ?" in err_msg

def test_traceback(self):
def test_unidentifiable_name(self):
test_name = '-'
with pytest.raises(InstallationError) as e:
install_req_from_line('toto 42')
install_req_from_line(test_name)
err_msg = e.value.args[0]
assert "Invalid requirement" in err_msg
assert "\nTraceback " in err_msg
assert ("Invalid requirement: '%s'\n" % test_name) == err_msg

def test_requirement_file(self):
req_file_path = os.path.join(self.tempdir, 'test.txt')
Expand Down