Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: LEAP-1650: pkg_resources deprecation problems for 3.12,3.13 #6638

Merged
merged 2 commits into from
Nov 13, 2024
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
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 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 @@
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(

Check warning on line 397 in label_studio/core/utils/common.py

View check run for this annotation

Codecov / codecov/patch

label_studio/core/utils/common.py#L396-L397

Added lines #L396 - L397 were not covered by tests
'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
53 changes: 29 additions & 24 deletions poetry.lock

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

5 changes: 3 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 All @@ -199,6 +199,7 @@ mysqlclient = {version = "*", optional = true}
django-csp = "3.7"
openai = "^1.10.0"
django-migration-linter = "^5.1.0"
setuptools = ">=75.4.0"

# Humansignal repo dependencies
label-studio-sdk = {url = "https://github.com/HumanSignal/label-studio-sdk/archive/ae9984e544732025caadf96d2d716c728dbbe014.zip"}
Expand Down
Loading