Skip to content

Commit

Permalink
gui version check
Browse files Browse the repository at this point in the history
  • Loading branch information
sronilsson committed Feb 18, 2025
1 parent fd7e0a8 commit 037a6b5
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 24 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
# Setup configuration
setuptools.setup(
name="simba_uw_tf_dev",
version="2.7.1",
version="2.7.2",
author="Simon Nilsson, Jia Jie Choong, Sophia Hwang",
author_email="[email protected]",
description="Toolkit for computer classification and analysis of behaviors in experimental animals",
Expand Down
20 changes: 12 additions & 8 deletions simba/SimBA.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
__author__ = "Simon Nilsson"

import os.path
import time
import warnings

warnings.filterwarnings("ignore", category=FutureWarning)
Expand All @@ -23,8 +24,7 @@

from simba.bounding_box_tools.boundary_menus import BoundaryMenus
from simba.cue_light_tools.cue_light_menues import CueLightAnalyzerMenu
from simba.labelling.labelling_advanced_interface import \
select_labelling_video_advanced
from simba.labelling.labelling_advanced_interface import select_labelling_video_advanced
from simba.labelling.labelling_interface import select_labelling_video
from simba.labelling.targeted_annotations_clips import \
select_labelling_video_targeted_clips
Expand Down Expand Up @@ -158,17 +158,15 @@
FileSelect, SimbaButton, SimBALabel,
hxtScrollbar)
from simba.ui.video_info_ui import VideoInfoTable
from simba.utils.checks import (check_ffmpeg_available,
check_file_exist_and_readable, check_int)
from simba.utils.checks import (check_ffmpeg_available, check_file_exist_and_readable, check_int)
from simba.utils.custom_feature_extractor import CustomFeatureExtractor
from simba.utils.enums import (OS, Defaults, Formats, Keys, Links, Paths,
TagNames)
from simba.utils.errors import InvalidInputError
from simba.utils.lookups import (get_bp_config_code_class_pairs, get_emojis,
get_icons_paths, load_simba_fonts)
from simba.utils.lookups import (get_bp_config_code_class_pairs, get_emojis, get_icons_paths, load_simba_fonts)
from simba.utils.printing import stdout_success, stdout_warning
from simba.utils.read_write import find_core_cnt, get_video_meta_data
from simba.utils.warnings import FFMpegNotFoundWarning, PythonVersionWarning
from simba.utils.read_write import find_core_cnt, get_video_meta_data, fetch_pip_data
from simba.utils.warnings import FFMpegNotFoundWarning, PythonVersionWarning, VersionWarning
from simba.video_processors.video_processing import \
extract_frames_from_all_videos_in_directory

Expand Down Expand Up @@ -961,6 +959,12 @@ def __init__(self):
if not check_ffmpeg_available():
FFMpegNotFoundWarning(msg='SimBA could not find a FFMPEG installation on computer (as evaluated by "ffmpeg" returning None). SimBA works best with FFMPEG and it is recommended to install it on your computer', source=self.__class__.__name__)

simba_pip_data = fetch_pip_data(pip_url=Links.SIMBA_PIP_URL.value)
if (simba_pip_data[1] is not None) and OS.SIMBA_VERSION.value is not None:
if simba_pip_data[1] != OS.SIMBA_VERSION.value:
msg = f"A new version of SimBA is available: {simba_pip_data[1]} (you have version {OS.SIMBA_VERSION.value}). Consider upgrading using: pip install simba-uw-tf-dev --upgrade"
VersionWarning(msg=msg)

def restart(self):
confirm_restart = askyesno(title="RESTART", message="Are you sure that you want restart SimBA?")
if confirm_restart:
Expand Down
12 changes: 12 additions & 0 deletions simba/utils/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,18 @@ def check_valid_hex_color(color_hex: str, raise_error: Optional[bool] = True) ->
else:
return True

def check_valid_url(url: str) -> bool:
""" Helper to check if a string is a valid url"""
regex = re.compile(
r'^(https?|ftp)://' # protocol
r'(\S+(:\S*)?@)?' # user:password (optional)
r'((\d{1,3}\.){3}\d{1,3}|' # IP address
r'([a-zA-Z0-9.-]+\.[a-zA-Z]{2,}))' # domain name
r'(:\d+)?' # port (optional)
r'(/[\S]*)?$', # path (optional)
re.IGNORECASE)
return re.match(regex, url) is not None


