Skip to content

Commit

Permalink
fix pkg_resources deprecation problems for 3.12,3.13
Browse files Browse the repository at this point in the history
  • Loading branch information
jombooth committed Nov 12, 2024
1 parent fbe0863 commit 1683709
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 32 deletions.
18 changes: 7 additions & 11 deletions label_studio/core/utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import calendar
import contextlib
import copy
import importlib
import logging
import os
import random
Expand All @@ -18,11 +19,9 @@
from typing import Any, Callable, Generator, Iterable, Mapping, Optional

import drf_yasg.openapi as openapi
import pkg_resources
import pytz
import requests
import ujson as json
from boxing import boxing
from colorama import Fore
from core.utils.params import get_env
from django.conf import settings
Expand All @@ -49,7 +48,8 @@
from label_studio_sdk._extensions.label_studio_tools.core.utils.exceptions import (
LabelStudioXMLSyntaxErrorSentryIgnored,
)
from pkg_resources import parse_version
from packaging.version import parse as parse_version
from pyboxen import boxen
from rest_framework import status
from rest_framework.exceptions import ErrorDetail
from rest_framework.views import Response, exception_handler
Expand Down Expand Up @@ -350,11 +350,7 @@ def f_retry(*args, **kwargs):


def get_app_version():
version = pkg_resources.get_distribution('label-studio').version
if isinstance(version, str):
return version
elif isinstance(version, dict):
return version.get('version') or version.get('latest_version')
return importlib.metadata.version('label-studio')


def get_latest_version():
Expand Down Expand Up @@ -397,13 +393,13 @@ def check_for_the_latest_version(print_message):
outdated = latest_version and current_version_is_outdated(latest_version)

def update_package_message():
update_command = Fore.CYAN + 'pip install -U ' + label_studio.package_name + Fore.RESET
return boxing(
update_command = 'pip install -U ' + label_studio.package_name
return boxen(
'Update available {curr_version} → {latest_version}\nRun {command}'.format(
curr_version=label_studio.__version__, latest_version=latest_version, command=update_command
),
style='double',
)
).replace(update_command, Fore.CYAN + update_command + Fore.RESET)

if outdated and print_message:
print(update_package_message())
Expand Down
4 changes: 2 additions & 2 deletions label_studio/core/utils/io.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""This file and its contents are licensed under the Apache License 2.0. Please see the included NOTICE for copyright information and LICENSE for a copy of the license.
"""
import glob
import importlib
import io
import ipaddress
import itertools
Expand All @@ -10,7 +11,6 @@
from contextlib import contextmanager
from tempfile import mkdtemp, mkstemp

import pkg_resources
import requests
import ujson as json
import yaml
Expand All @@ -31,7 +31,7 @@ def good_path(path):

def find_node(package_name, node_path, node_type):
assert node_type in ('dir', 'file', 'any')
basedir = pkg_resources.resource_filename(package_name, '')
basedir = importlib.resources.files(package_name).joinpath('')
node_path = os.path.join(*node_path.split('/')) # linux to windows compatibility
search_by_path = '/' in node_path or '\\' in node_path

Expand Down
36 changes: 19 additions & 17 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ django-ranged-fileresponse = ">=0.1.2"
drf-dynamic-fields = "0.3.0"
djangorestframework = "3.15.2"
drf-flex-fields = "0.9.5"
humansignal-drf-yasg = ">=1.21.9"
humansignal-drf-yasg = ">=1.21.10.post1"
drf-generators = "0.3.0"
lockfile = ">=0.12.0"
lxml = {extras = ["html_clean"], version = ">=4.9.4"}
Expand All @@ -188,7 +188,7 @@ rules = "3.4"
ujson = ">=3.0.0"
xmljson = "0.2.1"
colorama = ">=0.4.4"
boxing = ">=0.1.4"
pyboxen = ">=1.3.0"
redis = "~=3.5"
sentry-sdk = ">=2.16.0"
launchdarkly-server-sdk = "8.2.1"
Expand Down

0 comments on commit 1683709

Please sign in to comment.