Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
entry_points={
"console_scripts": ["submit50=submit50.__main__:main"]
},
version="3.2.0",
version="3.2.1",
include_package_data=True
)
34 changes: 24 additions & 10 deletions submit50/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,35 @@ def check_announcements():
raise Error(res.text.strip())


def check_version():
"""Check that submit50 is the latest version according to submit50.io."""
def check_version(package_name=__package__, timeout=5):
"""Check that submit50 is the latest version according to submit.cs50.io and PyPI."""
if not __version__:
return

# Retrieve version info
res = requests.get(f"{SUBMIT_URL}/versions/submit50")
res = requests.get(f"{SUBMIT_URL}/versions/submit50", timeout=timeout)
if res.status_code != 200:
raise Error(_("You have an unknown version of submit50. "
raise Error(_("Could not connect to submit.cs50.io."
"Please visit our status page https://cs50.statuspage.io for more information."))

# Check that latest version == version installed
required_version = version.parse(res.text.strip())
local_version = version.parse(__version__)
# Get the minimum required version from submit.cs50.io
latest_io = version.parse(res.text.strip())
current = version.parse(__version__)

# Get PyPI version
latest_pypi = max(
requests.get(f"https://pypi.org/pypi/{package_name}/json", timeout=timeout).json()["releases"],
key=version.parse
)
latest_pypi = version.parse(latest_pypi)

# Check for minimum requirement
if current < latest_io:
raise Error(_(f"Current version {current} of {package_name} is no longer supported. Run \"pip3 install --upgrade {package_name}\" now to upgrade."))

if required_version > local_version:
raise Error(_("You have an outdated version of submit50. "
"Please upgrade."))
# Check for latest version
if latest_pypi > current:
cprint(f"A newer version of {package_name} is available. Run \"pip3 install --upgrade {package_name}\" now to upgrade.", "magenta")


def setup_logging(level):
Expand Down
Loading