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

Version warning #327

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Changes from 2 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
19 changes: 18 additions & 1 deletion openeo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,28 @@ class BaseOpenEoException(Exception):
from openeo.rest.connection import connect, session, Connection
from openeo.rest.job import BatchJob, RESTJob
from openeo.internal.graph_building import UDF

import requests
import warnings

def client_version() -> str:
try:
import importlib.metadata
return importlib.metadata.version("openeo")
except Exception:
return __version__

def check_if_latest_version():
try:
package = 'openeo'
response = requests.get(f'https://pypi.org/pypi/{package}/json')
Copy link
Member

Choose a reason for hiding this comment

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

I think we should put a timeout here of just a couple of seconds so that users are not blocked to do import openeo when pypi is slow

Copy link
Member

Choose a reason for hiding this comment

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

I also think we should do this check like once a day, or cache the pypi.org response

Copy link
Member

Choose a reason for hiding this comment

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

for example, the pip implementation is roughly contained here: https://github.com/pypa/pip/blob/main/src/pip/_internal/self_outdated_check.py
apparently the check frequency is once a week there

Copy link
Member Author

Choose a reason for hiding this comment

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

I've added the timeout. The pip implementation using the cache would require some more time to be ported over.

latest_version = response.json()['info']['version']
except:
# Probably no internet connection available, pass
return
installed_version = client_version()
if latest_version != client_version():
clausmichele marked this conversation as resolved.
Show resolved Hide resolved
warnings.warn(f'You are using {package} version {installed_version}; however, version {latest_version} is available. You should consider upgrading via the \'pip install --upgrade {package}\' command.', Warning)
return

check_if_latest_version()