This repository has been archived by the owner on Aug 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updater: Add a utility to auto-update
In the process of updating zygrader to a package, it will be nice to automatically update if new versions exists. This provides the ability to do so.
- Loading branch information
1 parent
17346bb
commit 4028a52
Showing
3 changed files
with
49 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
"""Updater: To auto-update zygrader during runtime""" | ||
import requests | ||
import subprocess | ||
import sys | ||
|
||
from . import config | ||
|
||
REPO_NAME = "natecraddock/zygrader" | ||
API_URL = f"https://api.github.com/repos/{REPO_NAME}/tags" | ||
INSTALL_URL = f"https://github.com/{REPO_NAME}/tarball/master" | ||
|
||
def get_latest_version(): | ||
"""Check the zygrader git repo tags for a new version""" | ||
r = requests.get(API_URL) | ||
if not r.ok: | ||
return config.g_data.VERSION | ||
|
||
latest = float(r.json()[0]["name"]) | ||
if latest > config.g_data.VERSION: | ||
return latest | ||
|
||
return config.g_data.VERSION | ||
|
||
def update_zygrader(latest_version): | ||
"""Download zygrader from the git repository and update it""" | ||
print() | ||
print(f"Updating zygrader [{config.g_data.VERSION} -> {latest_version}]") | ||
print() | ||
|
||
# Install the new version of zygrader | ||
try: | ||
subprocess.check_call([sys.executable, "-m", "pip", "install", "--upgrade", INSTALL_URL]) | ||
except subprocess.CalledProcessError: | ||
print("Failed to update zygrader. Exiting") | ||
print() | ||
return | ||
|
||
# zygrader updated properly, fork and run zygrader again | ||
# TODO: Update here once zygrader is a package |