Skip to content

Commit

Permalink
Add upgrade instruction for users with outdated ASReview versions (#1590
Browse files Browse the repository at this point in the history
)
  • Loading branch information
J535D165 committed Nov 21, 2023
1 parent a793b06 commit 0dc0098
Showing 1 changed file with 36 additions and 6 deletions.
42 changes: 36 additions & 6 deletions asreview/webapp/entry_points/lab.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@
import logging
import os
import socket
import time
import webbrowser
from threading import Timer

import requests
from gevent.pywsgi import WSGIServer

from asreview import __version__
from asreview._deprecated import DeprecateAction
from asreview._deprecated import mark_deprecated_help_strings
from asreview.project import ASReviewProject
Expand Down Expand Up @@ -47,21 +50,37 @@ def _deprecated_dev_mode():


def _check_port_in_use(host, port):

logging.info(f"Checking if host and port are available :: {host}:{port}")
host = host.replace("https://", "").replace("http://", "")
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
return s.connect_ex((host, port)) == 0


def _open_browser(start_url):

Timer(1, lambda: webbrowser.open_new(start_url)).start()

print(
"\n\n\n\nIf your browser doesn't open. "
f"Navigate to {start_url}\n\n\n\n"
)
print("\n\n\n\nIf your browser doesn't open. " f"Navigate to {start_url}\n\n\n\n")


def _check_for_update():
"""Check if there is an update available."""

try:
r = requests.get("https://pypi.org/pypi/asreview/json")
r.raise_for_status()
latest_version = r.json()["info"]["version"]
if latest_version != __version__ and "+" not in __version__:
print(
"\n\n\n"
f"ASReview LAB version {latest_version} is available. "
"Please update using:\n"
"pip install --upgrade asreview"
"\n\n\n"
)

time.sleep(5)
except Exception:
print("Could not check for updates.")


def lab_entry_point(argv):
Expand All @@ -72,6 +91,10 @@ def lab_entry_point(argv):
mark_deprecated_help_strings(parser)
args = parser.parse_args(argv)

# check for update
if not args.skip_update_check:
_check_for_update()

app = create_app(
env="production",
config_file=args.flask_config_file,
Expand Down Expand Up @@ -239,4 +262,11 @@ def _lab_parser():
help="The full path to a private key file for usage with SSL/TLS.",
)

parser.add_argument(
"--skip-update-check",
dest="skip_update_check",
action="store_true",
help="Skip checking for updates.",
)

return parser

0 comments on commit 0dc0098

Please sign in to comment.