def check_if_2d_array_has_min_unique_values(data: np.ndarray, min: int) -> bool:
"""
Expand Down
7 changes: 5 additions & 2 deletions simba/utils/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import cv2
import numpy as np
import pkg_resources

import simba


Expand Down Expand Up @@ -119,6 +118,10 @@ class OS(Enum):
LINUX = "Linux"
MAC = "Darwin"
PYTHON_VER = str(f"{sys.version_info.major}.{sys.version_info.minor}")
try:
SIMBA_VERSION = pkg_resources.get_distribution("simba-uw-tf-dev").version
except pkg_resources.DistributionNotFound:
SIMBA_VERSION = None

class FontPaths(Enum):
POPPINS_REGULAR = Path("assets/fonts/Poppins Regular.ttf")
Expand Down Expand Up @@ -591,7 +594,7 @@ class Links(Enum):
COUNT_ANNOTATIONS_IN_PROJECT = "https://github.com/sgoldenlab/simba/blob/master/docs/label_behavior.md#count-annotations-in-simba-project"
COUNT_ANNOTATIONS_OUTSIDE_PROJECT = "https://github.com/sgoldenlab/simba/blob/master/docs/Tutorial_tools.md#extract-project-annotation-counts"
CIRCLE_CROP = "https://github.com/sgoldenlab/simba/blob/master/docs/Tutorial_tools.md#circle-crop"

SIMBA_PIP_URL = 'https://pypi.org/pypi/simba-uw-tf-dev/json'

class Labelling(Enum):
PADDING = 5
Expand Down
8 changes: 3 additions & 5 deletions simba/utils/lookups.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import re
import struct
import sys
import json
import urllib
from multiprocessing import Lock, Value
from pathlib import Path
from typing import Dict, List, Tuple, Union
Expand All @@ -16,8 +18,7 @@
from matplotlib import cm

import simba
from simba.utils.checks import (check_file_exist_and_readable,
check_if_dir_exists)
from simba.utils.checks import (check_file_exist_and_readable, check_if_dir_exists)
from simba.utils.enums import OS, UML, FontPaths, Methods, Paths
from simba.utils.read_write import get_fn_ext
from simba.utils.warnings import NoDataFoundWarning
Expand Down Expand Up @@ -673,9 +674,6 @@ def get_model_names():
return list(pd.read_parquet(model_names_dir)[UML.NAMES.value])





#
# def rao_spacing_critical_values():
# {4.0: 186.45,
Expand Down
32 changes: 24 additions & 8 deletions simba/utils/read_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
from typing_extensions import Literal

from urllib.parse import urlparse
from urllib import request


import cv2
import numpy as np
Expand All @@ -37,8 +39,7 @@
import pyarrow as pa
from numba import njit, prange
from pyarrow import csv
from shapely.geometry import (LineString, MultiLineString, MultiPolygon, Point,
Polygon)
from shapely.geometry import (LineString, MultiLineString, MultiPolygon, Point, Polygon)

import simba
from simba.utils.checks import (check_file_exist_and_readable, check_float,
Expand All @@ -50,8 +51,8 @@
check_int, check_nvidea_gpu_available,
check_str, check_valid_array,
check_valid_boolean, check_valid_dataframe,
check_valid_lst, is_video_color)
from simba.utils.enums import ConfigKey, Dtypes, Formats, Keys, Options, Paths
check_valid_lst, is_video_color, check_valid_url)
from simba.utils.enums import ConfigKey, Dtypes, Formats, Keys, Options, Paths, Links
from simba.utils.errors import (DataHeaderError, DuplicationError,
FFMPEGCodecGPUError, FileExistError,
FrameRangeError, IntegerError,
Expand All @@ -61,10 +62,7 @@
NoFilesFoundError, NotDirectoryError,
ParametersFileError, PermissionError)
from simba.utils.printing import SimbaTimer, stdout_success
from simba.utils.warnings import (
FileExistWarning, FrameRangeWarning, InvalidValueWarning,
NoDataFoundWarning, NoFileFoundWarning,
ThirdPartyAnnotationsInvalidFileFormatWarning)
from simba.utils.warnings import (FileExistWarning, FrameRangeWarning, InvalidValueWarning, NoFileFoundWarning, ThirdPartyAnnotationsInvalidFileFormatWarning)

SIMBA_DIR = os.path.dirname(simba.__file__)

Expand Down Expand Up @@ -1776,6 +1774,24 @@ def get_pkg_version(pkg: str):
except pkg_resources.DistributionNotFound:
return None

def fetch_pip_data(pip_url: str = Links.SIMBA_PIP_URL.value) -> Union[Tuple[Dict[str, Any], str], Tuple[None, None]]:
""" Helper to fetch the pypi data associated with a package """
if check_valid_url(url=pip_url):
try:
opener = request.build_opener(request.HTTPHandler(), request.HTTPSHandler())
with opener.open(pip_url, timeout=2) as response:
if response.status == 200:
encoding = response.info().get_content_charset("utf-8")
data = response.read().decode(encoding)
json_data = json.loads(data)
latest_release = json_data.get("info", {}).get("version", "")
return json_data, latest_release
except Exception as e:
#print(e.args)
return None, None
else:
return None, None


def write_pickle(data: Dict[str, Any], save_path: Union[str, os.PathLike]) -> None:
"""
Expand Down
4 changes: 4 additions & 0 deletions simba/utils/warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,7 @@ def ResolutionWarning(msg: str, source: str = ""):
@log_warning
def GPUToolsWarning(msg: str, source: str = ""):
pass

@log_warning
def VersionWarning(msg: str, source: str = ""):
pass

0 comments on commit 037a6b5

Please sign in to comment.