-
-
Notifications
You must be signed in to change notification settings - Fork 367
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
Replace requests
with httpx
#2041
Changes from all commits
7e36eae
3c7a912
5ffe0f1
568644d
bf89902
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Briefcase now uses `httpx <https://www.python-httpx.org/>`_ internally instead of ``requests``. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,9 +90,12 @@ def __str__(self): | |
|
||
|
||
class NetworkFailure(BriefcaseCommandError): | ||
def __init__(self, action): | ||
DEFAULT_HINT = "is your computer offline?" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The default hint is meant to prevent needing to modify other code paths that already relied on |
||
|
||
def __init__(self, action, hint=None): | ||
self.action = action | ||
super().__init__(msg=f"Unable to {action}; is your computer offline?") | ||
self.hint = hint if hint else self.DEFAULT_HINT | ||
super().__init__(msg=f"Unable to {action}; {self.hint}") | ||
|
||
|
||
class MissingNetworkResourceError(BriefcaseCommandError): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,8 @@ | |
import sys | ||
from unittest import mock | ||
|
||
import httpx | ||
import pytest | ||
from requests import exceptions as requests_exceptions | ||
|
||
from briefcase.exceptions import ( | ||
InvalidStubBinary, | ||
|
@@ -412,8 +412,9 @@ def test_offline_install( | |
stub_binary_revision_path_index, | ||
): | ||
"""If the computer is offline, an error is raised.""" | ||
create_command.tools.requests.get = mock.MagicMock( | ||
side_effect=requests_exceptions.ConnectionError | ||
stream_mock = create_command.tools.httpx.stream = mock.MagicMock() | ||
stream_mock.return_value.__enter__.side_effect = httpx.TransportError( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
"Unstable connection" | ||
) | ||
|
||
# Installing while offline raises an error | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really wasn't sure what version range to select here. I chose 0.20 by searching httpx's changelog and finding the last time they made any noted change to streaming. Other notable API usages are
response.url
ashttpx.URL
, which at least pre-dates 0.20 based on changelog notes that mention it receiving bug fixes in 0.18.0, as does the introduction of retries tohttpx.HTTPTransport
(0.15.0).Aside from that, 0.20.0 is kind of arbitrary. It might be possible to go back even further like to 0.15.0, but 0.20.0 is 3 years old at this point, and I don't really know how to validate that any older version is actually supported (to be fair, I haven't done anything to validate that 0.20.0 is either, other than check feature availability).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0.20.0 seems like a completely reasonable arbitrary version to me :-)