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
16 changes: 15 additions & 1 deletion deeplabcut/gui/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
#
# Licensed under GNU Lesser General Public License v3.0
#
from typing import Tuple

from PySide6 import QtCore
import re


class Worker(QtCore.QObject):
Expand Down Expand Up @@ -38,6 +41,17 @@ def stop_thread():
return worker, thread


def parse_version(version: str) -> Tuple[int, int, int]:
"""
Parses a version string into a tuple of (major, minor, patch).
"""
match = re.search(r"(\d+)\.(\d+)\.(\d+)", version)
if match:
return tuple(int(part) for part in match.groups())
else:
raise ValueError(f"Invalid version format: {version}")


def is_latest_deeplabcut_version():
import json
import urllib.request
Expand All @@ -46,4 +60,4 @@ def is_latest_deeplabcut_version():
url = "https://pypi.org/pypi/deeplabcut/json"
contents = urllib.request.urlopen(url).read()
latest_version = json.loads(contents)["info"]["version"]
return VERSION == latest_version, latest_version
return parse_version(VERSION) >= parse_version(latest_version), latest_version
17 changes: 14 additions & 3 deletions deeplabcut/gui/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from pathlib import Path
from typing import List
from urllib.error import URLError
from concurrent.futures import ThreadPoolExecutor, TimeoutError
import qdarkstyle

import deeplabcut
Expand All @@ -40,11 +41,21 @@
from PySide6.QtCore import Qt, QTimer


def call_with_timeout(func, timeout, *args, **kwargs):
with ThreadPoolExecutor(max_workers=1) as executor:
future = executor.submit(func, *args, **kwargs)
return future.result(timeout=timeout)


def _check_for_updates(silent=True):
try:
is_latest, latest_version = utils.is_latest_deeplabcut_version()
is_latest_plugin, latest_plugin_version = misc.is_latest_version()
except URLError: # Handle internet connectivity issues
is_latest, latest_version = call_with_timeout(
utils.is_latest_deeplabcut_version, 1
)
is_latest_plugin, latest_plugin_version = call_with_timeout(
misc.is_latest_version, 1
)
except (URLError, TimeoutError): # Handle internet connectivity issues
is_latest = is_latest_plugin = True

if is_latest and is_latest_plugin:
Expand Down