Skip to content

Commit

Permalink
Remove dependency on distutils module (cvat-ai#7318)
Browse files Browse the repository at this point in the history
The distutils module is [deprecated](https://peps.python.org/pep-0632)
and will be removed from the standard library in Python 3.12.
  • Loading branch information
Marishka17 authored Jan 9, 2024
1 parent 64d6d7a commit 9b99f6a
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 29 deletions.
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ RUN apt-get update && \
p7zip-full \
poppler-utils \
python3 \
python3-distutils \
python3-venv \
supervisor \
tzdata \
Expand Down
6 changes: 3 additions & 3 deletions cvat-cli/src/cvat_cli/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
import logging
import os
import textwrap
from distutils.util import strtobool
from pathlib import Path
from typing import Any, Tuple

from attr.converters import to_bool
from cvat_sdk.core.proxies.tasks import ResourceType

from .version import VERSION
Expand Down Expand Up @@ -60,7 +60,7 @@ def parse_function_parameter(s: str) -> Tuple[str, Any]:
elif type_ == "str":
pass
elif type_ == "bool":
value = bool(strtobool(value))
value = to_bool(value)
else:
raise argparse.ArgumentTypeError(f"unsupported parameter type {type_!r}")

Expand Down Expand Up @@ -339,7 +339,7 @@ def make_cmdline_parser() -> argparse.ArgumentParser:
)
dump_parser.add_argument(
"--with-images",
type=strtobool,
type=to_bool,
default=False,
dest="include_images",
help="Whether to include images or not (default: %(default)s)",
Expand Down
4 changes: 2 additions & 2 deletions cvat/apps/engine/backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from tempfile import NamedTemporaryFile

import django_rq
from attr.converters import to_bool
from django.conf import settings
from django.db import transaction
from django.utils import timezone
Expand All @@ -26,7 +27,6 @@
from rest_framework.renderers import JSONRenderer
from rest_framework.response import Response
from rest_framework.exceptions import ValidationError, PermissionDenied, NotFound
from distutils.util import strtobool

import cvat.apps.dataset_manager as dm
from cvat.apps.engine import models
Expand Down Expand Up @@ -944,7 +944,7 @@ def export(db_instance, request, queue_name):
else:
raise Exception(
"Unexpected type of db_instance: {}".format(type(db_instance)))
use_settings = strtobool(str(use_target_storage_conf))
use_settings = to_bool(use_target_storage_conf)
obj = db_instance if use_settings else request.query_params
location_conf = get_location_configuration(
obj=obj,
Expand Down
8 changes: 4 additions & 4 deletions cvat/apps/engine/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
import os.path
import uuid
from dataclasses import asdict, dataclass
from distutils.util import strtobool
from pathlib import Path
from tempfile import NamedTemporaryFile
from unittest import mock

import django_rq
from attr.converters import to_bool
from django.conf import settings
from rest_framework import mixins, status
from rest_framework.response import Response
Expand Down Expand Up @@ -390,7 +390,7 @@ def export_annotations(self, request, db_obj, export_func, callback, get_data=No
filename = request.query_params.get("filename", "")

use_default_location = request.query_params.get("use_default_location", True)
use_settings = strtobool(str(use_default_location))
use_settings = to_bool(use_default_location)
obj = db_obj if use_settings else request.query_params
location_conf = get_location_configuration(
obj=obj,
Expand Down Expand Up @@ -425,8 +425,8 @@ def import_annotations(self, request, db_obj, import_func, rq_func, rq_id_templa
return self.init_tus_upload(request)

use_default_location = request.query_params.get('use_default_location', True)
conv_mask_to_poly = strtobool(request.query_params.get('conv_mask_to_poly', 'True'))
use_settings = strtobool(str(use_default_location))
conv_mask_to_poly = to_bool(request.query_params.get('conv_mask_to_poly', True))
use_settings = to_bool(use_default_location)
obj = db_obj if use_settings else request.query_params
location_conf = get_location_configuration(
obj=obj,
Expand Down
3 changes: 1 addition & 2 deletions cvat/apps/engine/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import rq
import re
import shutil
from distutils.dir_util import copy_tree
from urllib import parse as urlparse
from urllib import request as urlrequest
import django_rq
Expand Down Expand Up @@ -98,7 +97,7 @@ def _copy_data_from_share_point(
source_path = os.path.join(server_dir, os.path.normpath(path))
target_path = os.path.join(upload_dir, path)
if os.path.isdir(source_path):
copy_tree(source_path, target_path)
shutil.copytree(source_path, target_path)
else:
target_dir = os.path.dirname(target_path)
if not os.path.exists(target_dir):
Expand Down
20 changes: 10 additions & 10 deletions cvat/apps/engine/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
import textwrap
from copy import copy
from datetime import datetime
from distutils.util import strtobool
from tempfile import NamedTemporaryFile
from textwrap import dedent

import django_rq
from attr.converters import to_bool
from django.conf import settings
from django.contrib.auth.models import User
from django.db import IntegrityError, transaction
Expand Down Expand Up @@ -197,8 +197,8 @@ def annotation_formats(request):
def plugins(request):
data = {
'GIT_INTEGRATION': False, # kept for backwards compatibility
'ANALYTICS': strtobool(os.environ.get("CVAT_ANALYTICS", '0')),
'MODELS': strtobool(os.environ.get("CVAT_SERVERLESS", '0')),
'ANALYTICS': to_bool(os.environ.get("CVAT_ANALYTICS", False)),
'MODELS': to_bool(os.environ.get("CVAT_SERVERLESS", False)),
'PREDICT': False, # FIXME: it is unused anymore (for UI only)
}
return Response(PluginsSerializer(data).data)
Expand Down Expand Up @@ -418,7 +418,7 @@ def upload_finished(self, request):
if self.action == 'dataset':
format_name = request.query_params.get("format", "")
filename = request.query_params.get("filename", "")
conv_mask_to_poly = strtobool(request.query_params.get('conv_mask_to_poly', 'True'))
conv_mask_to_poly = to_bool(request.query_params.get('conv_mask_to_poly', True))
tmp_dir = self._object.get_tmp_dirname()
uploaded_file = None
if os.path.isfile(os.path.join(tmp_dir, filename)):
Expand Down Expand Up @@ -999,7 +999,7 @@ def upload_finished(self, request):
def _handle_upload_annotations(request):
format_name = request.query_params.get("format", "")
filename = request.query_params.get("filename", "")
conv_mask_to_poly = strtobool(request.query_params.get('conv_mask_to_poly', 'True'))
conv_mask_to_poly = to_bool(request.query_params.get('conv_mask_to_poly', True))
tmp_dir = self._object.get_tmp_dirname()
if os.path.isfile(os.path.join(tmp_dir, filename)):
annotation_file = os.path.join(tmp_dir, filename)
Expand Down Expand Up @@ -1353,8 +1353,8 @@ def annotations(self, request, pk):
format_name = request.query_params.get('format', '')
if format_name:
# NOTE: continue process of import annotations
use_settings = strtobool(str(request.query_params.get('use_default_location', True)))
conv_mask_to_poly = strtobool(request.query_params.get('conv_mask_to_poly', 'True'))
use_settings = to_bool(request.query_params.get('use_default_location', True))
conv_mask_to_poly = to_bool(request.query_params.get('conv_mask_to_poly', True))
obj = self._object if use_settings else request.query_params
location_conf = get_location_configuration(
obj=obj, use_settings=use_settings, field_name=StorageType.SOURCE
Expand Down Expand Up @@ -1639,7 +1639,7 @@ def upload_finished(self, request):
if self.action == 'annotations':
format_name = request.query_params.get("format", "")
filename = request.query_params.get("filename", "")
conv_mask_to_poly = strtobool(request.query_params.get('conv_mask_to_poly', 'True'))
conv_mask_to_poly = to_bool(request.query_params.get('conv_mask_to_poly', True))
tmp_dir = self.get_upload_dir()
if os.path.isfile(os.path.join(tmp_dir, filename)):
annotation_file = os.path.join(tmp_dir, filename)
Expand Down Expand Up @@ -1791,8 +1791,8 @@ def annotations(self, request, pk):
elif request.method == 'PUT':
format_name = request.query_params.get('format', '')
if format_name:
use_settings = strtobool(str(request.query_params.get('use_default_location', True)))
conv_mask_to_poly = strtobool(request.query_params.get('conv_mask_to_poly', 'True'))
use_settings = to_bool(request.query_params.get('use_default_location', True))
conv_mask_to_poly = to_bool(request.query_params.get('conv_mask_to_poly', True))
obj = self._object.segment.task if use_settings else request.query_params
location_conf = get_location_configuration(
obj=obj, use_settings=use_settings, field_name=StorageType.SOURCE
Expand Down
4 changes: 2 additions & 2 deletions cvat/apps/iam/apps.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from distutils.util import strtobool
import os
from attr.converters import to_bool
from django.apps import AppConfig

from .utils import create_opa_bundle
Expand All @@ -11,5 +11,5 @@ def ready(self):
from .signals import register_signals
register_signals(self)

if strtobool(os.environ.get("IAM_OPA_BUNDLE", '0')):
if to_bool(os.environ.get("IAM_OPA_BUNDLE", False)):
create_opa_bundle()
4 changes: 2 additions & 2 deletions cvat/apps/organizations/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#
# SPDX-License-Identifier: MIT

from attr.converters import to_bool
from django.contrib.auth import get_user_model
from allauth.account.models import EmailAddress
from django.core.exceptions import ObjectDoesNotExist
Expand All @@ -11,7 +12,6 @@
from django.db import transaction

from rest_framework import serializers
from distutils.util import strtobool
from cvat.apps.engine.serializers import BasicUserSerializer
from cvat.apps.iam.utils import get_dummy_user
from .models import Invitation, Membership, Organization
Expand Down Expand Up @@ -124,7 +124,7 @@ def update(self, instance, validated_data):
def save(self, request, **kwargs):
invitation = super().save(**kwargs)
dummy_user = get_dummy_user(invitation.membership.user.email)
if not strtobool(settings.ORG_INVITATION_CONFIRM) and not dummy_user:
if not to_bool(settings.ORG_INVITATION_CONFIRM) and not dummy_user:
invitation.accept()
else:
invitation.send(request)
Expand Down
6 changes: 3 additions & 3 deletions cvat/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
import sys
import tempfile
from datetime import timedelta
from distutils.util import strtobool
from enum import Enum
import urllib

from attr.converters import to_bool
from corsheaders.defaults import default_headers
from logstash_async.constants import constants as logstash_async_constants

Expand Down Expand Up @@ -179,7 +179,7 @@ def generate_secret_key():
'PASSWORD_RESET_SERIALIZER': 'cvat.apps.iam.serializers.PasswordResetSerializerEx',
}

if strtobool(os.getenv('CVAT_ANALYTICS', '0')):
if to_bool(os.getenv('CVAT_ANALYTICS', False)):
INSTALLED_APPS += ['cvat.apps.log_viewer']

MIDDLEWARE = [
Expand Down Expand Up @@ -700,7 +700,7 @@ class CVAT_QUEUES(Enum):
# to check configuration and throw ImproperlyConfigured if thats a case
EMAIL_BACKEND = None

ONE_RUNNING_JOB_IN_QUEUE_PER_USER = strtobool(os.getenv('ONE_RUNNING_JOB_IN_QUEUE_PER_USER', 'false'))
ONE_RUNNING_JOB_IN_QUEUE_PER_USER = to_bool(os.getenv('ONE_RUNNING_JOB_IN_QUEUE_PER_USER', False))

# How many chunks can be prepared simultaneously during task creation in case the cache is not used
CVAT_CONCURRENT_CHUNK_PROCESSING = int(os.getenv('CVAT_CONCURRENT_CHUNK_PROCESSING', 1))
Expand Down

0 comments on commit 9b99f6a

Please sign in to comment.