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

PR: Use requests instead of urllib for updates #21423

Merged
merged 6 commits into from
Oct 18, 2023

Conversation

mrclary
Copy link
Contributor

@mrclary mrclary commented Oct 12, 2023

Description of Changes

  • Replaced the use of urllib.urlopen and urllib.urlrequest with requests.get when checking and downloading updates.
  • SSL certificates are now verified by default when checking for updates. This was already the default for downloading updates.
  • Some error messaging was updated to reflect possible SSL certificate verification errors.

Issue(s) Resolved

Fixes #21398

@pep8speaks
Copy link

pep8speaks commented Oct 12, 2023

Hello @mrclary! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

Line 289:80: E501 line too long (80 > 79 characters)

Comment last updated at 2023-10-17 19:39:18 UTC

spyder/workers/updates.py Outdated Show resolved Hide resolved
@mrclary mrclary marked this pull request as ready for review October 12, 2023 22:51
Copy link
Member

@dalthviz dalthviz left a comment

Choose a reason for hiding this comment

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

Thanks @mrclary ! Left some suggestions regarding the error text when doing the initial check for updates (keep mentioning that the error is related to Spyder checking for updates). I'm missing to give this a manual check but seems like it should work 👍

spyder/workers/updates.py Outdated Show resolved Hide resolved
spyder/workers/updates.py Outdated Show resolved Hide resolved
Copy link
Member

@ccordoba12 ccordoba12 left a comment

Choose a reason for hiding this comment

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

Some small suggestions for you @mrclary, the rest looks good to me.

Also, could you add a test for WorkerDownloadInstaller? That can be similar to the ones we have for WorkerUpdates and could also test the progress reporting through the sig_download_progress signal.

spyder/workers/updates.py Outdated Show resolved Hide resolved
spyder/workers/updates.py Outdated Show resolved Hide resolved
spyder/workers/updates.py Outdated Show resolved Hide resolved
spyder/workers/updates.py Outdated Show resolved Hide resolved
spyder/workers/updates.py Outdated Show resolved Hide resolved
spyder/workers/updates.py Outdated Show resolved Hide resolved
@mrclary mrclary marked this pull request as draft October 13, 2023 16:27
mrclary and others added 6 commits October 13, 2023 09:32
Note that the default is to verify ssl certificates.
Co-authored-by: Daniel Althviz Moré <16781833+dalthviz@users.noreply.github.com>
Co-authored-by: Carlos Cordoba <ccordoba12@gmail.com>
@mrclary
Copy link
Contributor Author

mrclary commented Oct 13, 2023

Some small suggestions for you @mrclary, the rest looks good to me.

Also, could you add a test for WorkerDownloadInstaller? That can be similar to the ones we have for WorkerUpdates and could also test the progress reporting through the sig_download_progress signal.

Actually, I think the only things to test in the WorkerDownloadInstaller are downloading and progress reporting. This class doesn't really do anything with respect to various circumstances (except Win/mac and Lite/Full, but I don't think we need to worry about that).

Do you have a recommendation on how to go about this? I was thinking of three options:

  1. Run UpdateInstallerDialog.start_installation but somehow mock the download url to point to some small test file somewhere.
    • This provides the most coverage.
  2. Instantiate WorkerDownloadInstaller and UpdateInstallation, connect sig_download_progress signal, and mock the download url to point to some small test file somewhere.
    • This tests the download worker and progress bar directly, so isolates these classes and is more narrowly tailored, but has less code coverage as it doesn't include the UpdateInstallerDialog class behavior.
  3. Either of the above, but somehow mock the requests.Response.iter_content results.
    • If this can be done properly, it will not require actually downloading a file, but actually downloading a file might be something we want tested.

@dalthviz
Copy link
Member

Checking this locally I noticed a couple of things:

Status bar text is not being updated when dismissing update:

  • Checking the update behavior from 5.4.4 to 5.5.0 (when an update is detected the status bar text changes):

detect_update

  • Simulating the update availability using this PR installer (changing the string version in the installed files):

update_pr

Status bar text is not being updated in case an error happens while checking updates (no internet connection):

Seems like this was happening also before so just sharing (could be worthy to fix here or maybe in a follow-up PR after this one gets merged).

update_no_internet

  • Simulating the update availability using the PR installer:

Status bar text is being wrongly updated in case case an error happens while downloading the installer (no internet connection):

Seems like this was happening also before so again just sharing (as the issue above, it could be worthy to fix here or maybe in a follow-up PR after this one gets merged).

download_no_internet

@mrclary
Copy link
Contributor Author

mrclary commented Oct 13, 2023

@dalthviz, thanks for reporting. Yes, I believe these may have been occurring before this PR. I recommend that we fix those in a separate PR. I may be able to address them next week before 5.5.0 release.

@mrclary mrclary marked this pull request as ready for review October 16, 2023 20:48
@mrclary mrclary force-pushed the requests branch 2 times, most recently from 4690ba0 to 314c3ea Compare October 17, 2023 19:39
@mrclary
Copy link
Contributor Author

mrclary commented Oct 17, 2023

Per discussion with @ccordoba12, we will not include unit testing for the WorkerDownloadInstaller. Testing the download of a release artifact will artificially affect our download count on GitHub metrics. To avoid this, a more involved solution is required that would otherwise delay releasing 5.5.0. Additionally, because the end-of-life for the 5.x branch is imminent, efforts at more comprehensive testing are better deferred to the 6.x branch.

Copy link
Member

@ccordoba12 ccordoba12 left a comment

Choose a reason for hiding this comment

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

Thanks @mrclary!

@ccordoba12 ccordoba12 merged commit 2562a84 into spyder-ide:5.x Oct 18, 2023
22 checks passed
ccordoba12 added a commit that referenced this pull request Oct 18, 2023
@mrclary mrclary deleted the requests branch October 18, 2023 16:07
Comment on lines +123 to +124
page = requests.get(self.url)
data = page.json()
Copy link
Member

Choose a reason for hiding this comment

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

If the expected page is not returned, we should raise a HTTPError as soon as possible, instead of a much longer and more cryptic JSONDecodeError on the next line or later on. This is much clearer and friendlier for users and ensures their reports will be much clearer and more useful for us.

So, in a followup PR we should add here between the .get() and the .json()

page.raise_for_status()

Which will raise this error appropriately.

except ConnectionError as err:
error_msg = CONNECT_ERROR_MSG
logger.debug(err, stack_info=True)
except Exception as err:
Copy link
Member

Choose a reason for hiding this comment

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

We could add one more block here to catch HTTPError:

except HTTPError as err:
    error_msg = HTTP_ERROR_MSG.format(page.status_code)
    ...

with a friendly message, e.g. :

HTTP_ERROR_MSG = _(
    'HTTP error {status_code} when checking for updates.'
    '<br><br>Make sure your connection is working properly.'
)

)

CONNECT_ERROR_MSG = _(
'Unable to connect to the internet while checking for Spyder updates.'
Copy link
Member

Choose a reason for hiding this comment

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

This should say something more like "Unable to connect to the Spyder update service." since this could be something specific to that site or due to a firewall, proxy, etc. issue rather than just internet connectivity

@mrclary
Copy link
Contributor Author

mrclary commented Oct 18, 2023

@CAM-Gerlach, I'm sorry, I should have requested a review from you as well. I'll submit a follow-up PR with your suggestions.

@CAM-Gerlach
Copy link
Member

No worries, I was away on my trip to the Python core dev sprint until yesterday, so I wasn't around anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants