-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
68 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
""" | ||
Functions for checking current version of the Scribe-Data CLI. | ||
.. raw:: html | ||
<!-- | ||
* Copyright (C) 2024 Scribe | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
--> | ||
""" | ||
|
||
import pkg_resources | ||
import requests | ||
|
||
|
||
def get_local_version(): | ||
try: | ||
return pkg_resources.get_distribution("scribe-data").version | ||
except pkg_resources.DistributionNotFound: | ||
return "Unknown (Not installed via pip)" | ||
|
||
|
||
def get_latest_version(): | ||
try: | ||
response = requests.get( | ||
"https://api.github.com/repos/scribe-org/Scribe-Data/releases/latest" | ||
) | ||
version = response.json()["name"] | ||
return version | ||
except Exception: | ||
return "Unknown (Unable to fetch version)" | ||
|
||
|
||
def get_version_message(): | ||
local_version = "Scribe-Data v" + get_local_version() | ||
latest_version = get_latest_version() | ||
|
||
if ( | ||
local_version == "Unknown (Not installed via pip)" | ||
or latest_version == "Unknown (Unable to fetch version)" | ||
): | ||
return f"{local_version}" | ||
|
||
if local_version == latest_version: | ||
return f"{local_version}" | ||
else: | ||
update_message = ( | ||
f"Scribe-Data v{local_version} (Update available: v{latest_version})\n" | ||
) | ||
update_message += "To update, run: pip scribe-data --upgrade" | ||
return update_message |