@@ -60,21 +60,35 @@ def check_announcements():
6060 raise Error (res .text .strip ())
6161
6262
63- def check_version ():
64- """Check that submit50 is the latest version according to submit50.io."""
63+ def check_version (package_name = __package__ , timeout = 5 ):
64+ """Check that submit50 is the latest version according to submit.cs50.io and PyPI."""
65+ if not __version__ :
66+ return
67+
6568 # Retrieve version info
66- res = requests .get (f"{ SUBMIT_URL } /versions/submit50" )
69+ res = requests .get (f"{ SUBMIT_URL } /versions/submit50" , timeout = timeout )
6770 if res .status_code != 200 :
68- raise Error (_ ("You have an unknown version of submit50. "
71+ raise Error (_ ("Could not connect to submit.cs50.io. "
6972 "Please visit our status page https://cs50.statuspage.io for more information." ))
7073
71- # Check that latest version == version installed
72- required_version = version .parse (res .text .strip ())
73- local_version = version .parse (__version__ )
74+ # Get the minimum required version from submit.cs50.io
75+ latest_io = version .parse (res .text .strip ())
76+ current = version .parse (__version__ )
77+
78+ # Get PyPI version
79+ latest_pypi = max (
80+ requests .get (f"https://pypi.org/pypi/{ package_name } /json" , timeout = timeout ).json ()["releases" ],
81+ key = version .parse
82+ )
83+ latest_pypi = version .parse (latest_pypi )
84+
85+ # Check for minimum requirement
86+ if current < latest_io :
87+ raise Error (_ (f"Current version { current } of { package_name } is no longer supported. Run \" pip3 install --upgrade { package_name } \" now to upgrade." ))
7488
75- if required_version > local_version :
76- raise Error ( _ ( "You have an outdated version of submit50. "
77- "Please upgrade.") )
89+ # Check for latest version
90+ if latest_pypi > current :
91+ cprint ( f"A newer version of { package_name } is available. Run \" pip3 install --upgrade { package_name } \" now to upgrade.", "magenta" )
7892
7993
8094def setup_logging (level ):
0 commit comments