mirror of
https://github.com/gradio-app/gradio.git
synced 2025-01-30 11:00:11 +08:00
parent
8c9419fce1
commit
68afe67497
@ -67,5 +67,5 @@ from gradio.templates import (
|
||||
Webcam,
|
||||
)
|
||||
|
||||
current_pkg_version = pkgutil.get_data(__name__, "version.txt").decode('ascii').strip()
|
||||
current_pkg_version = pkgutil.get_data(__name__, "version.txt").decode("ascii").strip()
|
||||
__version__ = current_pkg_version
|
||||
|
@ -7,6 +7,7 @@ import inspect
|
||||
import json
|
||||
import json.decoder
|
||||
import os
|
||||
import pkgutil
|
||||
import random
|
||||
import sys
|
||||
import warnings
|
||||
@ -38,7 +39,9 @@ JSON_PATH = os.path.join(os.path.dirname(gradio.__file__), "launches.json")
|
||||
|
||||
def version_check():
|
||||
try:
|
||||
current_pkg_version = pkg_resources.require("gradio")[0].version
|
||||
current_pkg_version = (
|
||||
pkgutil.get_data(__name__, "version.txt").decode("ascii").strip()
|
||||
)
|
||||
latest_pkg_version = requests.get(url=PKG_VERSION_URL).json()["version"]
|
||||
if StrictVersion(latest_pkg_version) > StrictVersion(current_pkg_version):
|
||||
print(
|
||||
@ -49,10 +52,6 @@ def version_check():
|
||||
)
|
||||
)
|
||||
print("--------")
|
||||
except pkg_resources.DistributionNotFound:
|
||||
warnings.warn(
|
||||
"gradio is not setup or installed properly. Unable to get version info."
|
||||
)
|
||||
except json.decoder.JSONDecodeError:
|
||||
warnings.warn("unable to parse version details from package URL.")
|
||||
except KeyError:
|
||||
|
@ -37,18 +37,6 @@ os.environ["GRADIO_ANALYTICS_ENABLED"] = "False"
|
||||
|
||||
|
||||
class TestUtils(unittest.TestCase):
|
||||
@mock.patch("pkg_resources.require")
|
||||
def test_should_fail_with_distribution_not_found(self, mock_require):
|
||||
mock_require.side_effect = pkg_resources.DistributionNotFound()
|
||||
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
warnings.simplefilter("always")
|
||||
version_check()
|
||||
self.assertEqual(
|
||||
str(w[-1].message),
|
||||
"gradio is not setup or installed properly. Unable to get version info.",
|
||||
)
|
||||
|
||||
@mock.patch("requests.get")
|
||||
def test_should_warn_with_unable_to_parse(self, mock_get):
|
||||
mock_get.side_effect = json.decoder.JSONDecodeError("Expecting value", "", 0)
|
||||
|
Loading…
Reference in New Issue
Block a user