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

Add a job to check import formatting using isort #333

Merged
merged 3 commits into from
Jul 7, 2021
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
15 changes: 15 additions & 0 deletions .github/workflows/isort.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Linter
on: pull_request
jobs:
isort:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.8

- name: Run checks
run: |
pip install --user -r <(grep "^isort" ./requirements.txt)
isort --check --diff .
6 changes: 6 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[settings]
forced_separate = tests
from_first = True
include_trailing_comma = True
line_length = 80
multi_line_output = 5
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ enable= E0001,E0100,E0101,E0102,E0103,E0104,E0105,E0106,E0107,E0110,
E0702,E0703,E0704,E0710,E0711,E0712,E1003,E1102,E1111,E0112,
E1120,E1121,E1123,E1124,E1125,E1126,E1127,E1132,E1200,E1201,
E1205,E1206,E1300,E1301,E1302,E1303,E1304,E1305,E1306,
C0123,C0200,C0303,C0411,C1001,
C0123,C0200,C0303,C1001,
W0101,W0102,W0104,W0105,W0106,W0107,W0108,W0109,W0110,W0120,
W0122,W0124,W0150,W0199,W0221,W0222,W0233,W0404,W0410,W0601,
W0602,W0604,W0611,W0612,W0622,W0623,W0702,W0705,W0711,W1300,
Expand Down
1 change: 0 additions & 1 deletion datum.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@

from datumaro.cli.__main__ import main


if __name__ == '__main__':
sys.exit(main())
1 change: 0 additions & 1 deletion datumaro/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@

from datumaro.cli.__main__ import main


if __name__ == '__main__':
sys.exit(main())
5 changes: 2 additions & 3 deletions datumaro/cli/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
import os.path as osp
import sys

from . import contexts, commands
from .util import CliException, add_subparser
from ..version import VERSION

from . import commands, contexts
from .util import CliException, add_subparser

