-
Notifications
You must be signed in to change notification settings - Fork 40
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
Fix logic and message reported for version if inaccessible. #701
Conversation
This PR includes some handling of instances where pypi.org is offline or inaccessible. I also cleaned up some of the naming and introduced an exception dataclass to make handling this issue more clear. Also also, I removed the dependence on the six module to instead use the provided urllib urlopen method. Closes #700
Codecov Report
@@ Coverage Diff @@
## master #701 +/- ##
=======================================
Coverage 29.23% 29.24%
=======================================
Files 10 10
Lines 1245 1248 +3
Branches 184 185 +1
=======================================
+ Hits 364 365 +1
- Misses 858 860 +2
Partials 23 23
Continue to review full report at Codecov.
|
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.
I think reading installed version is less likely to every fail as it is already loaded in the memory and is available as an imported attribute, so no need to initialize it as None
. Moreover, we do not need to overload the function that checks for the latest version to also compare it with the installed version. Let's do it something like this:
def get_latest_version():
# Check PyPI online, parse the returned JSON, and return just the version number string
# In case of any exception, return None
def check_for_update():
latest = get_latest_version()
if not latest:
print("Failed to check for the latest version")
return
current = re.sub(r'\.0+', '.', ipwb_version)
if latest == current:
print(f"Installed version {current} is up to date")
else:
print("A new update is available\nRun `pip install --upgrade ipwb` to upgrade.")
print(f"Latest version: {latest}\nInstalled version: {current}")
ipwb/util.py
Outdated
return (currentVersion, latestVersion) | ||
except Exception as e: | ||
return (None, None) | ||
latest_version = jResp['info']['version'] |
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.
It is possible that the returned JSON data is empty or has an error, in that case, this nested attribute access might throw another exception and the control main fail to reach to the next return statement
.
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.
In this case, the exception will be handled by the caller, An unknown exception occurred
. Perhaps we could/should handle it more directly. Thoughts?
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.
And that will be printed to the user something like:
An unknown error occurred.
Some ugly JSON parsing error message...
Which would be of no use of their as they cannot fix it. That's why I proposed a rather simpler approach to this simple task.
Co-authored-by: Sawood Alam <[email protected]>
Can you submit this as a code improvement amending this PR? I agree with your cohesive improvement of getting the latest version for potential reuse elsewhere. We will still need to handle the scenario when the request to pypi fails, which is the crux of this PR/issue, and is implemented using an exception model not present in your proposal. |
Sure!
I did not illustrate that in a verbose manner, because I said it this way:
Which was an indication to reuse the code of loading and response parsing you already put in place. |
@github-actions run #! /bin/sh
export PS4="$ "
exec > comment.buffer 2>&1
echo "\`\`\`"
set -x
git checkout issue-700
pip install ./
ipwb -u
sed -i 's/2020/2019/' ipwb/__init__.py
pip install ./
ipwb -u
{ set +x; } 2>/dev/null
echo "\`\`\`" |
|
Well, the branch was deleted before I posted the above comment, but the code still worked. |
GitHub auto-deletes branches post-merge now. (even though it says that I deleted it) |
This PR includes some handling of instances where pypi.org
is offline or inaccessible. I also cleaned up some of the
naming and introduced an exception dataclass to make handling
this issue more clear. Also also, I removed the dependence
on the six module to instead use the provided urllib
urlopen method.
Closes #700