未验证 提交 bddd4464 编写于 作者: M Maxim Zhiltsov 提交者: GitHub

Fix pylint issues (#100)

上级 57bc0e9c
......@@ -70,8 +70,8 @@ class AnnotationIR:
prev_shape = None
for shape in track['shapes']:
if prev_shape and not prev_shape['outside'] and \
has_overlap(prev_shape['frame'], shape['frame']):
return True
has_overlap(prev_shape['frame'], shape['frame']):
return True
prev_shape = shape
if not prev_shape['outside'] and prev_shape['frame'] <= stop:
......
......@@ -1434,7 +1434,8 @@ def import_dm_annotations(dm_dataset: Dataset, instance_data: Union[TaskData, Pr
if isinstance(instance_data, ProjectData):
for sub_dataset, task_data in instance_data.split_dataset(dm_dataset):
# FIXME: temporary workaround for cvat format, will be removed after migration importer to datumaro
# FIXME: temporary workaround for cvat format
# will be removed after migration importer to datumaro
sub_dataset._format = dm_dataset.format
import_dm_annotations(sub_dataset, task_data)
return
......@@ -1477,6 +1478,12 @@ def import_dm_annotations(dm_dataset: Dataset, instance_data: Union[TaskData, Pr
try:
if hasattr(ann, 'label') and ann.label is None:
raise CvatImportError("annotation has no label")
attributes = [
instance_data.Attribute(name=n, value=str(v))
for n, v in ann.attributes.items()
]
if ann.type in shapes:
if ann.type == datum_annotation.AnnotationType.cuboid_3d:
try:
......@@ -1485,44 +1492,50 @@ def import_dm_annotations(dm_dataset: Dataset, instance_data: Union[TaskData, Pr
ann.points = ann.points
ann.z_order = 0
# Use safe casting to bool instead of plain reading
# because in some formats return type can be different
# from bool / None
# https://github.com/openvinotoolkit/datumaro/issues/719
occluded = cast(ann.attributes.pop('occluded', None), bool) is True
keyframe = cast(ann.attributes.get('keyframe', None), bool) is True
outside = cast(ann.attributes.pop('outside', None), bool) is True
track_id = ann.attributes.pop('track_id', None)
source = ann.attributes.pop('source').lower() \
if ann.attributes.get('source', '').lower() in {'auto', 'manual'} else 'manual'
if track_id is None or dm_dataset.format != 'cvat' :
instance_data.add_shape(instance_data.LabeledShape(
type=shapes[ann.type],
frame=frame_number,
points=ann.points,
label=label_cat.items[ann.label].name,
occluded=ann.attributes.pop('occluded', None) == True,
occluded=occluded,
z_order=ann.z_order,
group=group_map.get(ann.group, 0),
source=str(ann.attributes.pop('source')).lower() \
if str(ann.attributes.get('source', None)).lower() in {'auto', 'manual'} else 'manual',
attributes=[instance_data.Attribute(name=n, value=str(v))
for n, v in ann.attributes.items()],
source=source,
attributes=attributes,
))
continue
if ann.attributes.get('keyframe', None) == True or ann.attributes.get('outside', None) == True:
if keyframe or outside:
track = instance_data.TrackedShape(
type=shapes[ann.type],
frame=frame_number,
occluded=ann.attributes.pop('occluded', None) == True,
outside=ann.attributes.pop('outside', None) == True,
keyframe=ann.attributes.get('keyframe', None) == True,
occluded=occluded,
outside=outside,
keyframe=keyframe,
points=ann.points,
z_order=ann.z_order,
source=str(ann.attributes.pop('source')).lower() \
if str(ann.attributes.get('source', None)).lower() in {'auto', 'manual'} else 'manual',
attributes=[instance_data.Attribute(name=n, value=str(v))
for n, v in ann.attributes.items()],
source=source,
attributes=attributes,
)
if track_id not in tracks:
tracks[track_id] = instance_data.Track(
label=label_cat.items[ann.label].name,
group=group_map.get(ann.group, 0),
source=str(ann.attributes.pop('source')).lower() \
if str(ann.attributes.get('source', None)).lower() in {'auto', 'manual'} else 'manual',
source=source,
shapes=[],
)
......@@ -1534,8 +1547,7 @@ def import_dm_annotations(dm_dataset: Dataset, instance_data: Union[TaskData, Pr
label=label_cat.items[ann.label].name,
group=group_map.get(ann.group, 0),
source='manual',
attributes=[instance_data.Attribute(name=n, value=str(v))
for n, v in ann.attributes.items()],
attributes=attributes,
))
except Exception as e:
raise CvatImportError("Image {}: can't import annotation "
......
......@@ -38,4 +38,4 @@ def _import(src_file, instance_data, load_data_callback=None):
dataset = Dataset.import_from(tmp_dir, 'imagenet', env=dm_env)
if load_data_callback is not None:
load_data_callback(dataset, instance_data)
import_dm_annotations(dataset, instance_data)
\ No newline at end of file
import_dm_annotations(dataset, instance_data)
......@@ -50,7 +50,7 @@ class LabelAttrToAttr(ItemTransform):
def transform_item(self, item):
annotations = list(item.annotations)
attributes = dict(item.attributes)
if self._label != None:
if self._label is not None:
labels = [ann for ann in annotations
if ann.type == AnnotationType.label \
and ann.label == self._label]
......
......@@ -32,7 +32,7 @@ def _import_task(dataset, task_data):
type='rectangle',
label=label_cat.items[ann.label].name,
points=ann.points,
occluded=ann.attributes.get('occluded') == True,
occluded=ann.attributes.get('occluded') is True,
z_order=ann.z_order,
group=0,
frame=frame_number,
......@@ -44,7 +44,7 @@ def _import_task(dataset, task_data):
shape = task_data.TrackedShape(
type='rectangle',
points=ann.points,
occluded=ann.attributes.get('occluded') == True,
occluded=ann.attributes.get('occluded') is True,
outside=False,
keyframe=True,
z_order=ann.z_order,
......
......@@ -52,7 +52,7 @@ def _import_task(dataset, task_data):
shape = task_data.TrackedShape(
type='polygon',
points=ann.points,
occluded=ann.attributes.get('occluded') == True,
occluded=ann.attributes.get('occluded') is True,
outside=False,
keyframe=True,
z_order=ann.z_order,
......
......@@ -19,7 +19,6 @@ from .registry import exporter, importer
@exporter(name='Kitti Raw Format', ext='ZIP', version='1.0', dimension=DimensionType.DIM_3D)
def _export_images(dst_file, task_data, save_images=False):
dataset = Dataset.from_extractors(GetCVATDataExtractor(
task_data, include_images=save_images, format_type="kitti_raw", dimension=DimensionType.DIM_3D), env=dm_env)
......@@ -33,14 +32,10 @@ def _export_images(dst_file, task_data, save_images=False):
def _import(src_file, instance_data, load_data_callback=None):
with TemporaryDirectory() as tmp_dir:
if zipfile.is_zipfile(src_file):
zipfile.ZipFile(src_file).extractall(tmp_dir)
dataset = Dataset.import_from(
tmp_dir, 'kitti_raw', env=dm_env)
zipfile.ZipFile(src_file).extractall(tmp_dir)
dataset = Dataset.import_from(tmp_dir, 'kitti_raw', env=dm_env)
else:
dataset = Dataset.import_from(
src_file.name, 'kitti_raw', env=dm_env)
dataset = Dataset.import_from(src_file.name, 'kitti_raw', env=dm_env)
if load_data_callback is not None:
load_data_callback(dataset, instance_data)
import_dm_annotations(dataset, instance_data)
......@@ -34,4 +34,4 @@ def bulk_create(db_model, objects, flt_param):
else:
return db_model.objects.bulk_create(objects)
return []
\ No newline at end of file
return []
......@@ -463,7 +463,9 @@ def update_states():
try:
get(db_git.task_id, db_user)
except Exception:
slogger.glob("Exception occurred during a status updating for db_git with tid: {}".format(db_git.task_id))
slogger.glob.exception("Exception occurred during a status "
"updating for db_git with tid: {}".format(db_git.task_id),
exc_info=True)
@transaction.atomic
def _onsave(jid, data, action):
......
# Copyright (C) 2018 Intel Corporation
#
# SPDX-License-Identifier: MIT
\ No newline at end of file
# SPDX-License-Identifier: MIT
# Copyright (C) 2018 Intel Corporation
#
# SPDX-License-Identifier: MIT
\ No newline at end of file
# SPDX-License-Identifier: MIT
......@@ -494,7 +494,7 @@ class FragmentMediaReader:
if idx < self._start_chunk_frame_number:
continue
elif idx < self._end_chunk_frame_number and \
not ((idx - self._start_chunk_frame_number) % self._step):
not (idx - self._start_chunk_frame_number) % self._step:
frame_range.append(idx)
elif (idx - self._start_chunk_frame_number) % self._step:
continue
......@@ -654,20 +654,20 @@ class Mpeg4ChunkWriter(IChunkWriter):
}
def _create_av_container(self, path, w, h, rate, options, f='mp4'):
# x264 requires width and height must be divisible by 2 for yuv420p
if h % 2:
h += 1
if w % 2:
w += 1
# x264 requires width and height must be divisible by 2 for yuv420p
if h % 2:
h += 1
if w % 2:
w += 1
container = av.open(path, 'w',format=f)
video_stream = container.add_stream(self._codec_name, rate=rate)
video_stream.pix_fmt = "yuv420p"
video_stream.width = w
video_stream.height = h
video_stream.options = options
container = av.open(path, 'w',format=f)
video_stream = container.add_stream(self._codec_name, rate=rate)
video_stream.pix_fmt = "yuv420p"
video_stream.width = w
video_stream.height = h
video_stream.options = options
return container, video_stream
return container, video_stream
def save_as_chunk(self, images, chunk_path):
if not images:
......@@ -779,7 +779,7 @@ def _is_zip(path):
# 'mode': 'annotation' or 'interpolation' - mode of task that should be created.
# 'unique': True or False - describes how the type can be combined with other.
# True - only one item of this type and no other is allowed
# False - this media types can be combined with other which have unique == False
# False - this media types can be combined with other which have unique is False
MEDIA_TYPES = {
'image': {
......
......@@ -14,4 +14,4 @@ class TusUploadParser(BaseParser):
# exception because a parser for the request with the non-standard
# content media type isn't defined.
# https://github.com/imtapps/django-rest-framework/blob/master/docs/api-guide/parsers.md
return {}
\ No newline at end of file
return {}
......@@ -5,4 +5,4 @@
from rest_framework.renderers import JSONRenderer
class CVATAPIRenderer(JSONRenderer):
media_type = 'application/vnd.cvat+json'
\ No newline at end of file
media_type = 'application/vnd.cvat+json'
......@@ -2,4 +2,4 @@
#
# SPDX-License-Identifier: MIT
from .schema import *
\ No newline at end of file
from .schema import * # force import of extensions
......@@ -23,4 +23,4 @@ class CustomGroupAdmin(GroupAdmin):
admin.site.unregister(User)
admin.site.unregister(Group)
admin.site.register(User, CustomUserAdmin)
admin.site.register(Group, CustomGroupAdmin)
\ No newline at end of file
admin.site.register(Group, CustomGroupAdmin)
......@@ -41,4 +41,4 @@ class SignatureAuthenticationScheme(OpenApiAuthenticationExtension):
'type': 'apiKey',
'in': 'query',
'name': 'sign',
}
\ No newline at end of file
}
......@@ -38,4 +38,4 @@ if settings.IAM_TYPE == 'BASIC':
name='account_email_verification_sent'),
]
urlpatterns = [path('auth/', include(urlpatterns))]
\ No newline at end of file
urlpatterns = [path('auth/', include(urlpatterns))]
......@@ -32,13 +32,13 @@ def get_context(request):
org_id = request.GET.get('org_id')
org_header = request.headers.get('X-Organization')
if org_id != None and (org_slug != None or org_header != None):
raise BadRequest('You cannot specify "org_id" query parameter with ' +
if org_id is not None and (org_slug is not None or org_header is not None):
raise BadRequest('You cannot specify "org_id" query parameter with '
'"org" query parameter or "X-Organization" HTTP header at the same time.')
if org_slug != None and org_header != None and org_slug != org_header:
raise BadRequest('You cannot specify "org" query parameter and ' +
if org_slug is not None and org_header is not None and org_slug != org_header:
raise BadRequest('You cannot specify "org" query parameter and '
'"X-Organization" HTTP header with different values.')
org_slug = org_slug if org_slug != None else org_header
org_slug = org_slug if org_slug is not None else org_header
org_filter = None
if org_slug:
......
......@@ -382,7 +382,7 @@ class LambdaQueue:
def fetch_job(self, pk):
queue = self._get_queue()
job = queue.fetch_job(pk)
if job == None or not job.meta.get("lambda"):
if job is None or not job.meta.get("lambda"):
raise ValidationError("{} lambda job is not found".format(pk),
code=status.HTTP_404_NOT_FOUND)
......
......@@ -199,4 +199,4 @@ class InvitationViewSet(viewsets.ModelViewSet):
if 'accepted' in self.request.query_params:
serializer.instance.accept()
else:
super().perform_update(serializer)
\ No newline at end of file
super().perform_update(serializer)
from django.apps import apps
if apps.is_installed('silk'):
from silk.profiling.profiler import silk_profile
from silk.profiling.profiler import silk_profile # pylint: disable=unused-import
else:
from functools import wraps
def silk_profile(name=None):
......@@ -10,4 +10,4 @@ else:
def wrapped(*args, **kwargs):
return f(*args, **kwargs)
return wrapped
return profile
\ No newline at end of file
return profile
......@@ -213,7 +213,7 @@ def org_staff(memberships):
return set()
else:
return set(m['user']['id'] for m in memberships
if m['role'] in ['maintainer', 'owner'] and m['user'] != None
if m['role'] in ['maintainer', 'owner'] and m['user'] is not None
and m['organization'] == org_id)
return find
......@@ -224,7 +224,7 @@ def is_org_member(memberships):
return True
else:
return user_id in set(m['user']['id'] for m in memberships
if m['user'] != None and m['organization'] == org_id)
if m['user'] is not None and m['organization'] == org_id)
return check
@pytest.fixture(scope='session')
......@@ -273,4 +273,4 @@ def filter_tasks_with_shapes(annotations):
@pytest.fixture(scope='session')
def tasks_with_shapes(tasks, filter_tasks_with_shapes):
return filter_tasks_with_shapes(tasks)
\ No newline at end of file
return filter_tasks_with_shapes(tasks)
......@@ -22,7 +22,7 @@ class TestCreateInvitations:
@staticmethod
def get_non_member_users(memberships, users):
organization_users = set(m['user']['id'] for m in memberships if m['user'] != None)
organization_users = set(m['user']['id'] for m in memberships if m['user'] is not None)
non_member_users = [u for u in users if u['id'] not in organization_users]
return non_member_users
......@@ -30,7 +30,7 @@ class TestCreateInvitations:
@staticmethod
def get_member(role, memberships, org_id):
member = [m['user'] for m in memberships if m['role'] == role and
m['organization'] == org_id and m['user'] != None][0]
m['organization'] == org_id and m['user'] is not None][0]
return member
......
# Copyright (C) 2021 Intel Corporation
#
# SPDX-License-Identifier: MIT
from .core import VideoManifestManager, ImageManifestManager, is_manifest
\ No newline at end of file
from .core import VideoManifestManager, ImageManifestManager, is_manifest
......@@ -522,7 +522,7 @@ class VideoManifestManager(_ManifestManager):
@property
def data(self):
return (self.video_name)
return self.video_name
def get_subset(self, subset_names):
raise NotImplementedError()
......
......@@ -57,7 +57,7 @@ def main():
# If the source is a glob expression, we need additional processing
abs_root = source
while abs_root and re.search('[*?\[\]]', abs_root):
while abs_root and re.search(r'[*?\[\]]', abs_root):
abs_root = os.path.split(abs_root)[0]
related_images = detect_related_images(sources, abs_root)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册