_log_levels = {
'debug': log.DEBUG,
Expand Down
7 changes: 2 additions & 5 deletions datumaro/cli/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
# pylint: disable=redefined-builtin

from . import (
create, add, remove, import_,
explain,
export, merge, convert, transform, filter,
diff, ediff, stats,
info, validate
add, convert, create, diff, ediff, explain, export, filter, import_, info,
merge, remove, stats, transform, validate,
)
2 changes: 1 addition & 1 deletion datumaro/cli/commands/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import os
import os.path as osp

from datumaro.components.project import Environment
from datumaro.components.dataset import Dataset
from datumaro.components.project import Environment

from ..contexts.project import FilterModes
from ..util import CliException, MultilineFormatter, make_file_name
Expand Down
9 changes: 6 additions & 3 deletions datumaro/cli/commands/explain.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@
import os.path as osp

from datumaro.components.project import Project
from datumaro.util.command_targets import (TargetKinds, target_selector,
ProjectTarget, SourceTarget, ImageTarget, is_project_path)
from datumaro.util.command_targets import (
ImageTarget, ProjectTarget, SourceTarget, TargetKinds, is_project_path,
target_selector,
)
from datumaro.util.image import load_image, save_image

from ..util import MultilineFormatter
from ..util.project import load_project

Expand Down Expand Up @@ -108,8 +111,8 @@ def explain_command(args):
args.project_dir = osp.dirname(osp.abspath(args.target[1]))


import cv2
from matplotlib import cm
import cv2

project = load_project(args.project_dir)

Expand Down
8 changes: 4 additions & 4 deletions datumaro/cli/commands/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
#
# SPDX-License-Identifier: MIT

from collections import OrderedDict
import argparse
import json
import logging as log
import os.path as osp
from collections import OrderedDict

from datumaro.components.project import Project
from datumaro.components.errors import MergeError, QualityError
from datumaro.components.operations import IntersectMerge
from datumaro.components.errors import QualityError, MergeError
from datumaro.components.project import Project

from ..util import at_least, MultilineFormatter, CliException
from ..util import CliException, MultilineFormatter, at_least
from ..util.project import generate_next_file_name, load_project


Expand Down
2 changes: 1 addition & 1 deletion datumaro/cli/contexts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
#
# SPDX-License-Identifier: MIT

from . import project, source, model
from . import model, project, source
5 changes: 3 additions & 2 deletions datumaro/cli/contexts/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
from datumaro.util import error_rollback

from ..util import CliException, MultilineFormatter, add_subparser
from ..util.project import load_project, \
generate_next_name, generate_next_file_name
from ..util.project import (
generate_next_file_name, generate_next_name, load_project,
)


def build_add_parser(parser_ctor=argparse.ArgumentParser):
Expand Down
17 changes: 10 additions & 7 deletions datumaro/cli/contexts/project/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,30 @@
#
# SPDX-License-Identifier: MIT

from enum import Enum
import argparse
import json
import logging as log
import os
import os.path as osp
import shutil
from enum import Enum

import numpy as np

from datumaro.components.dataset_filter import DatasetItemEncoder
from datumaro.components.extractor import AnnotationType
from datumaro.components.operations import (DistanceComparator,
ExactComparator, compute_ann_statistics, compute_image_statistics)
from datumaro.components.project import \
PROJECT_DEFAULT_CONFIG as DEFAULT_CONFIG
from datumaro.components.operations import (
DistanceComparator, ExactComparator, compute_ann_statistics,
compute_image_statistics,
)
from datumaro.components.project import PROJECT_DEFAULT_CONFIG as DEFAULT_CONFIG
from datumaro.components.project import Environment, Project
from datumaro.components.validator import TaskType
from datumaro.util import error_rollback

from ...util import (CliException, MultilineFormatter, add_subparser,
make_file_name)
from ...util import (
CliException, MultilineFormatter, add_subparser, make_file_name,
)
from ...util.project import generate_next_file_name, load_project
from .diff import DatasetDiffVisualizer

Expand Down
3 changes: 2 additions & 1 deletion datumaro/cli/contexts/project/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
# SPDX-License-Identifier: MIT

from collections import Counter
from itertools import zip_longest
from enum import Enum, auto
from itertools import zip_longest
import logging as log
import os
import os.path as osp
import warnings

import cv2
import numpy as np

Expand Down
3 changes: 2 additions & 1 deletion datumaro/cli/contexts/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
import shutil

from datumaro.components.project import Environment
from ..util import add_subparser, CliException, MultilineFormatter

from ..util import CliException, MultilineFormatter, add_subparser
from ..util.project import load_project


Expand Down
3 changes: 2 additions & 1 deletion datumaro/cli/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ def make_file_name(s):
Normalizes string, converts to lowercase, removes non-alpha characters,
and converts spaces to hyphens.
"""
import unicodedata, re
import re
import unicodedata
s = unicodedata.normalize('NFKD', s).encode('ascii', 'ignore')
s = s.decode()
s = re.sub(r'[^\w\s-]', '', s).strip().lower()
Expand Down
1 change: 1 addition & 0 deletions datumaro/components/algorithms/rise.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# pylint: disable=unused-variable

from math import ceil

import numpy as np

from datumaro.components.extractor import AnnotationType
Expand Down
7 changes: 4 additions & 3 deletions datumaro/components/cli_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ def _get_name(cls):
def _get_doc(cls):
doc = getattr(cls, '__doc__', "")
if doc:
from datumaro.components.launcher import Launcher
from datumaro.components.extractor import Extractor, Transform, \
Importer
from datumaro.components.converter import Converter
from datumaro.components.extractor import (
Extractor, Importer, Transform,
)
from datumaro.components.launcher import Launcher
base_classes = [Launcher, Extractor, Transform, Importer, Converter]

if any(getattr(t, '__doc__', '') == doc for t in base_classes):
Expand Down
7 changes: 3 additions & 4 deletions datumaro/components/config_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
#
# SPDX-License-Identifier: MIT

from datumaro.components.config import Config, \
DictConfig as _DictConfig, \
SchemaBuilder as _SchemaBuilder

from datumaro.components.config import Config
from datumaro.components.config import DictConfig as _DictConfig
from datumaro.components.config import SchemaBuilder as _SchemaBuilder

SOURCE_SCHEMA = _SchemaBuilder() \
.add('url', str) \
Expand Down
2 changes: 1 addition & 1 deletion datumaro/components/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import shutil

from datumaro.components.cli_plugin import CliPlugin
from datumaro.util.image import save_image, ByteImage
from datumaro.util.image import ByteImage, save_image


class Converter(CliPlugin):
Expand Down
24 changes: 13 additions & 11 deletions datumaro/components/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,30 @@
#
# SPDX-License-Identifier: MIT

from copy import copy
from contextlib import contextmanager
from copy import copy
from enum import Enum, auto
from typing import Any, Iterable, Iterator, Optional, Tuple, Union, Dict, List
import logging as log
from typing import Any, Dict, Iterable, Iterator, List, Optional, Tuple, Union
import inspect
import logging as log
import os
import os.path as osp
import shutil

from datumaro.components.dataset_filter import \
XPathDatasetFilter, XPathAnnotationsFilter
from datumaro.components.extractor import (CategoriesInfo, Extractor,
IExtractor, ItemTransform, LabelCategories, AnnotationType, DatasetItem,
DEFAULT_SUBSET_NAME, Transform)
from datumaro.components.dataset_filter import (
XPathAnnotationsFilter, XPathDatasetFilter,
)
from datumaro.components.environment import Environment
from datumaro.components.errors import (CategoriesRedefinedError,
DatumaroError, RepeatedItemError)
from datumaro.components.errors import (
CategoriesRedefinedError, DatumaroError, RepeatedItemError,
)
from datumaro.components.extractor import (
DEFAULT_SUBSET_NAME, AnnotationType, CategoriesInfo, DatasetItem, Extractor,
IExtractor, ItemTransform, LabelCategories, Transform,
)
from datumaro.util import error_rollback, is_member_redefined
from datumaro.util.log_utils import logging_disabled


DEFAULT_FORMAT = 'datumaro'

IDataset = IExtractor
Expand Down
10 changes: 6 additions & 4 deletions datumaro/components/dataset_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
# SPDX-License-Identifier: MIT

import logging as log
from lxml import etree as ET # lxml has proper XPath implementation
from datumaro.components.extractor import (ItemTransform,
Annotation, AnnotationType,
Label, Mask, Points, Polygon, PolyLine, Bbox, Caption,

from lxml import etree as ET # lxml has proper XPath implementation

from datumaro.components.extractor import (
Annotation, AnnotationType, Bbox, Caption, ItemTransform, Label, Mask,
Points, Polygon, PolyLine,
)


Expand Down
16 changes: 10 additions & 6 deletions datumaro/components/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

from functools import partial
from glob import glob
from typing import Dict, Iterable
import inspect
import logging as log
import os
import os.path as osp
from typing import Dict, Iterable

import git

from datumaro.components.config import Config
Expand Down Expand Up @@ -112,7 +113,8 @@ class Environment:

def __init__(self, config=None):
from datumaro.components.project import (
PROJECT_DEFAULT_CONFIG, PROJECT_SCHEMA)
PROJECT_DEFAULT_CONFIG, PROJECT_SCHEMA,
)
config = Config(config,
fallback=PROJECT_DEFAULT_CONFIG, schema=PROJECT_SCHEMA)

Expand All @@ -128,8 +130,9 @@ def _filter(accept, skip=None):
return lambda t: issubclass(t, accept) and t not in skip

from datumaro.components.converter import Converter
from datumaro.components.extractor import (Importer, Extractor,
SourceExtractor, Transform, ItemTransform)
from datumaro.components.extractor import (
Extractor, Importer, ItemTransform, SourceExtractor, Transform,
)
from datumaro.components.launcher import Launcher
self._extractors = PluginRegistry(_filter(Extractor,
skip=SourceExtractor))
Expand Down Expand Up @@ -207,8 +210,9 @@ def _import_module(cls, module_dir, module_name, types, package=None):
def _load_plugins(cls, plugins_dir, types=None):
if not types:
from datumaro.components.converter import Converter
from datumaro.components.extractor import (Extractor, Importer,
Transform)
from datumaro.components.extractor import (
Extractor, Importer, Transform,
)
from datumaro.components.launcher import Launcher
types = [Extractor, Converter, Importer, Launcher, Transform]

Expand Down
Loading